PyMapGIS Documentation

Modern GIS toolkit for Python - Simplifying geospatial workflows with built-in data sources, intelligent caching, and fluent APIs

View the Project on GitHub pymapgis/core

Interactive Mapping with Leafmap Example

This example demonstrates how to use PyMapGIS to load geospatial data and create an interactive choropleth map using its Leafmap integration.

Description

The Python script interactive_map_example.py performs the following steps:

  1. Imports PyMapGIS: import pymapgis as pmg.
  2. Loads Data: It fetches US state-level geometry and land area data from the TIGER/Line data provider for the year 2022.
  3. Data Preparation: Ensures the land area column (ALAND) is in a numeric format.
  4. Creates Map: It generates an interactive choropleth map where the color intensity of each state corresponds to its land area.
  5. Saves Map: The interactive map is saved as an HTML file (us_states_land_area_map.html) in the script’s directory. Tooltips will show the state name and its land area.

How to Run

  1. Ensure PyMapGIS is installed: If you haven’t installed PyMapGIS and its optional dependencies for mapping, you might need to: ```bash pip install pymapgis[leafmap] ``` or ```bash pip install pymapgis leafmap ```

  2. Navigate to the example directory: ```bash cd docs/examples/interactive_mapping_leafmap ```

  3. Run the script: ```bash python interactive_map_example.py ```

Expected Output

Note on Display

If you run this script in a Jupyter Notebook environment, the map might display directly within the notebook after the cell execution, depending on your Leafmap and Jupyter setup. The script explicitly saves to an HTML file for broader compatibility.