-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOSM_Roundabout.py
More file actions
29 lines (26 loc) · 929 Bytes
/
Copy pathOSM_Roundabout.py
File metadata and controls
29 lines (26 loc) · 929 Bytes
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
import xml.etree.ElementTree as ET
from shapely.geometry import LineString
import matplotlib.pyplot as plt
# Loading the .osm file and parsing
tree = ET.parse('test_file.osm')
root = tree.getroot()
# Extract Roundabout from .osm
roundabouts = []
for way in root.findall("./way/tag[@k='junction'][@v='roundabout']/.."):
nodes = []
for nd in way.findall('nd'):
node_id = nd.get('ref')
node = root.find("node[@id='{}']".format(node_id))
lon = float(node.get('lon'))
lat = float(node.get('lat'))
nodes.append((lon, lat))
roundabout = LineString(nodes)
roundabouts.append({'geometry': roundabout})
# Display the roundabouts on a map
fig, ax = plt.subplots(figsize=(10, 10))
for roundabout in roundabouts:
ax.plot(*roundabout['geometry'].xy, color='red', linewidth=2)
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.grid(True)
plt.show()