Пример #1
0
def create_supporting_points(points, name='support'):
    nodes = []
    for p in points:
        n = osm.Node(myid=name,
                     uid=uid,
                     timestamp=ts,
                     changeset_id=csid,
                     lon=p[0],
                     lat=p[1])
        DB.add(n)
        nodes.append(n)
    DB.flush()
    return nodes
Пример #2
0
"""
import sys
import os.path
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import pandas as pd
import openmod.sh.schemas.osm as osm
from openmod.sh import web

web.app.app_context().push()
db = osm.DB.session
cs = osm.Changeset()
db.add(cs)
db.commit()

x = pd.read_csv('../data/pp-sh.csv')
x['type'] = x['type'].fillna('Condesing')

for i, r in x.iterrows():
    node = osm.Node(r['lat'],
                    r['lon'],
                    1,
                    cs.id,
                    myid="hereami",
                    tags=[("type", r["type"]), ("capacity", r["capacity"]),
                          ("fuel", r["fuel"]),
                          ("commissioned", r["commissioned"])])
    db.add(node)
    db.commit()
Пример #3
0
               'class':'source', 'lon':10, 'lat':53.6, 'hub': 'hub2'},
              {'name': 'powerplant', 'installed_capacity':100, 'lon':10.3,
               'lat':53.1, 'class':'LinearTransformer', 'fuel':'gas',
               'hub':'hub1'}]
cs = osm.Changeset()
DB.flush()

cs = cs.id

# create nodes from data dictionary
nodes = {}
for c in components:
    n = osm.Node(myid=c['name'],
                 user_id='1',
                 changeset_id=cs,
                 timestamp=datetime.now(tz.utc),
                 version=1,
                 lon=c['lon'],
                 lat=c['lat'],
                 tags={'adad':'asd'})
    nodes[c['hub']] = nodes.get(c['hub'], []) + [n]
    DB.add(n)

# Hubs
hub_tags ={'hub1': {'type': 'hub', 'balanced': True, 'name':'hub112'},
           'hub2': {'type': 'hub1', 'balanced': True, 'name': 'hub211'}}

# create relations from
relations = []
for k,v in hub_tags.items():
    r = osm.Relation(myid=k,
                    timestamp=datetime.now(tz.utc),
Пример #4
0
#   * this attribute is a list of objects.
#   * each of these objects has the attribute `master_way_squeezed`.
#   * `master_way_squeezed` is a list of objects with the attributes `lat`,
#     `lon` and `id`. These objects correspond to nodes in the OSM database.
#     The `id` attribute is the `id` of the node in the OSM database, which we
#     currently don't care about.
#   * the whole `master_way_squeezed` list corresponds to one "way" in the OSM
#     database.
#
# Let's see how easy it is to populate our database with data in this format.

# The heat data is temporaly stored in data in root of the openmod repository
heat = pd.read_csv('../data/heat_demand.csv', dtype={'region_key':str})
heat.set_index('region_key', inplace=True)

for i, r in enumerate(result.relations):
    nodes = [osm.Node(n.lat, n.lon, 1, cs.id)
            for n in r.master_way_squeezed[0:-1:50]]
    nodes.append(nodes[0])
    way = osm.Way(version='1', nodes=nodes, uid=1, changeset=cs,
                  tags=( [osm.Tag(key="area", value="yes")] +
                         ([osm.Tag(key="name", value=r.tags["name"])]
                                if r.tags.get("name")
                                else []) +
                          ([osm.Tag(key="heat_demand",
                                    value=int(heat.loc[r.tags['de:regionalschluessel'][0:5]]['demand']))])))
    db.add(way)
    print("Committing way #{}".format(i))
    db.commit()

Пример #5
0
points = [f for f in features if f['geometry']['type'] == 'Point']
linestrings = [f for f in features if f['geometry']['type'] == 'LineString']
polygons = [f for f in features if f['geometry']['type'] == 'Polygon']

hub_elements = {}

print("Adding points")
number_of_points = len(points)
i = 0
for f in points:
    i += 1
    print(i, 'of', number_of_points)
    n = osm.Node(myid=f['id'],
                 uid=uid,
                 changeset_id=csid,
                 timestamp=ts,
                 lon=f['geometry']['coordinates'][0],
                 lat=f['geometry']['coordinates'][1],
                 tags=make_tags(f),
                 referencing_relations=[scenario])
    for key, value in n.tags.copy().items():
        if value == 'timeseries':
            n.timeseries[key] = f['properties'][key]
    DB.add(n)
    for h in f['properties']['hubs']:
        hub_elements[h] = hub_elements.get(h, []) + [n]

DB.flush()

print("Adding linestrings")
for f in linestrings:
    nodes = create_supporting_points(f['geometry']['coordinates'], f['id'])