【问题标题】:How to convert HEXEWKB to Latitude, Longitude (in python)?如何将 HEXEWKB 转换为纬度、经度(在 python 中)?
【发布时间】:2016-03-20 03:44:48
【问题描述】:

我从 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,这感觉有点像过冲。有没有更简单的方法?

【问题讨论】:

标签: python gis openstreetmap latitude-longitude


【解决方案1】:

在尝试了不同的库之后,我在一个有点相关的问题中找到了最实用的解决方案:Why can shapely/geos parse this 'invalid' Well Known Binary?。这涉及到使用 shapely (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 对象,然后从该点提取经纬度坐标。

【讨论】:

    猜你喜欢
    • 2013-12-19
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 2010-09-11
    相关资源
    最近更新 更多