Skip to content
VarunGore36Public

About

AI-powered geospatial intelligence API that converts satellite imagery and geographic datasets into structured, actionable intelligence.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

62 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌍 GeoMind

AI-powered geospatial intelligence platform.

License: MIT Python 3.11+ FastAPI PostGIS Tests Docker


GeoMind transforms open geospatial data β€” satellite imagery, OpenStreetMap, elevation models, and live camera feeds β€” into structured, queryable, actionable intelligence through developer-friendly APIs.

🎯 Vision

Make geographic intelligence accessible through simple APIs and scalable infrastructure β€” no GIS expertise required.


πŸ›°οΈ Core Modules

1. Location Intelligence API (/api/v1/location-intelligence)

Extract real-world metrics around any coordinate:

Metric Description Unit
Building Density Footprint area Γ· analysis area ratio (0–1)
Road Density Total road length Γ· area km/kmΒ²
Vegetation Coverage Vegetated land Γ· area ratio (0–1)
Water Proximity Distance to nearest water + coverage meters + ratio
Elevation Center + ring samples (min/max/mean) meters

Data sources: OpenStreetMap (via Overpass API), SRTM elevation (OpenTopoData/Open-Elevation)
Provenance: Every response includes source metadata, cache status, timestamps, and licenses (ODbL, public domain).

curl "http://localhost:8000/api/v1/location-intelligence?lat=52.52&lon=13.405&radius_m=500"

2. Camera Pipeline (/api/v1/cameras)

Ingest live MJPEG/JPEG feeds, deduplicate, and serve latest frames.

Feature Details
Multi-feed Configure N cameras with individual intervals
Deduplication Perceptual hash (pHash) β€” skips visually identical frames
Scheduling APScheduler with per-feed intervals + exponential backoff retries
Storage Files organized by camera_id/YYYYMMDD_HHMMSS_NNNNNN.jpg
Persistence Async SQLAlchemy (PostgreSQL/SQLite) for frame metadata
API Health, list, latest frame (JSON + JPEG), manual trigger

Config (cameras.yaml):

feeds:
  - feed_url: "https://images.webcams.travel/api/cam/1471069946/image.jpg"
    camera_id: "nyc_times_square"
    fetch_interval_seconds: 30
    timeout_seconds: 10
    max_retries: 3

3. Vision Engine β€” Wildfire Detection (/api/v1/vision)

Real-time smoke and fire detection from camera frames using ONNX Runtime.

Feature Details
Model ONNX Runtime (YOLO-style) with custom wildfire classes (smoke=0, fire=1)
Temporal Validation Requires N consecutive frames (default 3) with confidence threshold
Detection States pending β†’ confirmed / rejected
Queue Async frame processing with configurable workers & batch size
Storage SQLite/PostgreSQL for detection events & confirmed incidents
API List events, latest per camera, real-time WebSocket streaming

Config (vision.yaml):

model:
  type: "onnx"           # dummy, yolo, wildfire, onnx, onnxruntime
  weights_path: "./models/wildfire_yolov8n.onnx"
  device: "cpu"          # cpu, cuda, mps
  confidence_threshold: 0.25
  iou_threshold: 0.45
  input_size: 640
  classes: [0, 1]        # smoke, fire
temporal:
  min_consecutive_frames: 3
  frame_confidence_threshold: 0.3
  max_frame_gap_seconds: 60.0

4. Authentication & Authorization (/api/v1/auth)

JWT + API Key authentication with Role-Based Access Control.

Feature Details
JWT Access (15m) + Refresh (7d) tokens, HS256
API Keys Hashed storage, per-key rate limits, expiration
Roles admin, user, viewer, service
Rate Limiting Token bucket (per-minute + per-hour) by IP / API key / Bearer token
Endpoints Login, refresh, logout, register, user management, API key CRUD

5. Real-time WebSocket Streaming (/ws/connect)

Pub/Sub for live detection events and camera status.

Channel Events
detections All detection events (pending + confirmed)
detections:confirmed Only temporally validated detections
detections:pending Pending detections awaiting confirmation
cameras Camera status updates (active, error, fps)
system System notifications

Features: JWT/API key auth, channel subscriptions with filters (camera_id, class_name, min_confidence), heartbeat/ping-pong, auto-reconnect.


6. Monitoring & Observability

Component Details
Prometheus /metrics endpoint with 50+ custom metrics
Grafana Pre-built dashboard (16 panels)
Alerting 25+ alert rules (API, DB, cache, vision, auth, business)
Recording Rules Pre-computed percentiles, rates, ratios
Health /health (liveness), /health/ready (readiness)

πŸš€ Quick Start

Docker (Recommended)

git clone https://github.com/VarunGore36/GeoMind
cd GeoMind

# Start PostGIS + Redis + API
docker-compose up -d

# API at http://localhost:8000
# Docs at http://localhost:8000/docs
# Dev server (hot reload) at http://localhost:8001

Local Development

# Install with all extras
pip install -e ".[camera,vision,auth,dev]"

# Copy config templates
cp cameras.yaml.example cameras.yaml
cp vision.yaml.example vision.yaml
cp auth.yaml.example auth.yaml
cp metrics.yaml.example metrics.yaml

# Edit configs with your settings
# ...

# Run
GEOMIND_CAM_CONFIG_PATH=cameras.yaml python -m src.geomind.main

πŸ“‘ API Reference

Location Intelligence

Method Endpoint Description
GET /api/v1/location-intelligence Extract features around a point
Query params lat, lon, radius_m (optional), refresh (optional) WGS84 coords, radius in meters

Camera Pipeline

Method Endpoint Description
GET /api/v1/cameras/health All cameras status + frame counts
GET /api/v1/cameras List configured cameras
GET /api/v1/cameras/{id} Single camera status
GET /api/v1/cameras/{id}/latest Latest frame metadata
GET /api/v1/cameras/{id}/latest/image Latest frame as JPEG
POST /api/v1/cameras/{id}/fetch Trigger immediate fetch

Vision Engine

Method Endpoint Description
GET /api/v1/vision/events List detection events (paginated, filterable)
GET /api/v1/vision/events/latest/{camera_id} Latest event for camera
GET /api/v1/vision/health Vision engine health

Authentication

Method Endpoint Description
POST /api/v1/auth/login Get access + refresh tokens
POST /api/v1/auth/refresh Refresh access token
POST /api/v1/auth/logout Invalidate tokens
POST /api/v1/auth/register Register new user
GET /api/v1/auth/users List users (admin)
GET /api/v1/auth/users/{id} Get user
PATCH /api/v1/auth/users/{id} Update user
DELETE /api/v1/auth/users/{id} Delete user
POST /api/v1/auth/api-keys Create API key
GET /api/v1/auth/api-keys List API keys
DELETE /api/v1/auth/api-keys/{id} Revoke API key

WebSocket

Method Endpoint Description
WS /ws/connect WebSocket connection endpoint
GET /api/v1/ws/stats Connection statistics
GET /api/v1/ws/channels Active channels + subscriber counts
GET /api/v1/ws/connections List connections (admin)

Health & Meta

Method Endpoint Description
GET /health Liveness probe
GET /health/ready Readiness (DB + PostGIS)
GET / Service metadata
GET /metrics Prometheus metrics

πŸ“Š Example Response

Location Intelligence:

{
  "query": { "latitude": 52.52, "longitude": 13.405, "radius_m": 500, "area_m2": 785398 },
  "features": {
    "building_density": { "value": 0.21, "building_count": 244, "footprint_area_m2": 164983 },
    "road_density": { "value": 57.3, "unit": "km/km2", "road_length_m": 44970 },
    "vegetation_coverage": { "value": 0.26, "vegetation_area_m2": 208049 },
    "water_proximity": { "nearest_distance_m": 125, "water_coverage_ratio": 0.056 },
    "elevation": { "value": 49, "min_m": 33, "max_m": 58, "mean_m": 44.2, "samples": 5 }
  },
  "provenance": {
    "sources": [
      { "name": "OpenStreetMap", "license": "ODbL-1.0" },
      { "name": "Elevation", "dataset": "srtm30m", "license": "Public domain" }
    ],
    "cache": { "hit": false, "ttl_s": 86400 }
  }
}

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         GeoMind API                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Location Intelligence       β”‚  Camera Pipeline                 β”‚
β”‚  ─────────────────────────   β”‚  ────────────────────            β”‚
β”‚  Overpass API (OSM)    ────▢ β”‚  Camera Feeds (MJPEG/JPEG)       β”‚
β”‚  OpenTopoData (SRTM)  ────▢  β”‚  ────────────────────            β”‚
β”‚  ─────────────────────────   β”‚  APScheduler ◀──── Intervals      β”‚
β”‚  PostGIS (metrics)           β”‚  ────────────────────            β”‚
β”‚  ─────────────────────────   β”‚  Fetcher (HTTP + Retry)           β”‚
β”‚  FastAPI /v1/location-intel  β”‚  ────────────────────            β”‚
β”‚                              β”‚  pHash Dedup                      β”‚
β”‚                              β”‚  ────────────────────            β”‚
β”‚                              β”‚  Files + Postgres                 β”‚
β”‚                              β”‚  ────────────────────            β”‚
β”‚                              β”‚  FastAPI /v1/cameras              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Vision Engine               β”‚  WebSocket / Auth / Monitoring   β”‚
β”‚  ─────────────────────────   β”‚  ─────────────────────────       β”‚
β”‚  ONNX Runtime (YOLO)         β”‚  JWT + API Keys (RBAC)           β”‚
β”‚  Temporal Validation (N=3)   β”‚  Token Bucket Rate Limiting      β”‚
β”‚  SQLite/Postgres Events      β”‚  WebSocket Pub/Sub               β”‚
β”‚  ─────────────────────────   β”‚  Prometheus /metrics             β”‚
β”‚  FastAPI /v1/vision          β”‚  Grafana Dashboards              β”‚
β”‚                              β”‚  Alerting Rules                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • Async throughout β€” FastAPI + asyncpg + SQLAlchemy 2.0
  • PostGIS β€” spatial indexes, UTM projection for accurate metrics
  • Caching β€” 24h TTL for OSM coverage areas, Redis for camera frames
  • Deduplication β€” 64-bit perceptual hash, β‰₯95% similarity skips save
  • Multi-stage Docker β€” minimal runtime image (~150MB), dev image with hot reload

βš™οΈ Configuration

All settings via environment variables (GEOMIND_ prefix) or YAML:

File Purpose
.env Runtime overrides (DB URL, API keys, log level)
cameras.yaml Camera feeds, storage, database, Redis
vision.yaml Vision engine, model, temporal validation
auth.yaml JWT, API keys, rate limiting, RBAC
metrics.yaml Prometheus metrics config
pyproject.toml Dependencies, tool config (ruff, mypy, pytest)

Key env vars:

GEOMIND_DATABASE_URL=postgresql+asyncpg://user:pass@host/db
GEOMIND_CAM_REDIS__URL=redis://localhost:6379/0
GEOMIND_VISION_MODEL__TYPE=onnx
GEOMIND_VISION_MODEL__WEIGHTS_PATH=./models/wildfire_yolov8n.onnx
GEOMIND_AUTH_JWT_SECRET=your-secret
GEOMIND_LOG_LEVEL=INFO

πŸ§ͺ Testing

# All tests (154 passing)
make test

# Camera tests only
make test-cam

# Vision tests only
make test-vision

# With coverage
pytest --cov=src --cov-report=html

# Integration tests (requires PostGIS)
GEOMIND_TEST_DATABASE_URL=postgresql+asyncpg://... pytest tests/integration/

Test breakdown:

  • 36 unit/integration tests for Location Intelligence
  • 18 camera pipeline tests (config, storage, fetcher, DB, API, scheduler)
  • Vision engine tests (model, temporal validation, database, API)
  • Auth tests (JWT, API keys, RBAC, rate limiting)
  • WebSocket tests (manager, models, API)
  • Metrics tests (collector, middleware)

🐳 Docker

# docker-compose.yml services:
#   db      - postgis/postgis:16-3.4 (PostGIS 3.4)
#   redis   - redis:7-alpine (for camera caching)
#   api     - geomind:latest (FastAPI + Uvicorn, 4 workers)
#   api-dev - geomind:dev (hot reload on port 8001)
docker-compose up -d          # Start production
docker-compose up -d api-dev  # Start dev server
docker-compose logs -f api    # View logs
docker-compose down           # Stop

Multi-stage build targets:

  • runtime β€” minimal production image (~150MB)
  • dev β€” development image with pytest, ruff, mypy
  • builder β€” dependency compilation stage

πŸ“ Project Structure

GeoMind/
β”œβ”€β”€ src/geomind/
β”‚   β”œβ”€β”€ cameras/              # Camera pipeline module
β”‚   β”‚   β”œβ”€β”€ config.py         # Pydantic config models
β”‚   β”‚   β”œβ”€β”€ models.py         # SQLAlchemy + Pydantic models
β”‚   β”‚   β”œβ”€β”€ storage.py        # File storage + pHash dedup
β”‚   β”‚   β”œβ”€β”€ fetcher.py        # HTTP fetcher with retries
β”‚   β”‚   β”œβ”€β”€ database.py       # Async SQLAlchemy CRUD
β”‚   β”‚   β”œβ”€β”€ scheduler.py      # APScheduler orchestration
β”‚   β”‚   β”œβ”€β”€ api.py            # FastAPI routes
β”‚   β”‚   └── README.md         # Module docs
β”‚   β”œβ”€β”€ vision/               # Vision engine module
β”‚   β”‚   β”œβ”€β”€ config.py         # Model, temporal, queue config
β”‚   β”‚   β”œβ”€β”€ models.py         # Detection events, frames
β”‚   β”‚   β”œβ”€β”€ models_impl.py    # ONNX, YOLO, Wildfire, Dummy models
β”‚   β”‚   β”œβ”€β”€ interfaces.py     # Model protocols
β”‚   β”‚   β”œβ”€β”€ engine.py         # Async inference engine
β”‚   β”‚   β”œβ”€β”€ temporal.py       # Temporal validation logic
β”‚   β”‚   β”œβ”€β”€ database.py       # Event storage
β”‚   β”‚   β”œβ”€β”€ api.py            # FastAPI routes
β”‚   β”‚   └── README.md         # Module docs
β”‚   β”œβ”€β”€ auth/                 # Authentication module
β”‚   β”‚   β”œβ”€β”€ models.py         # User, API key, role models
β”‚   β”‚   β”œβ”€β”€ database.py       # User/key storage
β”‚   β”‚   β”œβ”€β”€ utils.py          # JWT, hashing, tokens
β”‚   β”‚   β”œβ”€β”€ dependencies.py   # FastAPI auth deps
β”‚   β”‚   β”œβ”€β”€ rate_limit.py     # Token bucket rate limiting
β”‚   β”‚   β”œβ”€β”€ api.py            # Auth routes
β”‚   β”‚   └── README.md         # Module docs
β”‚   β”œβ”€β”€ ws/                   # WebSocket module
β”‚   β”‚   β”œβ”€β”€ models.py         # WS message models
β”‚   β”‚   β”œβ”€β”€ manager.py        # Connection manager + pub/sub
β”‚   β”‚   β”œβ”€β”€ api.py            # WS endpoint + publishing
β”‚   β”‚   β”œβ”€β”€ config.py         # WS config
β”‚   β”‚   └── README.md         # Module docs
β”‚   β”œβ”€β”€ metrics/              # Prometheus metrics
β”‚   β”‚   β”œβ”€β”€ collector.py      # Custom metrics
β”‚   β”‚   β”œβ”€β”€ middleware.py     # Request metrics middleware
β”‚   β”‚   └── README.md         # Module docs
β”‚   β”œβ”€β”€ core/                 # Config, errors, logging
β”‚   β”œβ”€β”€ db/                   # Base, session, engine proxy
β”‚   β”œβ”€β”€ providers/            # Overpass, Elevation
β”‚   β”œβ”€β”€ repositories/         # PostGIS metric queries
β”‚   β”œβ”€β”€ services/             # Ingestion, metrics, orchestration
β”‚   β”œβ”€β”€ api/                  # Health, Location Intelligence routes
β”‚   └── main.py               # FastAPI app factory
β”œβ”€β”€ geomind_client/           # Python client library
β”‚   β”œβ”€β”€ client.py             # Sync + Async clients
β”‚   β”œβ”€β”€ models.py             # Pydantic response models
β”‚   β”œβ”€β”€ pyproject.toml        # Package config
β”‚   └── README.md             # Client docs
β”œβ”€β”€ scripts/                  # Utility scripts
β”‚   β”œβ”€β”€ download_model.py     # Model download + placeholder
β”‚   β”œβ”€β”€ train_wildfire.py     # Training pipeline scaffold
β”‚   β”œβ”€β”€ validate_model.py     # ONNX model validation
β”‚   β”œβ”€β”€ satellite_ingest.py   # Sentinel-2/Landsat ingestion
β”‚   └── generate_openapi.py   # OpenAPI spec generation
β”œβ”€β”€ examples/                 # Usage examples
β”‚   β”œβ”€β”€ ws_client.py          # Python WS client
β”‚   β”œβ”€β”€ ws_client.js          # Node.js/Browser WS client
β”‚   └── ws_client.html        # Browser demo
β”œβ”€β”€ monitoring/               # Observability configs
β”‚   β”œβ”€β”€ prometheus_alerts.yml        # 25+ alert rules
β”‚   β”œβ”€β”€ prometheus_recording_rules.yml # Recording rules
β”‚   └── grafana_dashboard.json       # 16-panel dashboard
β”œβ”€β”€ tests/                    # 154 tests (unit + integration)
β”œβ”€β”€ alembic/                  # DB migrations
β”œβ”€β”€ data/                     # Training data (gitignored)
β”œβ”€β”€ models/                   # Model weights (gitignored)
β”œβ”€β”€ frames/                   # Camera frames (gitignored)
β”œβ”€β”€ cameras.yaml              # Camera config (gitignored)
β”œβ”€β”€ vision.yaml               # Vision config (gitignored)
β”œβ”€β”€ auth.yaml                 # Auth config (gitignored)
β”œβ”€β”€ metrics.yaml              # Metrics config (gitignored)
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ Makefile
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ CHANGELOG.md
└── LICENSE (MIT)

πŸ› οΈ Scripts & Examples

Script Purpose
scripts/download_model.py Download/convert YOLO models, create ONNX placeholders
scripts/train_wildfire.py Training pipeline scaffold (prepare, train, export, validate)
scripts/validate_model.py Validate ONNX models + benchmark + Vision Engine integration test
scripts/satellite_ingest.py Sentinel-2/Landsat search, download, indices (NDVI, NBR, NDWI...)
scripts/generate_openapi.py Generate OpenAPI 3.1 spec (JSON/YAML) with filtering
examples/ws_client.py Python async WebSocket client with auth, filters, reconnection
examples/ws_client.js Universal JS/Node.js WebSocket client
examples/ws_client.html Browser demo (vanilla JS, no deps)

🀝 Contributing

# Format & lint
make format
make lint

# Run tests
make test

# Type check
make typecheck

# Submit PR

Code style: ruff (line-length 100), type hints required (mypy). CI: GitHub Actions (lint, unit tests, integration tests, Docker build, security scan).


πŸ“„ License

MIT License β€” see LICENSE.


πŸ™‹β€β™‚οΈ Author

Varun Gore β€” @VarunGore36


Built with FastAPI, PostGIS, ONNX Runtime, and open geospatial data.

About

AI-powered geospatial intelligence API that converts satellite imagery and geographic datasets into structured, actionable intelligence.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages