模块 'shapely' 没有属性 'geometry' 错误
module 'shapely' has no attribute 'geometry' error
我正在使用来自 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'
您的代码正在 shapely 模块中搜索几何属性,但失败了。
要解决此问题,请按以下方式导入 shapely.geometry
模块。
import shapely.geometry
shape = shapely.geometry.asShape( shapefile_record['geometry'])
我正在使用来自 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'
您的代码正在 shapely 模块中搜索几何属性,但失败了。
要解决此问题,请按以下方式导入 shapely.geometry
模块。
import shapely.geometry
shape = shapely.geometry.asShape( shapefile_record['geometry'])