CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-leafmap

A Python package for geospatial analysis and interactive mapping in a Jupyter environment.

54

0.80x

Evaluation54%

0.80x

Agent success when using this tile

Overview
Eval results
Files

basemaps.mddocs/

Basemap Management

Extensive basemap collection with 100+ predefined providers supporting XYZ tiles, WMS services, and custom tile sources with backend-specific optimizations and QuickMapServices integration.

Capabilities

Basemap Access and Management

Access and manage basemaps from various providers with automatic backend-specific formatting and optimization.

def get_xyz_dict(free_only=True, france=False):
    """
    Get dictionary of available XYZ basemap providers.
    
    Args:
        free_only (bool): Return only free basemap providers
        france (bool): Include France-specific providers
    
    Returns:
        dict: Dictionary of basemap providers with metadata
    """

def xyz_to_leaflet():
    """
    Convert XYZ basemap definition to ipyleaflet format.
    
    Returns:
        ipyleaflet.TileLayer: Formatted basemap layer
    """

def xyz_to_folium(xyz):
    """
    Convert XYZ basemap definition to folium format.
    
    Args:
        xyz (dict): XYZ basemap definition
        
    Returns:
        folium.TileLayer: Formatted basemap layer
    """

def xyz_to_plotly(xyz):
    """
    Convert XYZ basemap definition to plotly format.
    
    Args:
        xyz (dict): XYZ basemap definition
        
    Returns:
        dict: Plotly basemap configuration
    """

def xyz_to_bokeh(xyz):
    """
    Convert XYZ basemap definition to bokeh format.
    
    Args:
        xyz (dict): XYZ basemap definition
        
    Returns:
        bokeh.models.WMTSTileSource: Bokeh tile source
    """

def xyz_to_pydeck(xyz):
    """
    Convert XYZ basemap definition to pydeck format.
    
    Args:
        xyz (dict): XYZ basemap definition
        
    Returns:
        dict: Pydeck basemap configuration
    """

QuickMapServices Integration

Search and access basemaps from QuickMapServices (QMS) repository with thousands of additional providers.

def search_qms(keyword):
    """
    Search QuickMapServices for basemaps matching keyword.
    
    Args:
        keyword (str): Search term for basemap names/descriptions
        
    Returns:
        list: List of matching QMS basemap definitions
    """

def get_qms(qms_id):
    """
    Get specific QuickMapServices basemap by ID.
    
    Args:
        qms_id (int): QMS basemap ID
        
    Returns:
        dict: QMS basemap definition with tile URL and metadata
    """

def qms_to_leaflet(qms_id):
    """
    Convert QMS basemap to ipyleaflet format.
    
    Args:
        qms_id (int): QMS basemap ID
        
    Returns:
        ipyleaflet.TileLayer: Leaflet basemap layer
    """

def qms_to_folium(qms_id):
    """
    Convert QMS basemap to folium format.
    
    Args:
        qms_id (int): QMS basemap ID
        
    Returns:
        folium.TileLayer: Folium basemap layer
    """

Map-Level Basemap Methods

Add and manage basemaps directly on map instances with automatic styling and layer control integration.

def add_basemap(self, basemap='OpenStreetMap', show=True, **kwargs):
    """
    Add basemap to the map.
    
    Args:
        basemap (str or dict): Basemap name or custom definition
        show (bool): Whether to show the basemap immediately
        **kwargs: Basemap options (opacity, attribution, etc.)
    """

def change_basemap(self, basemap):
    """
    Change the current basemap.
    
    Args:
        basemap (str): New basemap name
    """

def add_xyz_service(self, provider, **kwargs):
    """
    Add XYZ tile service as basemap.
    
    Args:
        provider (str): XYZ provider name or URL template
        **kwargs: Service options (attribution, max_zoom, etc.)
    """

def add_wms_layer(self, url, layers, **kwargs):
    """
    Add WMS service as basemap layer.
    
    Args:
        url (str): WMS service URL
        layers (str): Comma-separated layer names
        **kwargs: WMS options (format, transparent, version, etc.)
    """

Built-in Basemap Providers

XYZ_TILES Dictionary

The package includes access to 100+ basemap providers through built-in XYZ_TILES and integration with xyzservices:

XYZ_TILES: dict  # Dictionary of 100+ basemap provider definitions

# Core XYZ tile providers dictionary structure:
XYZ_TILES = {
    'OpenStreetMap': {...},
    'ROADMAP': {...},           # Google Roads
    'SATELLITE': {...},         # Google Satellite  
    'TERRAIN': {...},          # Google Terrain
    'HYBRID': {...},           # Google Hybrid
    'Esri WorldImagery': {...},
    'CartoDB positron': {...},
    'CartoDB dark_matter': {...},
    'OpenTopoMap': {...},
    'Stamen Terrain': {...},
    'Stamen Toner': {...},
    'Stamen Watercolor': {...},
    # ... 80+ additional providers
}

# WMS service definitions
WMS_TILES: dict  # Dictionary of WMS service providers

# basemaps object with accessor methods
basemaps = Box(XYZ_TILES)  # Box object providing dot notation access

# Key basemap categories:
# - OpenStreetMap variants
# - Satellite imagery (Google, Esri, etc.)
# - Topographic maps
# - Terrain and elevation
# - Specialized themes (dark, light, etc.)
# - Historical and vintage maps

Popular Basemap Providers

OpenStreetMap Family

  • 'OpenStreetMap': Standard OSM
  • 'OpenTopoMap': Topographic styling
  • 'Stamen Terrain': Terrain visualization
  • 'Stamen Toner': High contrast black and white
  • 'Stamen Watercolor': Artistic watercolor style

Satellite and Imagery

  • 'SATELLITE': Google Satellite
  • 'ROADMAP': Google Roads
  • 'TERRAIN': Google Terrain
  • 'HYBRID': Google Hybrid
  • 'Esri WorldImagery': Esri satellite imagery
  • 'Esri NatGeoWorldMap': National Geographic styling

Specialized Maps

  • 'CartoDB positron': Light theme
  • 'CartoDB dark_matter': Dark theme
  • 'OpenRailwayMap': Railway infrastructure
  • 'OpenFireMap': Fire station and hydrant data

WMS Services

Access to Web Map Services for specialized data layers:

WMS_TILES: dict  # WMS service definitions

# Available WMS services include:
# - National weather services
# - Geological surveys
# - Land cover datasets
# - Administrative boundaries

Usage Examples

Basic Basemap Usage

import leafmap

# Create map with specific basemap
m = leafmap.Map(center=[40, -100], zoom=4, basemap='OpenTopoMap')

# Add additional basemap
m.add_basemap('SATELLITE', show=False)

# Add layer control to toggle basemaps
m.add_layer_control()

m

Custom Basemap Configuration

import leafmap

# Define custom XYZ basemap
custom_basemap = {
    'url': 'https://your-tile-server.com/{z}/{x}/{y}.png',
    'attribution': 'Your Attribution',
    'name': 'Custom Basemap',
    'max_zoom': 18
}

# Create map and add custom basemap
m = leafmap.Map()
m.add_xyz_service(custom_basemap)

m

QuickMapServices Integration

import leafmap

# Search for specific basemap type
results = leafmap.search_qms('satellite')
print(f"Found {len(results)} satellite basemaps")

# Use specific QMS basemap
m = leafmap.Map()

if results:
    qms_layer = leafmap.qms_to_leaflet(results[0]['id'])
    m.add_layer(qms_layer)

m

Backend-Specific Basemap Usage

# Get basemap dictionary
xyz_dict = leafmap.get_xyz_dict()

# Convert for different backends
import leafmap.foliumap as folium_map
import leafmap.plotlymap as plotly_map

# Folium backend
folium_basemap = leafmap.xyz_to_folium(xyz_dict['OpenStreetMap'])

# Plotly backend  
plotly_basemap = leafmap.xyz_to_plotly(xyz_dict['OpenStreetMap'])

WMS Layer Integration

import leafmap

# Add WMS weather layer
m = leafmap.Map()

m.add_wms_layer(
    url='https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi',
    layers='nexrad-n0r-900913',
    name='Weather Radar',
    format='image/png',
    transparent=True,
    opacity=0.6
)

m

Basemap Categories

Geographic and Physical

  • Topographic: Elevation contours, terrain features
  • Satellite: High-resolution imagery from space
  • Terrain: 3D-style terrain visualization
  • Bathymetry: Ocean floor and water depth

Thematic and Specialized

  • Transportation: Roads, railways, airports
  • Land Cover: Vegetation, urban areas, water bodies
  • Administrative: Political boundaries, census data
  • Historical: Vintage maps and historical imagery

Artistic and Stylized

  • Watercolor: Artistic rendering styles
  • Minimalist: Clean, simple designs
  • Dark/Light: Theme-based color schemes
  • High Contrast: Enhanced visibility options

Basemap Configuration Options

Standard Options

basemap_options = {
    'opacity': 1.0,           # Layer opacity (0-1)
    'attribution': 'Custom',   # Attribution text
    'max_zoom': 18,           # Maximum zoom level
    'min_zoom': 0,            # Minimum zoom level
    'tms': False,             # TMS tile ordering
    'show': True              # Initially visible
}

Advanced Options

advanced_options = {
    'subdomains': ['a', 'b', 'c'],  # Tile server subdomains
    'format': 'png',                # Tile format
    'tile_size': 256,               # Tile size in pixels
    'zoomOffset': 0,                # Zoom level offset
    'detectRetina': True,           # High DPI display support
    'crossOrigin': False            # CORS settings
}

WMS Specific Options

wms_options = {
    'layers': 'layer_name',         # WMS layer names
    'styles': '',                   # WMS styles
    'format': 'image/png',          # Image format
    'transparent': True,            # Background transparency
    'version': '1.1.1',            # WMS version
    'crs': 'EPSG:3857',            # Coordinate reference system
    'uppercase': False              # Parameter case sensitivity
}

Provider Information

Attribution Requirements

All basemap providers have specific attribution requirements. Leafmap automatically includes proper attribution for built-in providers:

  • OpenStreetMap: © OpenStreetMap contributors
  • Google: Map data ©2023 Google
  • Esri: Source: Esri, Maxar, Earthstar Geographics
  • CartoDB: © CartoDB, © OpenStreetMap contributors
  • Stamen: Map tiles by Stamen Design, under CC BY 3.0

Usage Policies

Different providers have varying usage policies:

  • OpenStreetMap: Open usage with attribution
  • Google: Requires API key for heavy usage
  • Esri: Terms of service apply
  • Commercial providers: May require subscription

Performance Considerations

  • Tile caching: Most providers cache tiles for performance
  • Rate limiting: Some providers limit request frequency
  • Regional availability: Some services may be region-restricted
  • Quality variations: Resolution and update frequency vary by provider

Install with Tessl CLI

npx tessl i tessl/pypi-leafmap

docs

basemaps.md

cloud-data.md

data-visualization.md

file-io.md

geospatial-analysis.md

index.md

interactive-maps.md

osm-integration.md

statistical-plotting.md

tile.json