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

data-visualization.mddocs/

Data Visualization

Comprehensive data visualization capabilities for vector and raster data with support for various formats including shapefiles, GeoJSON, COG, STAC, NetCDF, and online data sources.

Capabilities

Vector Data Visualization

Display and style vector data from files, GeoDataFrames, and online sources with comprehensive styling and interaction options.

def add_vector(self, filename, layer_name='Untitled', **kwargs):
    """
    Add vector data to the map.
    
    Args:
        filename (str): Path to vector file or URL
        layer_name (str): Display name for the layer
        **kwargs: Styling options (style, hover_style, popup, etc.)
    """

def add_geojson(self, data, layer_name='Untitled', **kwargs):
    """
    Add GeoJSON data to the map.
    
    Args:
        data (dict or str): GeoJSON data or file path
        layer_name (str): Display name for the layer
        **kwargs: Styling options
    """

def add_gdf(self, gdf, layer_name='Untitled', **kwargs):
    """
    Add GeoDataFrame to the map.
    
    Args:
        gdf (gpd.GeoDataFrame): GeoDataFrame to display
        layer_name (str): Display name for the layer
        **kwargs: Styling options
    """

def add_shp(self, shp, layer_name='Untitled', **kwargs):
    """
    Add shapefile to the map.
    
    Args:
        shp (str): Path to shapefile
        layer_name (str): Display name for the layer
        **kwargs: Styling options
    """

def add_kml(self, kml, layer_name='Untitled', **kwargs):
    """
    Add KML file to the map.
    
    Args:
        kml (str): Path to KML file
        layer_name (str): Display name for the layer
        **kwargs: Styling options
    """

Raster Data Visualization

Display raster data with customizable colormaps, value ranges, and transparency settings supporting various formats and online sources.

def add_raster(self, image, colormap=None, vmin=None, vmax=None, **kwargs):
    """
    Add raster data to the map.
    
    Args:
        image (str): Path to raster file
        colormap (str): Matplotlib colormap name
        vmin (float): Minimum value for color mapping
        vmax (float): Maximum value for color mapping
        **kwargs: Additional raster options (opacity, layer_name, etc.)
    """

def add_cog_layer(self, url, name='Untitled', **kwargs):
    """
    Add Cloud Optimized GeoTIFF layer.
    
    Args:
        url (str): URL to COG file
        name (str): Layer name
        **kwargs: COG visualization options (bands, colormap, rescale, etc.)
    """

def add_stac_layer(self, url, collection=None, item=None, **kwargs):
    """
    Add STAC (SpatioTemporal Asset Catalog) layer.
    
    Args:
        url (str): STAC URL or item URL
        collection (str): STAC collection ID
        item (str): STAC item ID
        **kwargs: STAC layer options (assets, bands, etc.)
    """

def add_netcdf(self, filename, variables=None, **kwargs):
    """
    Add NetCDF data to the map.
    
    Args:
        filename (str): Path to NetCDF file
        variables (list): Variables to display
        **kwargs: NetCDF visualization options
    """

Heatmaps and Point Data

Create heatmaps and visualize point data with various marker styles and clustering options.

def add_heatmap(self, data, latitude='latitude', longitude='longitude', **kwargs):
    """
    Add heatmap layer from point data.
    
    Args:
        data: DataFrame or list of points
        latitude (str): Column name for latitude values
        longitude (str): Column name for longitude values
        **kwargs: Heatmap options (radius, blur, max_zoom, etc.)
    """

def add_markers(self, markers, **kwargs):
    """
    Add point markers to the map.
    
    Args:
        markers (list): List of [lat, lon] coordinates or marker objects
        **kwargs: Marker styling (popup, tooltip, icon, etc.)
    """

def add_circle_markers_from_xy(self, data, x='longitude', y='latitude', **kwargs):
    """
    Add circle markers from coordinate data.
    
    Args:
        data: DataFrame with coordinate columns
        x (str): Column name for x/longitude coordinates
        y (str): Column name for y/latitude coordinates
        **kwargs: Circle marker options (radius, color, weight, etc.)
    """

def add_points_from_xy(self, data, x='longitude', y='latitude', **kwargs):
    """
    Add point markers from coordinate data.
    
    Args:
        data: DataFrame with coordinate columns
        x (str): Column name for x/longitude coordinates  
        y (str): Column name for y/latitude coordinates
        **kwargs: Point styling options
    """

Specialized Data Sources

Integration with specialized geospatial data sources and services.

def add_census_data(self, dataset='states', layer_name='Census Data', **kwargs):
    """
    Add US Census data to the map.
    
    Args:
        dataset (str): Census dataset name ('states', 'counties', etc.)
        layer_name (str): Layer name for display
        **kwargs: Census data options (year, variables, etc.)
    """

def add_nlcd(self, year=2019, region='conus', **kwargs):
    """
    Add National Land Cover Database data.
    
    Args:
        year (int): NLCD data year
        region (str): Geographic region ('conus', 'alaska', 'hawaii', 'pr')
        **kwargs: NLCD visualization options
    """

def add_nwi(self, layer_name='NWI', **kwargs):
    """
    Add National Wetlands Inventory data.
    
    Args:
        layer_name (str): Layer name for display
        **kwargs: NWI layer options
    """

def add_overture_data(self, bbox, theme, **kwargs):
    """
    Add Overture Maps data.
    
    Args:
        bbox (list): Bounding box [minx, miny, maxx, maxy]
        theme (str): Overture theme ('buildings', 'transportation', etc.)
        **kwargs: Overture data options
    """

3D Visualization (MapLibre GL JS Backend)

Advanced 3D visualization capabilities available with the MapLibre GL JS backend.

def add_3d_terrain(self, source=None, **kwargs):
    """
    Add 3D terrain visualization.
    
    Args:
        source: Terrain data source
        **kwargs: 3D terrain options (exaggeration, etc.)
    """

def add_sky_layer(self, **kwargs):
    """
    Add atmospheric sky layer for 3D scenes.
    
    Args:
        **kwargs: Sky layer options (sun_position, etc.)
    """

def add_3d_model(self, model_url, coordinates, **kwargs):
    """
    Add 3D model to the map.
    
    Args:
        model_url (str): URL to 3D model file
        coordinates (list): [longitude, latitude, altitude]
        **kwargs: 3D model options (scale, rotation, etc.)
    """

Image Comparison and Analysis

Tools for comparing and analyzing imagery with interactive features.

def image_comparison(self, img1, img2, **kwargs):
    """
    Create side-by-side image comparison.
    
    Args:
        img1 (str): Path to first image
        img2 (str): Path to second image
        **kwargs: Comparison options (labels, etc.)
    """

def create_timelapse(self, images, **kwargs):
    """
    Create animated timelapse from image series.
    
    Args:
        images (list): List of image paths or URLs
        **kwargs: Timelapse options (fps, loop, etc.)
    """

def add_time_slider(self, layers, **kwargs):
    """
    Add time slider control for temporal data.
    
    Args:
        layers (list): List of time-series layers
        **kwargs: Time slider options
    """

Styling Options

Vector Styling

# Style dictionary for vector data
vector_style = {
    'stroke': True,           # Draw stroke
    'color': '#3388ff',       # Stroke color
    'weight': 3,              # Stroke width
    'opacity': 1.0,           # Stroke opacity
    'fill': True,             # Fill polygons
    'fillColor': '#3388ff',   # Fill color
    'fillOpacity': 0.2,       # Fill opacity
    'dashArray': None,        # Dash pattern
    'lineCap': 'round',       # Line cap style
    'lineJoin': 'round'       # Line join style
}

# Hover style
hover_style = {
    'weight': 5,
    'fillOpacity': 0.5
}

Raster Styling

# Colormap options
colormaps = [
    'viridis', 'plasma', 'inferno', 'magma',  # Perceptually uniform
    'terrain', 'gist_earth', 'ocean',         # Earth/geographic
    'hot', 'cool', 'spring', 'summer',        # Temperature
    'jet', 'rainbow', 'hsv'                   # Classic
]

# Raster display options
raster_options = {
    'opacity': 0.8,           # Layer opacity
    'colormap': 'viridis',    # Color mapping
    'vmin': 0,                # Minimum value
    'vmax': 100,              # Maximum value
    'nodata': -9999,          # NoData value
    'layer_name': 'Raster'    # Display name
}

Usage Examples

Vector Data Visualization

import leafmap

# Create map
m = leafmap.Map(center=[40, -100], zoom=4)

# Add shapefile with custom styling
style = {
    'color': 'red',
    'weight': 2,
    'fillColor': 'yellow',
    'fillOpacity': 0.3
}

m.add_vector('path/to/data.shp', 
            layer_name='Custom Layer',
            style=style)

# Add GeoJSON with popup
m.add_geojson('data.geojson',
             layer_name='GeoJSON Layer',
             popup=['name', 'value'])

m

Raster Data Visualization

import leafmap

# Create map
m = leafmap.Map()

# Add raster with custom colormap
m.add_raster('elevation.tif',
            colormap='terrain',
            vmin=0,
            vmax=4000,
            layer_name='Elevation',
            opacity=0.7)

# Add COG from URL
m.add_cog_layer('https://example.com/data.tif',
               name='Remote COG',
               rescale='0,255',
               colormap='viridis')

m

Heatmap Creation

import leafmap
import pandas as pd

# Load point data
df = pd.read_csv('points.csv')

# Create map
m = leafmap.Map()

# Add heatmap
m.add_heatmap(df,
             latitude='lat',
             longitude='lon',
             radius=15,
             blur=10,
             max_zoom=18)

m

Data Format Support

Vector Formats

  • Shapefile (.shp)
  • GeoJSON (.geojson, .json)
  • KML/KMZ (.kml, .kmz)
  • GeoPackage (.gpkg)
  • GML (.gml)
  • PostGIS (via connection string)

Raster Formats

  • GeoTIFF (.tif, .tiff)
  • Cloud Optimized GeoTIFF (COG)
  • NetCDF (.nc, .nc4)
  • HDF5 (.h5, .hdf5)
  • JPEG2000 (.jp2)
  • PNG (.png)
  • JPEG (.jpg, .jpeg)

Online Sources

  • STAC catalogs and items
  • WMS/WMTS services
  • XYZ tile services
  • PMTiles archives
  • S3/cloud storage URLs

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