我在使用来自this的Clint的解决方案
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'发布于 2019-06-04 04:57:01
您的代码正在shapely模块中搜索几何图形属性,但它失败了。要解决这个问题,请导入shapely.geometry模块,如下所示。
import shapely.geometry
shape = shapely.geometry.asShape( shapefile_record['geometry'])https://stackoverflow.com/questions/56437382
复制相似问题