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

πŸ“¦ Package Structure

Overview

This document provides a detailed breakdown of PyMapGIS’s package structure, explaining the purpose and contents of each module, submodule, and key files.

Root Package Structure

pymapgis/
β”œβ”€β”€ __init__.py                 # Main API surface and lazy imports
β”œβ”€β”€ settings.py                 # Global settings and configuration
β”œβ”€β”€ cache.py                    # Legacy cache utilities
β”œβ”€β”€ plotting.py                 # Legacy plotting functions
β”œβ”€β”€ acs.py                      # American Community Survey utilities
β”œβ”€β”€ tiger.py                    # TIGER/Line data utilities
β”œβ”€β”€ cli.py                      # Legacy CLI entry point
β”œβ”€β”€ serve.py                    # Legacy serve functionality
└── [modules]/                  # Core module directories

Core Modules

1. IO Module (pymapgis/io/)

Purpose: Universal data reading and format handling

io/
β”œβ”€β”€ __init__.py                 # Main read() function and registry
β”œβ”€β”€ base.py                     # Base classes and interfaces
β”œβ”€β”€ registry.py                 # Data source plugin registry
β”œβ”€β”€ formats/                    # Format-specific handlers
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ geojson.py             # GeoJSON format handler
β”‚   β”œβ”€β”€ shapefile.py           # Shapefile format handler
β”‚   β”œβ”€β”€ geopackage.py          # GeoPackage format handler
β”‚   └── raster.py              # Raster format handlers
β”œβ”€β”€ sources/                    # Data source implementations
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ census.py              # Census API integration
β”‚   β”œβ”€β”€ tiger.py               # TIGER/Line data source
β”‚   β”œβ”€β”€ file.py                # Local file data source
β”‚   β”œβ”€β”€ http.py                # HTTP/URL data source
β”‚   └── cloud.py               # Cloud storage data sources
└── utils.py                    # IO utility functions

Key Components:

2. Vector Module (pymapgis/vector/)

Purpose: Vector spatial operations and GeoPandas integration

vector/
β”œβ”€β”€ __init__.py                 # Core vector operations
β”œβ”€β”€ operations.py               # Spatial operation implementations
β”œβ”€β”€ accessors.py                # GeoDataFrame accessor methods
β”œβ”€β”€ geoarrow_utils.py          # GeoArrow integration utilities
β”œβ”€β”€ spatial_index.py           # Spatial indexing optimizations
└── utils.py                    # Vector utility functions

Key Components:

3. Raster Module (pymapgis/raster/)

Purpose: Raster processing and xarray integration

raster/
β”œβ”€β”€ __init__.py                 # Core raster operations
β”œβ”€β”€ operations.py               # Raster operation implementations
β”œβ”€β”€ accessors.py                # DataArray accessor methods
β”œβ”€β”€ cog.py                      # Cloud Optimized GeoTIFF utilities
β”œβ”€β”€ zarr_utils.py              # Zarr format utilities
β”œβ”€β”€ reprojection.py            # Coordinate system transformations
└── utils.py                    # Raster utility functions

Key Components:

4. Visualization Module (pymapgis/viz/)

Purpose: Interactive mapping and visualization

viz/
β”œβ”€β”€ __init__.py                 # Main visualization functions
β”œβ”€β”€ accessors.py                # Accessor methods for mapping
β”œβ”€β”€ leafmap_integration.py      # Leafmap backend integration
β”œβ”€β”€ styling.py                  # Styling and symbology
β”œβ”€β”€ exports.py                  # Export functionality
└── utils.py                    # Visualization utilities

Key Components:

5. Serve Module (pymapgis/serve/)

Purpose: Web services and tile serving

serve/
β”œβ”€β”€ __init__.py                 # Main serve() function
β”œβ”€β”€ app.py                      # FastAPI application factory
β”œβ”€β”€ tiles/                      # Tile generation
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ xyz.py                 # XYZ tile service
β”‚   β”œβ”€β”€ wms.py                 # WMS service
β”‚   └── mvt.py                 # Vector tile (MVT) service
β”œβ”€β”€ middleware.py              # Custom middleware
β”œβ”€β”€ auth.py                    # Service authentication
└── utils.py                   # Service utilities

Key Components:

6. CLI Module (pymapgis/cli/)

Purpose: Command-line interface

cli/
β”œβ”€β”€ __init__.py                 # CLI app and imports
β”œβ”€β”€ main.py                     # Main Typer application
β”œβ”€β”€ commands/                   # Command implementations
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ info.py                # System information commands
β”‚   β”œβ”€β”€ cache.py               # Cache management commands
β”‚   β”œβ”€β”€ rio.py                 # Rasterio CLI passthrough
β”‚   └── serve.py               # Service commands
└── utils.py                   # CLI utilities

Key Components:

Advanced Modules

7. Authentication Module (pymapgis/auth/)

Purpose: Enterprise authentication and security

auth/
β”œβ”€β”€ __init__.py                 # Main auth exports
β”œβ”€β”€ api_keys.py                # API key management
β”œβ”€β”€ oauth.py                   # OAuth providers
β”œβ”€β”€ rbac.py                    # Role-based access control
β”œβ”€β”€ sessions.py                # Session management
β”œβ”€β”€ security.py               # Security utilities
β”œβ”€β”€ middleware.py              # Authentication middleware
└── providers/                 # OAuth provider implementations
    β”œβ”€β”€ __init__.py
    β”œβ”€β”€ google.py              # Google OAuth
    β”œβ”€β”€ microsoft.py           # Microsoft OAuth
    └── github.py              # GitHub OAuth

8. Cloud Module (pymapgis/cloud/)

Purpose: Cloud storage and processing integration

cloud/
β”œβ”€β”€ __init__.py                 # Main cloud functions
β”œβ”€β”€ storage.py                 # Cloud storage abstraction
β”œβ”€β”€ providers/                 # Cloud provider implementations
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ aws.py                 # AWS S3 integration
β”‚   β”œβ”€β”€ gcp.py                 # Google Cloud Storage
β”‚   └── azure.py               # Azure Blob Storage
β”œβ”€β”€ processing.py              # Cloud processing utilities
└── utils.py                   # Cloud utilities

9. Streaming Module (pymapgis/streaming/)

Purpose: Real-time data processing

streaming/
β”œβ”€β”€ __init__.py                 # Main streaming exports
β”œβ”€β”€ kafka_integration.py       # Apache Kafka integration
β”œβ”€β”€ mqtt_integration.py        # MQTT integration
β”œβ”€β”€ processors.py              # Stream processing utilities
β”œβ”€β”€ buffers.py                 # Data buffering strategies
└── utils.py                   # Streaming utilities

10. Machine Learning Module (pymapgis/ml/)

Purpose: Spatial ML and analytics

ml/
β”œβ”€β”€ __init__.py                 # Main ML exports
β”œβ”€β”€ features.py                # Spatial feature engineering
β”œβ”€β”€ sklearn_integration.py     # Scikit-learn integration
β”œβ”€β”€ spatial_algorithms.py      # Spatial ML algorithms
β”œβ”€β”€ evaluation.py              # Model evaluation
β”œβ”€β”€ preprocessing.py           # Data preprocessing
└── pipelines.py               # ML pipeline utilities

11. Network Module (pymapgis/network/)

Purpose: Network analysis and routing

network/
β”œβ”€β”€ __init__.py                 # Main network exports
β”œβ”€β”€ graph.py                   # Graph construction
β”œβ”€β”€ routing.py                 # Routing algorithms
β”œβ”€β”€ analysis.py                # Network analysis
β”œβ”€β”€ osm_integration.py         # OpenStreetMap integration
└── utils.py                   # Network utilities

12. Point Cloud Module (pymapgis/pointcloud/)

Purpose: 3D point cloud processing

pointcloud/
β”œβ”€β”€ __init__.py                 # Main point cloud exports
β”œβ”€β”€ pdal_integration.py        # PDAL integration
β”œβ”€β”€ processing.py              # Point cloud processing
β”œβ”€β”€ visualization.py           # 3D visualization
β”œβ”€β”€ formats.py                 # Format handling (LAS, LAZ, etc.)
└── utils.py                   # Point cloud utilities

Infrastructure Modules

13. Cache Module (pymapgis/cache/)

Purpose: Intelligent caching system

cache/
β”œβ”€β”€ __init__.py                 # Main cache functions
β”œβ”€β”€ manager.py                 # Cache management
β”œβ”€β”€ backends/                  # Cache backend implementations
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ memory.py              # In-memory caching
β”‚   β”œβ”€β”€ disk.py                # Disk-based caching
β”‚   └── redis.py               # Redis caching
β”œβ”€β”€ strategies.py              # Caching strategies
└── utils.py                   # Cache utilities

14. Settings Module (pymapgis/settings/)

Purpose: Configuration management

settings/
β”œβ”€β”€ __init__.py                 # Settings exports
β”œβ”€β”€ config.py                  # Configuration classes
β”œβ”€β”€ validation.py              # Settings validation
β”œβ”€β”€ defaults.py                # Default configurations
└── utils.py                   # Settings utilities

15. Plugins Module (pymapgis/plugins/)

Purpose: Plugin system and extensions

plugins/
β”œβ”€β”€ __init__.py                 # Plugin system exports
β”œβ”€β”€ registry.py                # Plugin registry
β”œβ”€β”€ base.py                    # Base plugin classes
β”œβ”€β”€ loader.py                  # Plugin loading utilities
β”œβ”€β”€ discovery.py               # Plugin discovery
└── examples/                  # Example plugins
    β”œβ”€β”€ __init__.py
    └── sample_plugin.py       # Sample plugin implementation

Deployment and Testing Modules

16. Deployment Module (pymapgis/deployment/)

Purpose: Deployment utilities and configurations

deployment/
β”œβ”€β”€ __init__.py                 # Deployment exports
β”œβ”€β”€ docker.py                  # Docker utilities
β”œβ”€β”€ kubernetes.py              # Kubernetes configurations
β”œβ”€β”€ cloud_deploy.py            # Cloud deployment
β”œβ”€β”€ monitoring.py              # Monitoring setup
└── utils.py                   # Deployment utilities

17. Testing Module (pymapgis/testing/)

Purpose: Testing utilities and fixtures

testing/
β”œβ”€β”€ __init__.py                 # Testing exports
β”œβ”€β”€ fixtures.py                # Common test fixtures
β”œβ”€β”€ data.py                    # Test data generation
β”œβ”€β”€ mocks.py                   # Mock objects
β”œβ”€β”€ assertions.py              # Custom assertions
└── utils.py                   # Testing utilities

18. Performance Module (pymapgis/performance/)

Purpose: Performance optimization and profiling

performance/
β”œβ”€β”€ __init__.py                 # Performance exports
β”œβ”€β”€ profiling.py               # Profiling utilities
β”œβ”€β”€ optimization.py            # Optimization strategies
β”œβ”€β”€ benchmarks.py              # Benchmark utilities
β”œβ”€β”€ monitoring.py              # Performance monitoring
└── utils.py                   # Performance utilities

File Naming Conventions

Module Files

Implementation Files

Test Files

Import Strategy

Lazy Imports

Public API

Internal APIs


Next: Design Patterns for architectural patterns used throughout PyMapGIS