使用Python、geopy和shapely实现GPS定位

3

我正在尝试处理以下情况:

  • Getting polygon coordinates from google earth
  • Getting boundaries with Shapely:

    >>> polygon = Polygon([(53.349459,-6.260159),(53.349366,-6.260126),(53.349383,-6.260012),(53.349478,-6.260053),(53.349459,-6.260159)])   
    >>> polygon.bounds
    (53.349366, -6.260159, 53.349478, -6.260012)
    

    I am getting 2 coordinates, which are 2 border points on the top of my figure.

  • Getting distance with geopy

    And now I am stuck... trying to figure out:

    1. How to find 2 other border points (in the bottom)
    2. How to detect whether a user is near (e.g. 3 meters) the polygon from any side? (left, right, up, down). in this case, I need to know not only the edges border points, but also all the border points from left, right, up and down? I can calculate the distance between the user location and the polygon, but what point to from polygon to take dynamically? Can I use existing libs for this, like geopy and Shapely?

    Image


这可能更适合在http://gis.stackexchange.com上提问。 - RickyA
Bounds返回您的多边形的边界框。它是多边形适合其中的最小矩形。如果您查看它,它不是顶点坐标。 - RickyA
1个回答

1

如果我理解正确,您有一堆Shapely多边形,并且想要测试任意点是否靠近这些形状。对于这个问题,Shapely提供了distance

from shapely.geometry import Point, Polygon
polygon = Polygon([(53.349459,-6.260159),
                   (53.349366,-6.260126),
                   (53.349383,-6.260012),
                   (53.349478,-6.260053),
                   (53.349459,-6.260159)])
testpoint = Point(53.349459,-6.260190)
dist = polygon.distance(testpoint)
print(dist)
>>> 3.09999999999e-05

请注意:距离是以弧度而不是米为单位,因此您需要进行转换。

距离以弧度为单位,如果我理解得正确的话,只有在使用坐标时才会这样。在这种情况下,我甚至不确定这是否准确。测量经纬度距离的更好方法是先投影多边形(pyproj?),然后再测量它。我们正在使用一种更简单的投影方法,它依赖于多边形的平均纬度。 - Guy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接