Skip to content

A FastAPI service for efficient geospatial data management, queries, and advanced spatial analysis.

Notifications You must be signed in to change notification settings

TAnas0/GeoSpatialNexus

Repository files navigation

PolygonFinder

This REST API helps you keep track of Service Areas and determine whether a geo point falls within any of your service areas.

Architecture

  • PostgreSQL with PostGIS extensions
  • FastAPI as the web framework
  • SQLAlchemy as the ORM
  • GeoAlchemy2 for managing geo data format
  • Alembic for database schema migrations

Requirements

  • Python 3.10
  • Docker & Docker Compose

Getting Started

You can quickly get started by running a single command: docker-compose up -d. This will launch a Postgres database with PostGIS installed, apply Alembic migrations on the database and serve the API.

If you wish to run the API locally for the sake of easier development and debugging, you can proceed as follows:

  1. Run the Postgres Database:
docker-compose up -d db pgadmin
  1. Install Python dependencies:
pip install -r requirements.txt
  1. Set up environment variables:
cp .env.sample .env
  1. Apply database migrations:
alembic upgrade head
  1. Run the application:
uvicorn src.main:app --reload

Endpoints

Providers:

  • GET api/v1/providers: List all providers
  • POST api/v1/providers: Create a new provider
  • GET api/v1/providers/{id}: Get details of a provider
  • PUT api/v1/providers/{id}: Update a provider
  • DELETE /providers/{id}: Delete a provider

Service Areas:

  • GET api/v1/service-areas: List all service areas
  • POST api/v1/service-areas: Create a new service area
  • GET api/v1/service-areas/{id}: Get details of a service area
  • PUT api/v1/service-areas/{id}: Update a service area
  • DELETE api/v1/service-areas/{id}: Delete a service area

Point Geospatial Querying:

  • GET api/v1/service-areas/search?lat={latitude}&lng={longitude}: Find service areas containing a specific geo point

Testing

To test using curl commands, you can try creating a Service Area, and check if a latitude/longitude pair is contained in the registered Service Areas:

curl -X 'POST'   'http://127.0.0.1:8000/api/v1/serviceareas/'   -H 'Content-Type: application/json'   -d '{
  "name": "Downtown Area 2",
  "price": 25.50,
  "geojson": "{\"type\": \"Polygon\", \"coordinates\": [[[30.0, 10.0], [40.0, 40.0], [20.0, 40.0], [10.0, 20.0], [30.0, 10.0]]]}"
}'

curl -X GET "http://localhost:8000/api/v1/serviceareas/check?lat=30&lng=20"

To run the unit tests:

pytest

Deployment

We recommend you stick to the Docker Copose setup to deploy the API on an AWS EC2 instance: docker-compose build -d. This will include the Postgres database, run the Alembic migrations to create the database schema, and serve the PolygonFinder API.

You can find an example hosted online at http://13.51.79.167:8000.

You can try it out with the following curl commands:

curl -X 'POST'   'http://13.51.79.167:8000/api/v1/serviceareas/'   -H 'Content-Type: application/json'   -d '{
  "name": "Downtown Area",
  "price": 25.50,
  "geojson": "{\"type\": \"Polygon\", \"coordinates\": [[[30.0, 10.0], [40.0, 40.0], [20.0, 40.0], [10.0, 20.0], [30.0, 10.0]]]}"
}'

curl -X GET "http://13.51.79.167:8000/api/v1/serviceareas/check?lat=30&lng=200"

About

A FastAPI service for efficient geospatial data management, queries, and advanced spatial analysis.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published