我从OpenStreetMap下载了一些感兴趣的数据,结果发现这些位置是用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语言(How to convert HEXEWKB to Latitude, Longitude (in java)?)之前也被问过,但是我需要一个Python解决方案。在
到目前为止,我的尝试主要集中在尝试使用GeoDjango的GEOS模块(https://docs.djangoproject.com/en/1.8/ref/contrib/gis/geos/#creating-a-geometry),但是由于我在应用程序中没有使用Django,这感觉有点过头了。有没有更简单的方法?在
在尝试了不同的库之后,我在一个有点相关的问题中找到了最实用的解决方案:Why can shapely/geos parse this 'invalid' Well Known Binary?。这涉及到使用shapely(https://pypi.python.org/pypi/Shapely):
也就是说,你只需要使用wkb荷载将HEXEWKB字符串转换为shapely Point对象,然后从该点提取long/lat坐标。在
相关问题 更多 >
编程相关推荐