Shapely contains(point) 总是给出 False

2024-06-18

我今天开始研究 geopandas 和 shapely,我正在尝试使用contains检查点是否位于地质选区数据多边形内部的方法here http://projects.datameet.org/maps/assembly-constituencies/#issues。我的代码是:

if janak.boundary.contains(cent_janak):
    print('True')
else:
    print('False')

where janak是来自 shapefile 的几何数据的多边形,cent_janak是 janak 的质心。 为了验证,我像这样绘制了它们

from descartes import PolygonPatch
BLUE = '#6699cc'
poly= janak
fig = plt.figure() 
ax = fig.gca() 
ax.add_patch(PolygonPatch(poly, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2 ))

ax.axis('scaled')
plt.plot(cjx, cjy, 'bo')
plt.show()

The resulting plot is this. enter image description here

为了更清楚janak.boundary.coords.xy多边形坐标为:

(array('d', [77.27673511633259, 77.28194987388764, 77.29578190561051, 77.27662755381863, 77.25524963905963, 77.2580696782731, 77.26521771742375, 77.26932536547332, 77.26832967477475, 77.27477975458208, 77.27673511633259]),
 array('d', [28.540205606503605, 28.52730150785834, 28.495644714432103, 28.493054206486477, 28.506460566601902, 28.521859125598212, 28.525798083314953, 28.52190443074494, 28.540396930973657, 28.544344420558616, 28.540205606503605]))

质心cent_janak.coords.xy坐标是:

(array('d', [77.27464056229368]), array('d', [28.51348721728798])) 

你打电话时janak.boundary.contains(cent_janak),你问是否cent_janak lies on边界。您正在寻找的方法很简单janak.contains(cent_janak).

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Shapely contains(point) 总是给出 False 的相关文章

随机推荐