Add function to plot GeoDataframe / GeoSeries on folium map

This commit is contained in:
heyarne 2021-02-22 17:47:18 +00:00
commit 06d2afbe25

View file

@ -198,3 +198,16 @@ class RasterReaderList():
def __exit__(self, _type, _value, _traceback):
for f in self.open_files:
f.close()
def geodataframe_on_map(geodataframe):
'''
Plot a GeoDataframe or GeoSeries on a Leaflet map; map automatically
centers
'''
bbox = geodataframe.unary_union.bounds
minx, miny, maxx, maxy = bbox
m = folium.Map([0, 0], tiles='cartodbpositron')
folium.GeoJson(geodataframe.to_json()).add_to(m)
m.fit_bounds([[miny, minx], [maxy, maxx]])
return m