bswag
bswag

Reputation: 101

Cannot make GeoDataFrame from Shapely Polygons: NotImplementedError: A polygon does not itself provide the array interface. Its rings do

This is code that used to work previously, but doesn't anymore:

import geopandas as gp
from shapely.geometry import Polygon

a = Polygon([(0, 0), (0, 1), (1, 1), (1, 0)])
b = Polygon([(0, 1), (0, 2), (1, 2), (1, 1)])
c = Polygon([(1, 0), (1, 1), (2, 1), (2, 0)])
d = Polygon([(1, 1), (1, 2), (2, 2), (2, 1)])
df = gp.GeoDataFrame({"ID": ["a", "b", "c", "d"], "geometry": [a, b, c, d]})

The error I get is this:

NotImplementedError: A polygon does not itself provide the array interface. Its rings do.

Why could this be happening? My GeoPandas version is 0.81 and Shapely version is 1.71.

Upvotes: 10

Views: 12011

Answers (3)

The error NotImplementedError: Component rings have coordinate sequences, but the polygon does not typically occurs when attempting to convert a polygonal geometry object (Polygon) to a list of coordinates using the coords property and the geometry object does not have an associated list of coordinates.

To fix this error, make sure that the geometry object you are trying to convert is a valid polygonal geometry object and has an associated list of coordinates. One way to do this is to use the exterior.coords method instead of coords to access the coordinates of the polygon.

Upvotes: 4

chenste
chenste

Reputation: 81

Upgrading Shapely==1.8.4 from 1.7.1 resolved my issues.

Upvotes: 8

Yingbin
Yingbin

Reputation: 91

I got the same error with Shapely==1.7.1 geopandas==0.9.0 numpy==1.23.1, changing numpy==1.22.4 works for me.

Upvotes: 9

Related Questions