首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模块“shapely”没有属性“几何学”错误

模块“shapely”没有属性“几何学”错误
EN

Stack Overflow用户
提问于 2019-06-04 04:31:28
回答 1查看 4.6K关注 0票数 2

我在使用来自this的Clint的解决方案

代码语言:javascript
复制
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)),但这个错误似乎无法解决:

代码语言:javascript
复制
---------------------------------------------------------------------------
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'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-04 04:57:01

您的代码正在shapely模块中搜索几何图形属性,但它失败了。要解决这个问题,请导入shapely.geometry模块,如下所示。

代码语言:javascript
复制
import shapely.geometry

shape = shapely.geometry.asShape( shapefile_record['geometry'])
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56437382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档