Last active
July 7, 2025 14:55
-
-
Save ArthurDelannoyazerty/4eb5f41d0595c87b5864823be4bab641 to your computer and use it in GitHub Desktop.
Display geojson/geometris on a earth map and save it as html interactive page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import folium | |
from pathlib import Path | |
from folium.plugins import Draw | |
def display_geometries(list_geometries:list, output_filepath:Path, inverse_lat_lon:bool=True): | |
""" | |
Save the geometries on a map on a html page with an Earth background. | |
Args: | |
list_geometries (list[dict]): List of geometry dicts to plot. | |
output_filepath (Path): Path to save the output html file. | |
""" | |
# Create the map | |
m = folium.Map( | |
location=[20.0, 0.0], | |
zoom_start=3, | |
tiles='OpenStreetMap', | |
control_scale=True, | |
) | |
# Add plugins ( https://python-visualization.github.io/folium/latest/user_guide/plugins ) | |
Draw(export=True).add_to(m) | |
# Add the geometries to the map | |
for geom in list_geometries: | |
geom_coords = geom['coordinates'][0] | |
if inverse_lat_lon: | |
geom_coords = [[coord[1], coord[0]] for coord in geom_coords] | |
else: | |
geom_coords = [[coord[0], coord[1]] for coord in geom_coords] | |
folium.Polygon( | |
locations=geom_coords, | |
color='blue', | |
weight=1, | |
fill=True, | |
fill_opacity=0.2, | |
).add_to(m) | |
m.save(output_filepath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.