Hello everyone.
I have to make a choropleth map and I have a shapefile for this. I read the geometry of this shapefile and the geometry is a MultiPolygon, which I don’t know how to use it.
import geopandas as gpd
shape_adress = r"C:\Users\DIRECTORY\Bokeh"
geodf = gpd.read_file(shape_adress)
According to this link I used the following function:
def getPolyCoords(row, geom, coord_type):
"""Returns the coordinates ('x' or 'y') of edges of a Polygon exterior"""
# Parse the exterior of the coordinate
exterior = row[geom].exterior
if coord_type == 'x':
# Get the x coordinates of the exterior
return list( exterior.coords.xy[0] )
elif coord_type == 'y':
# Get the y coordinates of the exterior
return list( exterior.coords.xy[1] )
Then I wrote the following:
geodf['x'] = geodf.apply(getPolyCoords, geom='geometry', coord_type='x', axis=1)
geodf['y'] = geodf.apply(getPolyCoords, geom='geometry', coord_type='y', axis=1)
And I recieved this error:
AttributeError: ("‘MultiPolygon’ object has no attribute ‘exterior’", ‘occurred at index 0’)
Is there a way to overcome this? I have also attached a print screen of my shapefile. The color column is the one that I want to visualize and the PC4 column is the postal code distric that I want to visualize.
Thanks in advance!
<img src='//bokeh-discourse-uploads.s3.dualstack.us-east-1.amazonaws.com/original/1X/d16af1204de79e90bb828548e6e02511bca75b8b.png' width='711' height='292'>

