def coords_for(name):
geocoder = Nominatim()
location = geocoder.geocode(name, geometry='geojson')
try:
geometry = shape(location.raw['geojson'])
# Coordinates have to be flipped in order to work in overpass
if geometry.geom_type == 'Polygon':
west, south, east, north = geometry.bounds
return BoundingBox(south, west, north, east)
elif geometry.geom_type == 'MultiPolygon':
bboxs = (BoundingBox(*(g.bounds[0:2][::-1] + g.bounds[2:][::-1]))
for g in geometry)
return bboxs
elif geometry.geom_type == 'Point':
south, north, west, east = (float(coordinate)
for coordinate in
location.raw['boundingbox'])
return BoundingBox(south, west, north, east)
except (KeyError, AttributeError):
raise AttributeError(
'No bounding box available for this location name.')
评论列表
文章目录