In [1]:
Copied!
# %pip install "leafmap[duckdb]"
# %pip install "leafmap[duckdb]"
In [2]:
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 [3]:
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 [4]:
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)
Downloading... From: https://data.source.coop/giswqs/nwi/wetlands/RI_Wetlands.parquet To: /home/runner/work/leafmap/leafmap/docs/maplibre/RI_Wetlands.parquet
0%| | 0.00/72.4M [00:00<?, ?B/s]
1%| | 524k/72.4M [00:00<00:15, 4.68MB/s]
14%|█▍ | 9.96M/72.4M [00:00<00:01, 54.9MB/s]
35%|███▍ | 25.2M/72.4M [00:00<00:00, 89.4MB/s]
47%|████▋ | 34.1M/72.4M [00:00<00:00, 89.0MB/s]
59%|█████▉ | 43.0M/72.4M [00:00<00:00, 87.0MB/s]
75%|███████▍ | 54.0M/72.4M [00:00<00:00, 94.2MB/s]
88%|████████▊ | 63.4M/72.4M [00:00<00:00, 90.4MB/s]
100%|██████████| 72.4M/72.4M [00:00<00:00, 83.1MB/s]
Example 1: Load data from vector file(creates temporary database)
In [5]:
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
Note: Using temporary database file for tile serving: /tmp/leafmap_duckdb_957fl51o.db Initializing DuckDB database for layer 'wetlands'...
Auto-detected CRS: EPSG:5070 (NAD83 / Conus Albers) Sample coordinates: X=2045123.16, Y=2319961.41 Use src_crs='EPSG:5070' to override if incorrect
Successfully loaded data into table 'features' (transformed from EPSG:5070 to EPSG:3857) Total features: 55229
Starting DuckDB tile server on port 8000...
DuckDB tile server running at http://127.0.0.1:8000/ Tiles available at: http://127.0.0.1:8000/tiles/{z}/{x}/{y}.pbf * Serving Flask app 'leafmap.common'
* Debug mode: off
Layer 'wetlands' added successfully!
Example 2: Load from existing DuckDB database (no data loading)
In [6]:
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)
Downloading... From: https://data.gishub.org/duckdb/nyc_data.db.zip To: /home/runner/work/leafmap/leafmap/docs/maplibre/nyc_data.db.zip
0%| | 0.00/8.60M [00:00<?, ?B/s]
100%|██████████| 8.60M/8.60M [00:00<00:00, 268MB/s]
Extracting files...
Out[6]:
'/home/runner/work/leafmap/leafmap/docs/maplibre/nyc_data.db.zip'
In [7]:
Copied!
db_path = "nyc_data.db"
db_path = "nyc_data.db"
In [8]:
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