我正在使用this的Clint Harris的解决方案
import fiona
import shapely
with fiona.open("./areas_shp.shp") as fiona_collection:
shapefile_record = next(iter(fiona_collection))
shape = shapely.geometry.asShape( shapefile_record['geometry'] )
point = shapely.geometry.Point(coords[0])
for point in coords:
if (shape.contains(point)):
print("yay")
在这里,我仅使用shapefile测试一个坐标,但是看来代码可能已过期。我已经将shapefile_record = fiona_collection.next()
更改为shapefile_record = next(iter(fiona_collection))
,但是这个错误似乎无法解决:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-8-18ca8979d01f> in <module>
38 with fiona.open("./areas_shp.shp") as fiona_collection:
39 shapefile_record = next(iter(fiona_collection))
---> 40 shape = shapely.geometry.asShape( shapefile_record['geometry'] )
41 point = shapely.geometry.Point(coords[0])
42 for point in coords:
AttributeError: module 'shapely' has no attribute 'geometry'
答案 0 :(得分:0)
您的代码正在匀称模块中搜索几何属性,并且失败。
要解决此问题,请按如下所示导入shapely.geometry
模块。
import shapely.geometry
shape = shapely.geometry.asShape( shapefile_record['geometry'])