mirror of
https://github.com/netzbegruenung/social-spider.git
synced 2024-05-08 05:23:41 +02:00
add code to include city states
This commit is contained in:
parent
4db20ad25c
commit
dcdf2ba71a
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import os
|
||||
from copy import copy
|
||||
from pprint import pprint
|
||||
from spider import dir_entries
|
||||
|
@ -284,12 +285,52 @@ def createKVBasemap():
|
|||
feature["properties"]["state"] = entry["state"]
|
||||
feature["properties"]["district"] = entry["district"]
|
||||
result_features.append(feature)
|
||||
result_features += getHamburgMap()
|
||||
result_features += getBerlinMap()
|
||||
result_features += getBremenMap()
|
||||
result_map = {"type": "FeatureCollection",
|
||||
"features": result_features}
|
||||
with open("maps/kv_basemap.geojson", "w") as output_f:
|
||||
json.dump(result_map, output_f, indent=4)
|
||||
|
||||
|
||||
def getBerlinMap():
|
||||
lat, lon = location.geocode('Berlin, Germany')
|
||||
bounds = location.from_buffer(lat, lon, buffer_size=10000)
|
||||
print(bounds)
|
||||
# Build an overpass QL query and get the JSON response
|
||||
query = f'[out:json][timeout:25];(relation["type"="boundary"]["boundary"="administrative"]["admin_level"="9"]{bounds}; ); out geom qt;'
|
||||
response = overpass.request(query)
|
||||
ids = []
|
||||
names = []
|
||||
for elem in response["elements"]:
|
||||
print(elem["id"])
|
||||
ids.append(elem["id"])
|
||||
names.append(elem["tags"]["name"])
|
||||
|
||||
mapdata = []
|
||||
for id_, name in zip(ids, names):
|
||||
if name == "Lindenberg":
|
||||
continue
|
||||
url = "http://polygons.openstreetmap.fr/get_geojson.py?id=" + str(id_) + "¶ms=0"
|
||||
urllib.request.urlretrieve(url, './tmp.geojson')
|
||||
print(name)
|
||||
with open('./tmp.geojson') as f:
|
||||
data = json.load(f)
|
||||
print(len(data["geometries"]))
|
||||
c = {"type": "Feature",
|
||||
"properties": {
|
||||
"type": "REGIONAL_CHAPTER",
|
||||
"level": "DE:KREISVERBAND",
|
||||
"state": "Berlin",
|
||||
"district": name
|
||||
},
|
||||
"geometry": data["geometries"][0]}
|
||||
mapdata.append(c)
|
||||
os.remove('./tmp.geojson')
|
||||
return mapdata
|
||||
|
||||
|
||||
def getHamburgMap():
|
||||
lat, lon = location.geocode('Hamburg, Germany')
|
||||
bounds = location.from_buffer(lat, lon, buffer_size=10000)
|
||||
|
@ -309,12 +350,28 @@ def getHamburgMap():
|
|||
url = "http://polygons.openstreetmap.fr/get_geojson.py?id=" + str(id_) + "¶ms=0"
|
||||
urllib.request.urlretrieve(url, './tmp.geojson')
|
||||
print(name)
|
||||
if name.startswith("Hamburg-"):
|
||||
name = name.replace("Hamburg-", "")
|
||||
with open('./tmp.geojson') as f:
|
||||
data = json.load(f)
|
||||
pprint(data)
|
||||
# TODO
|
||||
print(len(data["geometries"]))
|
||||
c = {"type": "Feature",
|
||||
"properties": {
|
||||
"type": "REGIONAL_CHAPTER",
|
||||
"level": "DE:KREISVERBAND",
|
||||
"state": "Hamburg",
|
||||
"district": name
|
||||
},
|
||||
"geometry": data["geometries"][0]}
|
||||
mapdata.append(c)
|
||||
os.remove('./tmp.geojson')
|
||||
return mapdata
|
||||
|
||||
def getBremenMap():
|
||||
with open('./maps/additional_hb.geojson') as f:
|
||||
data = json.load(f)
|
||||
return data["features"]
|
||||
|
||||
if __name__ == "__main__":
|
||||
#createKVBasemap()
|
||||
#createLVBasemap()
|
||||
getHamburgMap()
|
||||
createKVBasemap()
|
||||
createLVBasemap()
|
||||
|
|
5561
maps/additional_hb.geojson
Normal file
5561
maps/additional_hb.geojson
Normal file
File diff suppressed because it is too large
Load diff
61146
maps/kv_basemap.geojson
61146
maps/kv_basemap.geojson
File diff suppressed because it is too large
Load diff
61419
maps/kv_fb.geojson
61419
maps/kv_fb.geojson
File diff suppressed because it is too large
Load diff
61419
maps/kv_in.geojson
61419
maps/kv_in.geojson
File diff suppressed because it is too large
Load diff
61419
maps/kv_tw.geojson
61419
maps/kv_tw.geojson
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue