TypeError: 'MultiPolygon' object is not iterable (VS Code: Python geopandas)

69 Views Asked by At

In my anaconda env, I have installed geopandas just fine but I am unable to make plots in Visual Studio Code due to the error:

TypeError: 'MultiPolygon' object is not iterable.

I am quite new to programming, and so far, I encountered many difficulties running Visual Code Studio on Mac M1 - is it a common error? Should I switch to a different IDE?

**Code: **

import geopandas as gpd
import matplotlib.pyplot as plt
world_data = gpd.read_file(r'/Users/xxxxx/world.shp')
world_data
world_data.plot()

**Error: **

/Users/lantyynka/opt/anaconda3/envs/datax/lib/python3.12/site-packages/geopandas/plotting.py:48: ShapelyDeprecationWarning: The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead. if geom.type.startswith(prefix): Traceback (most recent call last): File "", line 1, in File "/Users/lantyynka/opt/anaconda3/envs/datax/lib/python3.12/site-packages/geopandas/geodataframe.py", line 921, in plot return plot_dataframe(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/lantyynka/opt/anaconda3/envs/datax/lib/python3.12/site-packages/geopandas/plotting.py", line 615, in plot_dataframe return plot_series( ^^^^^^^^^^^^ File "/Users/lantyynka/opt/anaconda3/envs/datax/lib/python3.12/site-packages/geopandas/plotting.py", line 413, in plot_series _plot_polygon_collection( File "/Users/lantyynka/opt/anaconda3/envs/datax/lib/python3.12/site-packages/geopandas/plotting.py", line 129, in _plot_polygon_collection geoms, multiindex = _flatten_multi_geoms(geoms) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/lantyynka/opt/anaconda3/envs/datax/lib/python3.12/site-packages/geopandas/plotting.py", line 49, in _flatten_multi_geoms for poly in geom: TypeError: 'MultiPolygon' object is not iterable

Thank you in advance for any help!:)

I tried running the code in the terminal as well as the interactive window through Jupyter. Both attempts resulted in the same error.

I also tried installing older version of shapely but it did not work.

0

There are 0 best solutions below