forked from fritzvd/wur-python
-
Notifications
You must be signed in to change notification settings - Fork 4
/
city_info.py
67 lines (52 loc) · 1.93 KB
/
city_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from shapely.geometry import mapping
from input_output import read_txt
from input_output import write_shape
from apis import get_latlong
from apis import get_height_ahn2
from apis import get_landuse
from apis import get_soil
from apis import get_height_profile_ahn2
from geobuilder import point
from geobuilder import line
# files
in_cities = "cities.txt"
out_shape = "/home/arjen/Desktop/city_info_result.shp"
# we want our data to look like this
schema = {'geometry': 'Point',
'properties': {'city': 'str',
'height_ahn2': 'float',
'soil': 'str'}}
# we want to store each result in a list
results = []
# read text file with cities
cities = read_txt(in_cities)
# main loop
for city in cities:
city = city.strip()
print city
# get location from google
location = get_latlong(city)
# build geometry
geometry = point(location['lng'], location['lat'])
geometry_wkt = geometry.wkt
print geometry_wkt
# get info from lizard
height_ahn2 = get_height_ahn2(geometry_wkt)
# landuse = get_landuse(geometry_wkt)
soil = get_soil(geometry_wkt)
results.append({"geometry": mapping(geometry),
"properties": {"city": city,
"height_ahn2": height_ahn2,
# "landuse": landuse,
"soil": soil}})
# save results to a shapefile
write_shape(out_shape, schema, results)
# build a linestring from an array of cities
city_route = line([result['geometry']['coordinates'] for result in results])
city_route_wkt = city_route.wkt # city_route.AsWKT()
# get height profile for linestring
height_profile_ahn2 = get_height_profile_ahn2(city_route_wkt)
# build a buffer around a city and get landuse and soil counts
#TODO: live bonus feature
#NOTE: we do conversions to other file formats with cli ogr2ogr,
# be smart, use the proper library, use the proper tool.