2015-06-05 17 views
2

我希望在给定的多边形中相交的点的结果,但是出现错误。如何在Pysal中使用Shapefile

我的代码是:

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'

回答

1

pysal.open返回形状“文件”对象,而不是形状。

要获取形状,您需要迭代该文件或调用文件的读取方法,该方法返回形状列表。这将返回一个列表,即使文件中只有一个形状。 get_polygon_point_intersect只需要1个多边形和1个点,因此您需要为每个要比较的点/多边形调用它。

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

*以上代码未经测试,仅供参考。

相关问题