我想得到在给定多边形中相交的点的结果,但是我得到了一个错误。
我的代码是:
from pysal.cg.standalone import get_polygon_point_intersect
poly=pysal.open('Busroute_buffer.shp')
point=pysal.open('pmpml_24.shp')
i=get_polygon_point_intersect(poly,point)但我得到了错误信息:
'PurePyShpWrapper‘对象没有属性'bounding_box’
发布于 2015-06-09 19:10:50
pysal.open返回形状"file“对象,而不是形状。
要获得形状,您需要迭代文件,或者调用文件的read方法,该方法返回形状列表。这将返回一个列表,即使您的文件中只有一个形状。get_polygon_point_intersect只需要一个多边形和一个点,所以您需要为要比较的每一个点/多边形调用它。
point_file = pysal.open('points.shp')
polygon_file = pysal.open('polygons.shp')
# .read with no arguments returns a list of all shapes in the file.
polygons = polygon_file.read()
for polygon in polygons:
# for x in shapefile: iterates over each shape in the file.
for point in point_file:
if get_polygon_point_intersect(polygon, point):
print point, 'intersects with', polygon还有其他更有效的方法来做到这一点。有关更多信息,请参见pysal.cg.locators。
*上述守则未经测试,例如只作测试用途。
https://stackoverflow.com/questions/30658551
复制相似问题