leafmap

repository·master·Indexed 25 days ago

https://github.com/opengeos/leafmap

A Python package for interactive geospatial mapping and analysis optimized for Jupyter environments, including Google Colab, JupyterLab, and marimo. It provides a high-level API and interactive GUIs for loading and visualizing raster and vector data, integrating with WhiteboxTools for advanced analysis, and supporting multiple plotting backends such as ipyleaflet, folium, pydeck, kepler.gl, and bokeh.

Tokens
164.8K
Snippets
642
Records
971
Agent score
85%

What's inside leafmap

  1. Overview of leafmap

    master

    leafmap is a Python package designed for interactive mapping and geospatial analysis within Jupyter environments (such as Google Colab, Jupyter Notebook, JupyterLab, and marimo). It is a spin-off of the geemap package, specifically designed for users who do not require Google Earth Engine (GEE).

    Key characteristics:

    • Minimal Coding: Enables loading and visualizing geospatial datasets with very little code.
    • Interactive GUI: Provides tools to load vector and raster data and perform advanced geospatial analysis (via WhiteboxTools) directly through a user interface.
    • Bidirectional Communication: Leverages ipyleaflet to allow interaction between the map frontend and the Python backend.
    • Extensive Analysis: Integrates with WhiteboxTools for over 500+ advanced geospatial analysis tools (e.g., hydrological, geomorphometric, and LiDAR analysis).
  2. Key features of leafmap

    master

    leafmap provides a comprehensive suite of mapping and analysis capabilities:

    Mapping & Visualization

    • Multiple Backends: Supports ipyleaflet, folium, kepler.gl, pydeck, and bokeh.
    • Basemaps & Services: Interactive basemap switching and support for XYZ, WMS, and vector tile services.
    • Data Display: Supports vector data (Shapefile, GeoJSON, GeoPackage, GeoPandas formats) and raster data (GeoTIFFs).
    • Advanced Map Types: Creation of split-panel maps, linked maps, choropleth maps, heat maps, and time series animations.
    • Customization: Tools for creating custom legends and colorbars.

    Data Interaction & Discovery

    • Interactive Editing: Tools to create and edit vector data (points, lines, polygons) directly on the map.
    • Data Inspection: Interactive pixel value inspection for raster datasets.
    • Data Search: Access to geospatial data from STAC, Microsoft Planetary Computer, AWS Open Data Registry, and OpenAerialMap.
    • Database Integration: Display spatial data from PostGIS databases.

    Analysis & Web Apps

    • Geospatial Analysis: Integration with WhiteboxTools for advanced analysis and segment-geospatial for remote sensing imagery segmentation/classification.
    • Web Application Building: Compatible with frameworks like Voila, Streamlit, and Solara for building interactive web apps.
  3. Set up leafmap for local development

    master

    To contribute to leafmap, follow these steps to set up a local development environment using conda and pip:

    1. Fork the repository on GitHub.
    2. Clone your fork locally.
    3. Create and activate a new conda environment.
    4. Install the package in editable mode (-e) so changes are reflected immediately.
    5. Create a new branch for your work.

    Ensure you have flake8 and tox installed in your environment to run linting and tests.

    # 1. Clone your fork
    git clone git@github.com:your_name_here/leafmap.git
    
    # 2. Create and activate a conda environment
    conda create -n leafmap-test python
    conda activate leafmap-test
    
    # 3. Install in editable mode
    cd leafmap/
    pip install -e .
    
    # 4. Create a development branch
    git checkout -b name-of-your-bugfix-or-feature
  4. Use the heremap backend

    master

    The heremap backend provides 3D mapping functionality but requires a HERE developer account and an API key.

    Prerequisites:

    1. Obtain an API key from the HERE Developer Portal.
    2. Set the HEREMAPS_API_KEY environment variable or pass it directly to the Map constructor.
    import os
    import leafmap.heremap as leafmap
    
    # Option 1: Set via environment variable
    os.environ["HEREMAPS_API_KEY"] = "YOUR_HEREMAPS_API_KEY"
    api_key = os.environ.get("HEREMAPS_API_KEY")
    
    # Option 2: Pass directly to Map
    m = leafmap.Map(api_key=api_key, center=(40, -100), zoom=4)
    m
  5. Install leafmap via conda-forge

    master

    If you use Anaconda or Miniconda, you can install leafmap from the conda-forge channel.

    Recommended Setup for Windows Users: Because some optional dependencies (like geopandas and localtileserver) can be difficult to install on Windows, it is highly recommended to create a fresh conda environment using mamba to ensure all dependencies are resolved correctly.