question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

folium.features.GeoJson could give a more descriptive error when passing GeoDataFrames with missing geometries

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ocefpafcommented, Dec 11, 2018

How about silently stripping out the rows that have no geometries?

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.

0reactions
ocefpafcommented, Dec 11, 2018

Okay, I’ll make a PR.

Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found