jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
898 stars 120 forks source link

Convert GeometryCollection to MultiPolygon #187

Closed SnehitDua closed 1 year ago

SnehitDua commented 1 year ago

Hi Can anyone tell me how can i convert a GeometryCollection object to MultiPolygon or a single Polygon. I am using Folium and it shows the following error:

UserWarning: GeoJsonTooltip is not configured to render for GeoJson GeometryCollection geometries. Please consider reworking these features: [{'NAME_1': 'Oaxaca', 'NAME_2': 'Dist. Juchitan', 'Total': 100, 'nombre': 'Dist. Juchitan, Oaxaca'}, {'NAME_1': 'Oaxaca', 'NAME_2': 'Dist. Pochutla', 'Total': 500, 'nombre': 'Dist. Pochutla, Oaxaca'}, {'NAME_1': 'Oaxaca', 'NAME_2': 'Dist. Tehuantepec', 'Total': 800, 'nombre': 'Dist. Tehuantepec, Oaxaca'}] to MultiPolygon for full functionality.

Code: import folium

map = folium.Map(location= [25, -99], zoom_start= 5, tiles= 'openstreetmap')

folium.Choropleth( geo_data= gdf[['nombre', 'geometry']].to_json(), data= gdf, columns= ['nombre', 'Total'], key_on= 'properties.nombre', fill_color= 'YlOrRd', nan_fill_color= 'white', fill_opacity=0.7, line_opacity=0.2, highlight=True, line_color='black' ).add_to(map)

folium.features.GeoJson( data= gdf, name= 'Total de Delitos', smooth_factor= 2, style_function= lambda x: {'color': 'black', 'fillColor': 'transparent', 'weight': 0.5}, tooltip= folium.features.GeoJsonTooltip( fields= ['nombre', 'Total'], aliases= ['Nombre:', 'Total de Delitos:'], localize= True, sticky= False, labels= True, style=""" background-color: #F0EFEF; border: 2px solid black; border-radius: 3px; box-shadow: 3px; """, max_width=800), highlight_function= lambda x: {'weight': 3, 'fillColor': 'grey'}, ).add_to(map)

map

Problem is that it is not showing the popup text.

image

Expected output like this: image

Json file which includes geometry collection: https://github.com/angelnmara/geojson/blob/master/Municipios/20_Oaxaca.json