def get_ways_data(elements, coords):
ways_data = {}
for element in elements:
# Only process ways
if element.get('type') != 'way':
continue
# Only process ways with 3 or more nodes, otherwise
# Shapely will complain.
nodes = element.get('nodes')
if len(nodes) < 3:
continue
exterior = [(coords[node].get('lat'), coords[node].get('lon')) \
for node in nodes]
# Build the polygon and compute its bbox and centroid
way_polygon = Polygon(exterior)
ways_data[element.get('id')] = {
'bounds': way_polygon.bounds,
'lat': way_polygon.centroid.x,
'lon': way_polygon.centroid.y}
# Done
return ways_data
评论列表
文章目录