pysepal.mapping.geojson_utils.get_ipygeojson#
- pysepal.mapping.geojson_utils.get_ipygeojson(gdf, name='aoi', style=None)[source]#
Convert a GeoDataFrame into an ipyleaflet GeoJSON layer.
This is a standalone utility function that creates a GeoJSON layer from a GeoDataFrame, suitable for display on an ipyleaflet Map.
- Parameters:
gdf (GeoDataFrame) – The GeoDataFrame to convert to a GeoJSON layer.
name (str) – The name to assign to the layer and as a property to features.
style (dict | None) – Optional style dictionary for the GeoJSON layer. If None, uses the default AOI style with primary color. See ipyleaflet GeoJSON documentation for style options.
- Returns:
An ipyleaflet GeoJSON layer ready to be added to a Map.
- Raises:
ValueError – If the GeoDataFrame is None or empty.
- Return type:
GeoJSON
Example
import geopandas as gpd from pysepal.mapping import get_ipygeojson, SepalMap # Create a simple GeoDataFrame gdf = gpd.read_file("my_shapefile.shp") # Create the GeoJSON layer geojson_layer = get_ipygeojson(gdf, name="my_layer") # Add to map m = SepalMap() m.add_layer(geojson_layer)