2

I'm using Clint Harris' solution from this

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")

Here I'm just testing one coordinate with a shapefile, but it appears the code may be out of date. I changed shapefile_record = fiona_collection.next() to shapefile_record = next(iter(fiona_collection)) already but this error I cannot seem to solve:

---------------------------------------------------------------------------
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'
Georgy
  • 12,464
  • 7
  • 65
  • 73
compsciman
  • 349
  • 3
  • 17
  • Does this answer your question? [Python Shapely Install Not working?](https://stackoverflow.com/questions/35978649/python-shapely-install-not-working) – Georgy Feb 25 '20 at 12:49

1 Answers1

5

Your code is searching for geometry attribute in shapely module and it is failing. To solve this, import the shapely.geometry module as below.

import shapely.geometry

shape = shapely.geometry.asShape( shapefile_record['geometry'])
Mithilesh_Kunal
  • 873
  • 7
  • 12