Skip to content

yassine-work/El-Morched

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

38 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

El-Morched

A full-stack geospatial platform for real-time flood and urban heat risk analysis β€” powered by terrain modeling, weather history, computer vision, hydraulic simulation, and an AI assistant.

πŸŽ₯ Watch Demo


Screenshots

Default View OSM + Routing
Default View OSM Routing
Satellite + Routing Advanced Mode
Satellite Advanced Mode

Features

  • πŸ—ΊοΈ Dual map modes β€” OpenStreetMap and satellite imagery
  • πŸ“ Waypoint routing β€” draw a path, get a navigable route
  • 🌊 Flood risk analysis β€” per-cell scoring from terrain + rainfall + simulation + street imagery
  • 🌑️ Heat risk analysis β€” Urban Heat Island scoring from temperature + impervious surfaces + vegetation
  • πŸ“· Street-level vision β€” Mapillary images analyzed by SegFormer, Groq vision, or CLIP
  • πŸ€– GeoAI Assistant β€” Groq-powered chatbot with tool-calling for routing, analysis, and weather
  • πŸ“Š Advanced mode β€” elevation profile, risk stats panel, image viewer, trajectory playback
  • ⚑ Redis caching β€” weather (1h TTL) and DEM (24h TTL) to avoid redundant API calls

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Frontend  (Next.js 14)           β”‚
β”‚  MapView Β· RiskMap Β· WaypointRouter           β”‚
β”‚  GeoAssistant Β· ProfileChart Β· RiskStatsPanel β”‚
β”‚  Zustand store  (useAnalysisStore)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚ REST / SSE
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Backend  (FastAPI)               β”‚
β”‚                                               β”‚
β”‚  /analysis  /assistant  /weather              β”‚
β”‚  /routing   /mapillary  /profile              β”‚
β”‚                                               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚          AnalysisPipeline               β”‚ β”‚
β”‚  β”‚  Fetch β†’ Process β†’ Simulate β†’ Score     β”‚ β”‚
β”‚  β”‚  β†’ GeoJSON Export                       β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                               β”‚
β”‚  Providers:  Open-Meteo Β· SRTM Β· Mapillary    β”‚
β”‚  Cache:      Redis                            β”‚
β”‚  Simulation: HEC-RAS | NullEngine             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Analysis Pipeline

AnalysisPipeline.run() in fusion/pipeline.py β€” five ordered stages:

Stage 1 β€” Data Fetching (concurrent)

All sources fetched in parallel via asyncio.gather:

Source Provider Cache TTL
Historical weather Open-Meteo 1 hour
Digital Elevation Model SRTM 24 hours
Street-level images Mapillary none

Redis caches weather and DEM results. Mapillary failures are silently ignored β€” the pipeline continues with an empty image list.

Stage 2 β€” Processing

Analyzer Input Output
TerrainAnalyzer DEM grid elevation, slope (Β°), flow accumulation (D8)
WeatherAnalyzer Weather history flood trigger score, heat stress, rainfall totals
VisionAnalyzer Mapillary images impervious %, vegetation %, shadow %, standing water %

Stage 3 β€” Simulation

Engine Description
HEC-RAS Full hydraulic simulation β†’ flood_extent_array + flood_depth_array
NullEngine Statistical fallback β€” produces a weaker extent array; its 25% weight is redistributed to terrain/weather

Active engine set via SIMULATION_ENGINE=null|hecras in .env.

Stage 4 β€” Risk Scoring

FloodRiskEngine and HeatRiskEngine each produce a per-cell NumPy score grid [0, 1], a category grid (0=none … 4=extreme), and a components dict for UI explainability.

Stage 5 β€” GeoJSON Export

grid_to_geojson_polygons() converts score/category grids into GeoJSON Polygon features rendered directly on the map.


Risk Engines

Flood Risk Engine

Factor Weight Notes
Weather 35% Rainfall total + peak intensity
Terrain 30% Elevation + slope + flow accumulation
Simulation 25% 0% with NullEngine; redistributed to terrain/weather
Vision 10% Impervious surface + standing water

Terrain score (per cell):

terrain = 0.4 Γ— (1 βˆ’ norm_elevation)
        + 0.3 Γ— (1 βˆ’ clip(slope / 30Β°))
        + 0.3 Γ— norm(log(flow_accumulation + 1))

Derived display metrics: runoff coefficient (Rational Method), peak flow index, drainage index, high-risk cell %, max flow accumulation.

Heat Risk Engine

heat_score = temp_baseline            ← dominant (15Β°Cβ†’0, 40Β°Cβ†’1)
           + heat_stress Γ— 0.25
           + impervious Γ— 0.25        ← Urban Heat Island proxy
           βˆ’ vegetation Γ— 0.15        ← cooling
           βˆ’ shadow Γ— 0.10            ← cooling
           βˆ’ elevation_norm Γ— 0.05    ← lapse rate

Derived display metrics: UHI intensity (Β°C), simplified Steadman heat index, cooling deficit, drought days.


Vision Analysis

VisionAnalyzer processes each Mapillary image through a fallback chain:

SegFormer (HuggingFace) β†’ Groq Vision β†’ CLIP (local) β†’ Mock
Model How it works
SegFormer nvidia/segformer-b0-finetuned-cityscapes-640-640 Pixel-level Cityscapes segmentation via HF Inference API. Decodes base64 PNG masks β†’ computes per-label pixel fractions (vegetation, impervious, water, sky)
Groq Vision llama-3.2-11b-vision-preview Prompts the model to return a JSON object with vegetation_score, impervious_score, shadow_score, standing_water, surface_type
CLIP openai/clip-vit-base-patch32 Zero-shot classification against 5 text labels, run locally via HuggingFace transformers
Mock Seeded random values β€” used in tests or when all APIs are unavailable

Set with CV_MODEL=segformer|groq|clip|mock.


GeoAI Assistant

The assistant (/api/v1/assistant/chat) is a Groq tool-calling agent backed by llama-3.3-70b-versatile.

Flow:

  1. Frontend sends messages[] + tools[] to the backend
  2. Backend proxies to Groq (/openai/v1/chat/completions) with tool_choice: auto
  3. Groq returns a tool_use response β€” frontend executes the tool locally
  4. Frontend sends the tool result back as a tool role message
  5. Loop repeats until Groq returns a plain text answer

Endpoints:

Endpoint Mode
POST /assistant/chat Standard JSON response
POST /assistant/chat/stream SSE streaming (token-by-token)

Tool examples registered by the frontend:

  • run_analysis β€” triggers the full risk pipeline for a bbox
  • get_weather β€” fetches weather for coordinates
  • route_waypoints β€” plans a path between waypoints
  • fly_to β€” pans the map camera (updates flyToTarget in Zustand)

Frontend State (Zustand)

All shared UI state lives in useAnalysisStore:

Slice Description
mode simple (map only) or advanced (full analysis UI)
aoi / drawnPath Current area of interest or freehand path
floodLayers / heatLayers GeoJSON risk features from last analysis
activeLayer Which risk overlay is visible (flood or heat)
trajectory / profile Elevation profile points for playback
images Mapillary image points for the image viewer
assistantWaypoints / assistantRoute Route generated by the AI assistant
flyToTarget Map camera target set by the assistant
lastAnalysisDurationSeconds Performance display in the stats panel

Redis Caching

Key pattern TTL Data
weather:{lat}:{lon}:{days} 1 hour WeatherSummary JSON
dem:{west}:{south}:{east}:{north} 24 hours DEMData JSON

Coordinates are snapped to 0.01Β° precision to avoid near-duplicate cache misses. If Redis is unavailable, the pipeline falls back to live fetches transparently.


Getting Started

Run with Docker

git clone https://github.com/your-org/GeoAI-RiskMapper.git
cd GeoAI-RiskMapper
cp .env.example .env   # fill in your keys
docker compose -f infra/docker-compose.yml up --build

Environment Variables

APP_NAME=GeoAI Risk Engine
DATABASE_URL=postgresql+asyncpg://geoai:geoai@localhost:5432/geoai
REDIS_URL=redis://localhost:6379

MAPILLARY_ACCESS_TOKEN=your_token
GROQ_API_KEY=your_key
GROQ_MODEL=llama-3.3-70b-versatile
HF_API_KEY=your_key
ORS_API_KEY=your_key
GEONAMES_USERNAME=your_username
OPENTOPOGRAPHY_API_KEY=your_key

WEATHER_PROVIDER=open_meteo
DEM_PROVIDER=srtm
ELEVATION_OPENTOPODATA_DATASET=srtm90m
ELEVATION_OPENTOPOGRAPHY_DEMTYPE=SRTMGL1

SIMULATION_ENGINE=null        # null | hecras
HECRAS_MCP_URL=http://localhost:8001
CV_MODEL=segformer             # segformer | groq | clip | mock

Run Locally

# Backend
cd backend && pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000

# Frontend
cd frontend && npm install && npm run dev

Project Structure

.
β”œβ”€β”€ backend/app/
β”‚   β”œβ”€β”€ api/routes/        # FastAPI endpoints
β”‚   β”œβ”€β”€ core/              # Config, DB, Redis
β”‚   β”œβ”€β”€ data_providers/    # SRTM, Open-Meteo, Mapillary
β”‚   β”œβ”€β”€ elevation/         # Multi-provider elevation catalog
β”‚   β”œβ”€β”€ fusion/            # AnalysisPipeline + GeoJSON export
β”‚   β”œβ”€β”€ processing/        # Terrain, Weather, Vision analyzers
β”‚   β”œβ”€β”€ risk_engine/       # FloodRiskEngine, HeatRiskEngine
β”‚   └── simulation/        # HEC-RAS + NullEngine
β”œβ”€β”€ frontend/src/
β”‚   β”œβ”€β”€ components/        # Map, analysis panels, assistant UI
β”‚   β”œβ”€β”€ store/             # Zustand (useAnalysisStore)
β”‚   └── lib/               # API client
β”œβ”€β”€ docs/                  # Platform screenshots
β”œβ”€β”€ infra/                 # docker-compose.yml, schema.sql
└── README.md

License

MIT

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 49.7%
  • Python 44.3%
  • JavaScript 3.9%
  • CSS 1.9%
  • Dockerfile 0.2%