-
Notifications
You must be signed in to change notification settings - Fork 0
/
overpass.py
39 lines (35 loc) · 998 Bytes
/
overpass.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
import overpy
import geopandas
from shapely.geometry import Point
import matplotlib.pyplot as plt
api = overpy.Overpass()
result = api.query("""
(
node
["place"~"city|town|village|hamlet"]
(38.6893216,-9.5005921,38.8869669,-9.3720427);
)->._;
(._;>;);
out;""")
# result = api.query("""
# (
# node
# ["place"~"city|town|village|hamlet"]
# (38.725965379021, -9.525146484375, 38.856820134744, -9.411506652832);
# )->._;
# (._;>;);
# out;
# """)
print(result)
towns_points_coord = []
towns_points_names = []
for node in result.nodes:
print(node.tags['name'], node.lat, node.lon)
towns_points_names.append(node.tags['name'])
towns_points_coord.append(Point(node.lon,node.lat))
points = geopandas.GeoDataFrame(towns_points_names, geometry=towns_points_coord, columns=['name'])
# print(points)
points.plot()
for x, y, name in zip(points.geometry.x, points.geometry.y, points.name):
plt.annotate(name, xy=(x, y), xytext=(3, 3), textcoords="offset points")
plt.show()