Shapely contains(point) always gives False

我的未来我决定 提交于 2019-12-11 01:56:27

问题


I started working on geopandas and shapely today and I am trying to use the contains method to check if a point lies inside a polygon of geological constituency data from here. My code is:

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

where janak is a polygon from geometry data of a shapefile and cent_janak is the centroid of janak. To verify, I plotted them like this

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.

For more clarity janak.boundary.coords.xy polygon coords are:

(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]))

The centroid cent_janak.coords.xy coords are:

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

回答1:


When you call janak.boundary.contains(cent_janak), you are asking if cent_janak lies on the boundary. The method you are looking for is simply janak.contains(cent_janak).



来源:https://stackoverflow.com/questions/53654056/shapely-containspoint-always-gives-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!