Skip to content

Commit b34ded5

Browse files
committed
ingest any from __geo_interface__
1 parent 0a8fdfc commit b34ded5

File tree

4 files changed

+428
-383
lines changed

4 files changed

+428
-383
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Added BeautifyIcon Plugin (arthuralvim and jeremybyu #819)
1616
- Explicit WMSTileLayer options, accept all **kwargs (conengmo #838)
1717
- Updated links to Draw plugin (conengmo #868)
18+
- Ingest any object that __geo_interface__ (ocefpaf #880)
1819

1920
API changes
2021

examples/Geopandas and geo_interface.ipynb

Lines changed: 423 additions & 0 deletions
Large diffs are not rendered by default.

examples/Geopandas.ipynb

Lines changed: 0 additions & 373 deletions
This file was deleted.

folium/features.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,11 @@ def __init__(self, data, style_function=None, name=None,
403403
else: # This is a filename
404404
with open(data) as f:
405405
self.data = json.loads(f.read())
406-
elif data.__class__.__name__ in ['GeoDataFrame', 'GeoSeries']:
406+
elif hasattr(data, '__geo_interface__'):
407407
self.embed = True
408-
if hasattr(data, '__geo_interface__'):
409-
# We have a GeoPandas 0.2 object.
410-
self.data = json.loads(json.dumps(data.to_crs(epsg='4326').__geo_interface__)) # noqa
411-
elif hasattr(data, 'columns'):
412-
# We have a GeoDataFrame 0.1
413-
self.data = json.loads(data.to_crs(epsg='4326').to_json())
414-
else:
415-
msg = 'Unable to transform this object to a GeoJSON.'
416-
raise ValueError(msg)
408+
if hasattr(data, 'to_crs'):
409+
data = data.to_crs(epsg='4326')
410+
self.data = json.loads(json.dumps(data.__geo_interface__)) # noqa
417411
else:
418412
raise ValueError('Unhandled object {!r}.'.format(data))
419413

0 commit comments

Comments
 (0)