15. Introduction to Geospatial Python#
15.1. Introduction#
15.2. The Geospatial Python Ecosystem#
15.2.1. Foundation Libraries#
15.2.2. Data Structures and Analysis#
15.2.3. Interactive Visualization#
15.2.4. Specialized Analysis#
15.2.5. Application Development#
15.3. Understanding Library Relationships#
15.4. Setting Up Your Environment#
15.4.1. Option 1: Using uv (Recommended for Beginners)#
# Install uv
# macOS and Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Create virtual environment
uv venv
# Activate environment
# macOS and Linux:
source .venv/bin/activate
# Windows:
.venv\Scripts\activate
# Install geospatial package (includes most libraries covered in this book)
uv pip install --find-links https://girder.github.io/large_image_wheels gdal pyproj
uv pip install pygis
15.4.2. Option 2: Using pixi (For Complex Dependencies)#
# Install pixi
# macOS and Linux:
curl -fsSL https://pixi.sh/install.sh | bash
# Windows:
iwr -useb https://pixi.sh/install.ps1 | iex
# Initialize project and add dependencies
pixi init
pixi add pygis jupyterlab
pixi run jupyter lab
15.4.3. Option 3: Using conda/mamba (Traditional Approach)#
# Create environment
conda create -n geo python=3.12
conda activate geo
# Install from conda-forge
conda install -c conda-forge mamba
mamba install -c conda-forge pygis
15.5. Verification and First Steps#
# Test core geospatial libraries
import geopandas as gpd
import rasterio
import xarray as xr
import rioxarray
import leafmap
import pandas as pd
import numpy as np
print("✓ All core libraries imported successfully!")
15.5.1. Create Your First Interactive Map#
# Create an interactive map using Leafmap
m = leafmap.Map(center=[40, -100], zoom=4, height="500px")
# Add different basemap options
m.add_basemap("OpenTopoMap")
m.add_basemap("USGS.Imagery")
# Display the map
m