Duckdb layer
In [ ]:
Copied!
# %pip install "leafmap[duckdb]"
# %pip install "leafmap[duckdb]"
In [ ]:
Copied!
import leafmap.maplibregl as leafmap
import leafmap.maplibregl as leafmap
If you are running in a remote Jupyter environment, you need to configure leafmap with your JupyterHub URL. Uncomment the following line and replace https://your-jupyterhub-domain.com with your JupyterHub URL.
In [ ]:
Copied!
# leafmap.configure_jupyterhub("https://your-jupyterhub-domain.com")
# leafmap.configure_jupyterhub("https://your-jupyterhub-domain.com")
Download a sample GeoParquet dataset from Source Coop.
In [ ]:
Copied!
url = "https://data.source.coop/giswqs/nwi/wetlands/RI_Wetlands.parquet"
fileapth = leafmap.download_file(url)
url = "https://data.source.coop/giswqs/nwi/wetlands/RI_Wetlands.parquet"
fileapth = leafmap.download_file(url)
Example 1: Load data from vector file(creates temporary database)
In [ ]:
Copied!
m = leafmap.Map(style="liberty", height="600px")
m.add_basemap("Esri.WorldImagery")
m.add_duckdb_layer(
data=fileapth, # Supports GeoParquet, GeoJSON, and GeoPackage, etc.
layer_name="wetlands",
layer_type="fill",
paint={"fill-color": "#3388ff"},
opacity=0.5,
fit_bounds=True,
use_view=False, # For remote datasets, set use_view to True to avoid copying data to local
min_zoom=None, # For large datasets, set min_zoom to None to avoid zooming out too much
quiet=False,
)
m
m = leafmap.Map(style="liberty", height="600px")
m.add_basemap("Esri.WorldImagery")
m.add_duckdb_layer(
data=fileapth, # Supports GeoParquet, GeoJSON, and GeoPackage, etc.
layer_name="wetlands",
layer_type="fill",
paint={"fill-color": "#3388ff"},
opacity=0.5,
fit_bounds=True,
use_view=False, # For remote datasets, set use_view to True to avoid copying data to local
min_zoom=None, # For large datasets, set min_zoom to None to avoid zooming out too much
quiet=False,
)
m
Example 2: Load from existing DuckDB database (no data loading)
In [ ]:
Copied!
url = "https://data.gishub.org/duckdb/nyc_data.db.zip"
leafmap.download_file(url)
url = "https://data.gishub.org/duckdb/nyc_data.db.zip"
leafmap.download_file(url)
In [ ]:
Copied!
db_path = "nyc_data.db"
db_path = "nyc_data.db"
In [ ]:
Copied!
#
m = leafmap.Map(
center=[-73.9031255, 40.7127753], zoom=9, style="liberty", height="600px"
)
m.add_duckdb_layer(
database_path=db_path,
table_name="nyc_neighborhoods",
layer_type="fill",
paint={"fill-color": "#ff0000"},
opacity=0.5,
fit_bounds=False,
src_crs="EPSG:26918",
quiet=True,
)
m
#
m = leafmap.Map(
center=[-73.9031255, 40.7127753], zoom=9, style="liberty", height="600px"
)
m.add_duckdb_layer(
database_path=db_path,
table_name="nyc_neighborhoods",
layer_type="fill",
paint={"fill-color": "#ff0000"},
opacity=0.5,
fit_bounds=False,
src_crs="EPSG:26918",
quiet=True,
)
m