我从OpenStreetMap下载了一些Point of Interest数据,事实证明这些位置是以HEXEWKB格式编码的:
CSV fields
==============================================
1 : Node type; N|W|R (in upper case), wheter it is a Node, Way or Relation in the openstreetmap model
2 : id; The openstreetmap id
3 : name; The default name of the city
4 : countrycode; The iso3166-2 country code (2 letters)
5 : alternatenames; the names of the POI in other languages
6 : location; The middle location of the POI in HEXEWKB
7 : tags; the POI tags : amenity,aeroway,building,craft,historic,leisure,man_made,office,railway,tourism,shop,sport,landuse,highway separated by '___'
我需要将它们转换为经度/纬度值。对于Java语言,以前也曾问过同样的问题(如何将HEXEWKB转换为纬度,经度(在Java中)?),但是我需要Python解决方案。
到目前为止,我的尝试一直集中在尝试使用GeoDjango的GEOS模块(https://docs.djangoproject.com/en/1.8/ref/contrib/gis/geos/#creating-a-geometry),但自从没有在我的应用程序中使用Django,这有点像过头了。有没有更简单的方法?
在尝试了不同的库之后,我在一个相关的问题中找到了最实用的解决方案:为什么可以通过形状/地理解析这种“无效”的知名二进制文件?。这涉及使用匀称(https://pypi.python.org/pypi/Shapely):
from shapely import wkb
hexlocation = "0101000020E6100000CB752BC86AC8ED3FF232E58BDA7E4440"
point = wkb.loads(hexlocation, hex=True)
longitude = point.x
latitude = point.y
也就是说,您只需要使用wkb.loads将HEXEWKB字符串转换为整齐的Point对象,然后从该点提取长/纬度坐标。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句