Talks - Lazouich Ford: Geospatial Validations Using FastAPI and PostGIS

Learn how to validate geospatial data using FastAPI and PostGIS, covering coordinate systems, Pydantic models, shapefiles, and best practices for handling geographic data in web APIs.

Key takeaways
  • PostGIS is a Postgres extension that enables working with geospatial data and queries through functions like st-makepoint, st-intersects, and st-distance

  • FastAPI can be used to validate geospatial data through:

    • Pydantic models
    • Dependency injection
    • Response model validation
  • Shapefiles consist of multiple files containing different portions of data:

    • Geometry data
    • Spatial reference data
    • Table/attribute data
  • When working with geospatial data, important considerations include:

    • Earth’s curvature affects distance measurements
    • Different projection types have various trade-offs
    • Spatial Reference IDs (SRIDs) need proper handling
    • Data from different reference systems requires transformation
  • Common validation patterns:

    • Checking if points intersect with boundaries
    • Validating coordinates are within expected regions
    • Transforming between coordinate systems
    • Protecting against bad incoming data
  • Best practices:

    • Use SQL files over raw shapefiles for data loading
    • Validate both incoming and outgoing data
    • Consider computational costs of geospatial operations
    • Use geoalchemy2 for ORM integration with PostGIS
  • The st-transform function is crucial for converting between different coordinate systems and ensuring accurate geospatial calculations