【发布时间】:2014-02-15 05:19:23
【问题描述】:
我正在使用 matplotlib 和 shapely 测试多边形中的点函数。
这是一个 map 包含一个百慕大三角形多边形。
Google 地图 的多边形内点功能清楚地显示 testingPoint 和 testingPoint2 在多边形内,这是正确的结果。
如果我在 matplotlib 中测试这两个点并且匀称,只有 point2 通过测试。
In [1]: from matplotlib.path import Path
In [2]: p = Path([[25.774252, -80.190262], [18.466465, -66.118292], [32.321384, -64.75737]])
In [3]: p1=[27.254629577800088, -76.728515625]
In [4]: p2=[27.254629577800088, -74.928515625]
In [5]: p.contains_point(p1)
Out[5]: 0
In [6]: p.contains_point(p2)
Out[6]: 1
shapely 显示与 matplotlib 相同的结果。
In [1]: from shapely.geometry import Polygon, Point
In [2]: poly = Polygon(([25.774252, -80.190262], [18.466465, -66.118292], [32.321384, -64.75737]))
In [3]: p1=Point(27.254629577800088, -76.728515625)
In [4]: p2=Point(27.254629577800088, -74.928515625)
In [5]: poly.contains(p1)
Out[5]: False
In [6]: poly.contains(p2)
Out[6]: True
这里到底发生了什么?谷歌的算法比这两个更好吗?
谢谢
【问题讨论】:
标签: python google-maps-api-3 matplotlib point-in-polygon shapely