我一直在寻找一种在Python中将一组地理数据转换为多边形的有效方法,除此之外我有时会获得多个多边形而不是多边形,可能是因为缺少一些内部地理数据。我目前正在使用python-geohash和shapely,我的方法包括以下步骤:
我通过提取角坐标将每个geohash转换为多边形。
# after all your other code, just before execution falls off the bottom...
input("Press enter to close...")
然后我def to_polygon(geohash):
box = Geohash.bbox(geohash)
return Polygon([(box['e'], box['n']), (box['w'], box['n']), (box['w'], box['s']), (box['e'], box['s'])])
对map
地理位置执行先前解释过的转换。
iterable
最后,我使用多边形的方法union将所有这些多边形组合成一个多边形。
polygons = [to_polygon(geohash) for geohash in geohashes]
如果地理数据集大约为几千,则可能需要几分钟。
答案 0 :(得分:0)
# GeoHash to GeoJSON
converter_1 = geohashlite.GeoJsonHasher()
x = ['u09k', 'u095', 'u08g', 'u09h', 'u09e', 'u097']
converter_1.geohash_codes = x
converter_1.decode_geohash(multipolygon=True)
print(converter_1.geojson)
答案 1 :(得分:0)
我创建了一个库(polygon-geohasher)以实现此目的:
from polygon_geohasher.polygon_geohasher import geohashes_to_polygon
geohashes = ['9bc1db2',
'9bc1db6',
'9bc1db1',
'9bc1db0',
'9bc1db4',
'9bc1db9',
'9bc1db8',
'9bc1dbd',
'9bc1db3']
polygon = geohashes_to_polygon(geohashes)
print(polygon)
# POLYGON ((-99.71878051757812 4.483795166015625, -99.71878051757812 4.482421875, -99.72015380859375 4.482421875, -99.72152709960938 4.482421875, -99.722900390625 4.482421875, -99.722900390625 4.483795166015625, -99.722900390625 4.48516845703125, -99.722900390625 4.486541748046875, -99.72152709960938 4.486541748046875, -99.72015380859375 4.486541748046875, -99.71878051757812 4.486541748046875, -99.71878051757812 4.48516845703125, -99.71878051757812 4.483795166015625))