folium.features.GeoJson could give a more descriptive error when passing GeoDataFrames with missing geometries
See original GitHub issueI frequently pass GeoDataFrames to folium.features.GeoJson. When GeoDataFrames with missing geometries are passed, it gives ValueError: Unhandled object
and then prints the table. It might be better if it said something more descriptive about how the GeoDataFrame was missing geometries.
This appears to be the relevant line. GeoDataFrames with missing geometries do not have the __geo_interface__
property. Not sure if this is something worth addressing in Folium or in GeoPandas.
Replicate error with
import geopandas as gpd
import folium as f
df = gpd.read_file(gpd.datasets.get_path('nybb'))
df.loc[0, 'geometry'] = None
f.features.GeoJson(df)
Output
ValueError: Unhandled object BoroCode BoroName Shape_Leng Shape_Area \
0 5 Staten Island 330470.010332 1.623820e+09
1 4 Queens 896344.047763 3.045213e+09
2 3 Brooklyn 741080.523166 1.937479e+09
3 1 Manhattan 359299.096471 6.364715e+08
4 2 Bronx 464392.991824 1.186925e+09
geometry
0 None
1 (POLYGON ((1029606.076599121 156073.8142089844...
2 (POLYGON ((1021176.479003906 151374.7969970703...
3 (POLYGON ((981219.0557861328 188655.3157958984...
4 (POLYGON ((1012821.805786133 229228.2645874023... .
Output of folium.__version__
0.6.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
missing geometries, however the geojson data looks ...
Am I just having an issue with folium here? Because as far as I can tell, the data (and geometries therein) are fine....
Read more >Understanding ValueError from folium? - python
Python needs to be able to find the file world.json. Either that or there is something python isn't liking about that file.
Read more >[GeoPandas, Folium] Cannot render objects with any missing ...
folium.features.GeoJson could give a more descriptive error when passing GeoDataFrames with missing geometries · Issue #1037 ·.
Read more >foliumap module
A Python package for interactive mapping and geospatial analysis with minimal coding in a Jupyter environment.
Read more >foliumap module
See https://python-visualization.github.io/folium/modules.html#folium.features.GeoJson for more info about setting style.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not really sure that is a good idea. I’d rather leave data cleaning to the user than implicitly dropping empty rows. 99.99% of the cases an empty geometry row is indicative of another problem in the data.
Thanks!