Add a GeoPandas GeoDataFrame to the map with MapLibre
AuHoh opened this issue · 5 comments
AuHoh commented
Environment Information
- leafmap version:0.34.1
- Python version:3.10.14
- Operating System:macOS-14.3
Description
I was trying to add a GeoDataFrame following this tutorial https://leafmap.org/maplibre/geopandas/ when a strange error appeared: telling me that the add_gdf command doesn't exist
What I Did
import os
import geopandas as gpd
import leafmap.maplibregl as leafmap
MAPTILER_KEY = leafmap.get_api_key("MAPTILER_KEY")
style = f"https://api.maptiler.com/maps/streets/style.json?key={MAPTILER_KEY}"
m = leafmap.Map(center=[-100, 40], zoom=3, style=style)
url = "https://github.com/opengeos/datasets/releases/download/us/us_states.geojson"
gdf = gpd.read_file(url)
paint = {
"fill-color": "#3388ff",
"fill-opacity": 0.8,
"fill-outline-color": "#ffffff",
}
m.add_gdf(gdf, layer_type="fill", name="States", paint=paint)
m
giswqs commented
Make sure you update it to the latest version.
pip install -U "leafmap[maplibre]"
giswqs commented
You are using v0.34.1. The latest version is v0.34.6
AuHoh commented
I didn't understand, because I started my notebook by this command: pip install "leafmap[maplibre]"
giswqs commented
Note the -U
in the command. Otherwise, it will not update it to the latest version if you have installed it before.
pip install -U "leafmap[maplibre]"
AuHoh commented
Thank you Dr Wu, it is now working after an update and a reboot of my environment.