модуль 'shapely' не имеет атрибута 'geometry' error - PullRequest
0 голосов
/ 04 июня 2019

Я использую решение Клинта Харриса от этого

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_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'

1 Ответ

0 голосов
/ 04 июня 2019

Ваш код ищет атрибут геометрии в модуле shapely, и он не работает.Чтобы решить эту проблему, импортируйте модуль shapely.geometry, как показано ниже.

import shapely.geometry

shape = shapely.geometry.asShape( shapefile_record['geometry'])
...