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
|
|
@ -149,7 +149,7 @@ def scihub_cloud_mask(product_path, **kwargs):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# empty cloud mask
|
# empty cloud mask
|
||||||
mask = Polygon([])
|
mask = Polygon([])
|
||||||
|
|
||||||
if kwargs.get('rasterize'):
|
if kwargs.get('rasterize'):
|
||||||
# return raster version of the vector geometry we found above
|
# return raster version of the vector geometry we found above
|
||||||
target_shape = kwargs.get('target_shape')
|
target_shape = kwargs.get('target_shape')
|
||||||
|
|
@ -197,4 +197,17 @@ class RasterReaderList():
|
||||||
|
|
||||||
def __exit__(self, _type, _value, _traceback):
|
def __exit__(self, _type, _value, _traceback):
|
||||||
for f in self.open_files:
|
for f in self.open_files:
|
||||||
f.close()
|
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