我正在运行下面的脚本,我认为对于多边形中的点,它应该返回TRUE,但它返回FALSE。
from shapely import geometry
polygon = [(-1571236.8349707182, 8989180.222117377), (1599362.9654156454, 8924317.946336618), (-1653179.0745812152, 8922145.163675062), (-1626237.6614402141, 8986445.107619021)]
Point_X = -1627875.474
Point_Y = 8955472.968
line = geometry.LineString(polygon)
point = geometry.Point(Point_X, Point_Y)
print(line.contains(point))
当我在Matlab中绘制多边形和点时,我得到了以下形状
from matplotlib import pylab as plt
poly = [[-1571236.8349707182, 8989180.222117377],
[1599362.9654156454, 8924317.946336618],
[-1653179.0745812152, 8922145.163675062],
[-1626237.6614402141, 8986445.107619021]]
x = [point[0] for point in poly]
y = [point[1] for point in poly]
p1 = [-1627875.474, 8955472.968]
p2 = [-1627875.474, 8955472.968]
plt.plot(x,y,p1[0],p1[1],'*r',p2[0],p2[1],'*b')
plt.show()
知道为什么shapely脚本返回FALSE吗?
2条答案
按热度按时间fcy6dtqo1#
您要测试的是您的点是否在对象
LineString
上。如果要测试点是否在面中,则必须使用
Polygon
类的contains
方法输出
请参阅https://shapely.readthedocs.io/en/latest/manual.html
8nuwlpux2#
此代码使用geopandas查找多边形内的点。