/
extract_supermarkets.py
54 lines (48 loc) · 2.19 KB
/
extract_supermarkets.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
import sys
import xml.etree.ElementTree as ET
from parse_osm import *
def extract_supermarkets(tree, flag):
for c1 in root:
if c1.tag == "way":
for c2 in c1:
if flag==True:
if get_tag(c2, "shop") or get_tag(c2, "landuse") == "retail" or get_tag(c2, "building") == "retail":
if get_tag(c2, "amenity") == "supermarket" or get_tag(c2, "other_tags") == "supermarket":
p = get_polygon_from_way(c1, node_list)
if p:
#print(get_nodes(c1))
#print(c2.tag, c2.attrib, p.centroid, calc_geom_area(p))
print("supermarket,{},{},{}".format(p.centroid.x, p.centroid.y, int(calc_geom_area(p))))
break
else:
p = get_polygon_from_way(c1, node_list)
if p:
#print(get_nodes(c1))
#print(c2.tag, c2.attrib, p.centroid, calc_geom_area(p))
print("shopping,{},{},{}".format(p.centroid.x, p.centroid.y, int(calc_geom_area(p))))
break
else:
if get_tag(c2, "shop"):
if get_tag(c2, "shop") == "supermarket" or get_tag(c2, "amenity") == "supermarket" or get_tag(c2, "other_tags") == "supermarket":
p = get_polygon_from_way(c1, node_list)
if p:
#print(get_nodes(c1))
#print(c2.tag, c2.attrib, p.centroid, calc_geom_area(p))
print("supermarket,{},{},{}".format(p.centroid.x, p.centroid.y, int(calc_geom_area(p))))
break
else:
p = get_polygon_from_way(c1, node_list)
if p:
#print(get_nodes(c1))
#print(c2.tag, c2.attrib, p.centroid, calc_geom_area(p))
print("shopping,{},{},{}".format(p.centroid.x, p.centroid.y, int(calc_geom_area(p))))
break
print("Debug: list of leisure types in osm file:", leisure_types, file=sys.stderr)
if __name__ == "__main__":
tree = ET.parse(sys.argv[1])
root = tree.getroot()
leisure_types = {}
node_list = build_node_list(root)
# use flag = true to execute special code block for landuse and buildings = retail
flag = True
extract_supermarkets(tree, flag)