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

3

10

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.

Unexampled answered 12/1, 2021 at 0:36 Comment(3)
your code looks fine. i tired it with geopands 0.8.1 and shapely 1.71 and it worked too. any other logs or changes you can think of?Hass
any update on this? I believe it should be the installation. I got the same error when opening gjson files with geopandasTar
What version of numpy do you have? I had it work with Shapely==1.7.1, geopandas==0.10.2, numpy==1.20.3Seaworthy
C
9

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.

Chet answered 25/7, 2022 at 8:10 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Muscular
If you are using conda for updating packages: the suggested numpy version (1.22.4) is currently not available from the default conda channel. So you first need to add the conda-forge channel: conda config --append channels conda-forge. Then, you will be able to download the newer version of numpy: conda install numpy>=1.22.4.Quadrature
T
8

Upgrading Shapely==1.8.4 from 1.7.1 resolved my issues.

Thumbscrew answered 20/8, 2022 at 23:32 Comment(1)
Shapely==1.8.4 solves the issue. You might run into other compatibility issues if you upgrade to Shapely==1.8.5Lactometer
U
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.

Unknit answered 17/12, 2022 at 3:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.