mirror of
https://github.com/heyarne/earth-observation-for-journalism.git
synced 2026-05-06 19:13:40 +02:00
Add function to plot GeoDataframe / GeoSeries on folium map
This commit is contained in:
parent
a8afc3855b
commit
06d2afbe25
1 changed files with 15 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue