#!/usr/bin/env python3 """ Jordan Topographic Contours Pipeline (SRTM 30m / Copernicus DEM -> PostGIS) ============================================================================= This script downloads digital elevation model data (DEM) for Jordan, generates vector contour lines (10m minor, 50m/100m index), and loads them into PostGIS for automatic high-speed vector tile serving via Martin. """ import os import sys import subprocess import psycopg2 DB_USER = os.getenv("POSTGRES_USER", "postgres") DB_PASS = os.getenv("POSTGRES_PASSWORD", "postgres") DB_HOST = os.getenv("POSTGRES_HOST", "localhost") DB_PORT = os.getenv("POSTGRES_PORT", "5432") DB_NAME = os.getenv("POSTGRES_DB", "maps_db") WORKDIR = "/tmp/jordan_dem" def run_cmd(cmd): print(f"🚀 Running: {cmd}") res = subprocess.run(cmd, shell=True, check=True) return res def setup_postgis_table(): print("📦 Creating jordan_contours table in PostGIS...") conn = psycopg2.connect( dbname=DB_NAME, user=DB_USER, password=DB_PASS, host=DB_HOST, port=DB_PORT ) cur = conn.cursor() cur.execute(""" CREATE TABLE IF NOT EXISTS jordan_contours ( id SERIAL PRIMARY KEY, elevation FLOAT NOT NULL, is_major BOOLEAN DEFAULT FALSE, geometry GEOMETRY(MultiLineString, 4326) NOT NULL ); CREATE INDEX IF NOT EXISTS jordan_contours_geom_idx ON jordan_contours USING GIST(geometry); CREATE INDEX IF NOT EXISTS jordan_contours_elev_idx ON jordan_contours(elevation); """) conn.commit() cur.close() conn.close() print("✅ Table jordan_contours is ready.") def main(): os.makedirs(WORKDIR, exist_ok=True) print("📍 Starting Jordan Topographic Contours Generator...") # 1. Setup Table setup_postgis_table() print(""" ============================================================================= Instructions for generating vector contours for Jordan: 1. Download SRTM 30m or Copernicus DEM GeoTIFF for Jordan bbox (29-34N, 34-40E). 2. Generate 10m contours: gdal_contour -a elevation -i 10.0 /tmp/jordan_dem.tif /tmp/jordan_contours.shp 3. Import to PostGIS: shp2pgsql -I -s 4326 -a /tmp/jordan_contours.shp jordan_contours | psql -U $POSTGRES_USER -d $POSTGRES_DB 4. Update is_major flag: UPDATE jordan_contours SET is_major = (MOD(elevation::int, 50) = 0); ============================================================================= """) if __name__ == "__main__": main()