logo
leafmap
Duckdb layer
Initializing search
    GitHub
    GitHub
    • Home
    • Book
    • Installation
    • Get Started
    • Usage
    • Web App
    • Tutorials
    • Contributing
    • FAQ
    • Changelog
    • YouTube Channel
    • Report Issues
      • basemaps module
      • bokehmap module
      • colormaps module
      • common module
      • deck module
      • deckgl module
      • download module
      • examples module
      • foliumap module
      • kepler module
      • maplibregl module
      • leafmap module
      • legends module
      • map_widgets module
      • osm module
      • pc module
      • plot module
      • plotlymap module
      • deck module
      • stac module
      • toolbar module
      • FOSS4G 2021
      • SIGSPATIAL 2021
      • YouthMappers 2021
      • ICRW 2023
      • EarthCube 2023
      • Taiwan 2024
      • HGAC 2024
      • CVPR 2025
      • Overview
      • 3d buildings
      • 3d choropleth
      • 3d indoor mapping
      • 3d pmtiles
      • 3d style
      • 3d terrain
      • Add 3d buildings
      • Add a marker
      • Add colorbar
      • Add components
      • Add deckgl layer
      • Add gif
      • Add html
      • Add icon
      • Add image
      • Add image generated
      • Add labels
      • Add legend
      • Add logo
      • Add text
      • AlphaEarth
      • Animate a line
      • Animate camera around point
      • Animate images
      • Animate point along line
      • Animate point along route
      • Arc layer
      • Attribution position
      • Basemaps
      • Center on symbol
      • Change building color
      • Change case of labels
      • Choropleth
      • Cloud optimized geotiff
      • Cluster
      • Color switcher
      • Countries filter
      • Create vector
      • Custom marker
      • Dashboard
      • Data driven lines
      • Disable scroll zoom
      • Display rich text
      • Drag a marker
      • Draw features
      • Duckdb layer
      • Edit vector
      • Fallback image
      • Fields of the world
      • Fit bounds
      • Fill pattern
      • Floating sidebar
      • Fly to
      • Fly to options
      • Fullscreen
      • Geojson layer in stack
      • Geojson line
      • Geojson points
      • Geojson polygon
      • Geopandas
      • Globe control
      • Google earth
      • Google earth engine
      • Gps trace
      • Heatmap layer
      • Historical imagery
      • Housing prices
      • Interactive false
      • Jump to
      • Language switch
      • Layer control
      • Layer groups
      • Layer manager
      • Layer styling
      • Line gradient
      • Live geojson
      • Live update feature
      • Local geojson
      • Local raster
      • Locate user
      • Map tiles
      • Mapillary
      • Maptiler styles
      • MGRS
      • Mouse position
      • Multiple geometries
      • Nasa opera
      • Navigation
      • Ocean bathymetry
      • Openfreemap
      • Openstreetmap
      • Overture
      • Pmtiles
      • Restrict bounds
      • Satellite map
      • Search control
      • Set pitch bearing
      • Set terrain
      • Sidebar
      • Similarity search
      • Stac
      • Time slider
      • To html
      • Variable label placement
      • Variable offset label placement
      • Vector tile
      • Video on a map
      • Visualize population density
      • Wms source
      • Zoom to linestring
      • Usage
      • 01 leafmap intro
      • 02 using basemaps
      • 03 cog stac
      • 04 cog mosaic
      • 05 load raster
      • 06 legend
      • 07 colorbar
      • 08 whitebox
      • 09 csv to points
      • 10 add vector
      • 11 linked maps
      • 12 split map
      • 13 geopandas
      • 14 postgis
      • 15 openstreetmap
      • 16 heremap
      • 17 vector tile layer
      • 18 point layer
      • 19 map to html
      • 20 planet imagery
      • 21 ts inspector
      • 22 time slider
      • 23 colormaps
      • 24 heatmap
      • 25 map title
      • 26 kepler gl
      • 27 basemap gallery
      • 28 publish map
      • 29 pydeck
      • 30 census data
      • 31 search basemaps
      • 32 local tile
      • 33 image overlay
      • 34 add points from xy
      • 35 circle markers
      • 36 add labels
      • 37 planetary computer
      • 38 plotly
      • 39 inspector tool
      • 40 plotly gui
      • 41 raster gui
      • 42 create cog
      • 43 search control
      • 44 attribute table
      • 45 create vector
      • 46 edit vector
      • 47 numpy to cog
      • 48 lidar
      • 49 split control
      • 50 marker cluster
      • 51 clip image
      • 52 netcdf
      • 53 choropleth
      • 54 plot raster
      • 55 lidar
      • 56 download ned
      • 57 national map
      • 58 bokeh
      • 59 create legend
      • 60 add widget
      • 61 vector to gif
      • 62 folium colorbar
      • 63 arcgis
      • 64 stac search
      • 65 sagemaker
      • 66 gradio
      • 67 maxar open data
      • 68 openaerialmap
      • 69 turkey earthquake
      • 70 zonal stats
      • 71 aws s3
      • 72 timelapse
      • 73 custom stac
      • 74 map tiles to geotiff
      • 75 segment anything
      • 76 image comparison
      • 77 split raster
      • 78 read raster
      • 79 timeseries
      • 80 solar
      • 81 buildings
      • 82 pmtiles
      • 83 vector viz
      • 84 read parquet
      • 85 gedi
      • 86 add markers
      • 87 actinia
      • 88 nasa earth data
      • 89 image array viz
      • 90 pixel inspector
      • 91 raster viz gui
      • 92 maplibre
      • 93 maplibre pmtiles
      • 94 mapbox
      • 95 edit vector
      • 96 batch edit vector
      • 97 overture data
      • 98 watershed
      • 99 wetlands
      • 100 nlcd
      • 101 nasa opera
      • 102 fused
      • 103 raster colormap
      • 104 point style
      • 105 vector time slider
      • 106 aws s3

    image image image

    Add DuckDB Vector Tiles

    Uncomment the following line to install leafmap if needed.

    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
    2025-10-22 2025-10-22
    Copyright © 2021 - 2024 Qiusheng Wu
    Made with Material for MkDocs