Creating point data from polygons

The Bay Area census tracts GeoJSON file has population data with polygon geometry. To create the first visualization we need to convert the geometry type to point:

tracts = gpd.read_file(r'tracts_bayarea.geojson')tracts['centroids'] = tracts.centroidtract_points = tractstract_points = tract_points.set_geometry('centroids')tract_points.plot()

The output of the previous code is as follows:

Get Mastering Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.