103 lines
3.7 KiB
Bash
Executable File
103 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# ==============================================================================
|
|
# Script: restore_osm_roads.sh
|
|
# Purpose: Restore all OSM roads for Jordan & Syria cleanly using osm2pgsql,
|
|
# then apply the exact border line without deleting any roads!
|
|
# ==============================================================================
|
|
|
|
echo "================================================================="
|
|
echo "🔄 Restoring OSM Road Network & Setting Official Jordan Border..."
|
|
echo "================================================================="
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
if [ -f .env ]; then
|
|
export $(grep -v '^#' .env | xargs)
|
|
fi
|
|
|
|
DB_USER=${POSTGRES_USER:-mapuser}
|
|
DB_NAME=${POSTGRES_DB:-mapdb}
|
|
DATA_DIR="./infrastructure/osm-data"
|
|
|
|
mkdir -p "$DATA_DIR"
|
|
|
|
# Download Jordan PBF if not present or corrupt
|
|
if [ ! -s "${DATA_DIR}/jordan-latest.osm.pbf" ]; then
|
|
echo "📥 Downloading Jordan OSM data..."
|
|
wget -q --show-progress -O "${DATA_DIR}/jordan-latest.osm.pbf" "https://download.geofabrik.de/asia/jordan-latest.osm.pbf"
|
|
fi
|
|
|
|
if [ ! -s "${DATA_DIR}/syria-latest.osm.pbf" ]; then
|
|
echo "📥 Downloading Syria OSM data..."
|
|
wget -q --show-progress -O "${DATA_DIR}/syria-latest.osm.pbf" "https://download.geofabrik.de/asia/syria-latest.osm.pbf"
|
|
fi
|
|
|
|
if [ ! -s "${DATA_DIR}/egypt-latest.osm.pbf" ]; then
|
|
echo "📥 Downloading Egypt OSM data..."
|
|
wget -q --show-progress -O "${DATA_DIR}/egypt-latest.osm.pbf" "https://download.geofabrik.de/africa/egypt-latest.osm.pbf" || true
|
|
fi
|
|
|
|
if [ ! -s "${DATA_DIR}/iraq-latest.osm.pbf" ]; then
|
|
echo "📥 Downloading Iraq OSM data..."
|
|
wget -q --show-progress -O "${DATA_DIR}/iraq-latest.osm.pbf" "https://download.geofabrik.de/asia/iraq-latest.osm.pbf" || true
|
|
fi
|
|
|
|
echo "🚀 Importing Jordan OSM roads into PostGIS..."
|
|
docker compose --profile import run --rm osm-import \
|
|
osm2pgsql --create --slim --cache 1000 \
|
|
--database "$DB_NAME" --host db --user "$DB_USER" \
|
|
/data/jordan-latest.osm.pbf
|
|
|
|
echo "🚀 Importing Syria OSM roads into PostGIS (--append)..."
|
|
docker compose --profile import run --rm osm-import \
|
|
osm2pgsql --append --slim --cache 1000 \
|
|
--database "$DB_NAME" --host db --user "$DB_USER" \
|
|
/data/syria-latest.osm.pbf
|
|
|
|
if [ -s "${DATA_DIR}/egypt-latest.osm.pbf" ]; then
|
|
echo "🚀 Importing Egypt OSM data (--append)..."
|
|
docker compose --profile import run --rm osm-import \
|
|
osm2pgsql --append --slim --cache 1000 \
|
|
--database "$DB_NAME" --host db --user "$DB_USER" \
|
|
/data/egypt-latest.osm.pbf || true
|
|
fi
|
|
|
|
if [ -s "${DATA_DIR}/iraq-latest.osm.pbf" ]; then
|
|
echo "🚀 Importing Iraq OSM data (--append)..."
|
|
docker compose --profile import run --rm osm-import \
|
|
osm2pgsql --append --slim --cache 1000 \
|
|
--database "$DB_NAME" --host db --user "$DB_USER" \
|
|
/data/iraq-latest.osm.pbf || true
|
|
fi
|
|
|
|
echo "📍 Applying exact straight Jordan-Syria border segment from user coordinates..."
|
|
docker exec -i map-db psql -U "$DB_USER" -d "$DB_NAME" << 'EOF'
|
|
-- Insert the official straight border line:
|
|
-- Point A: (36.839237, 32.311852) -> Point B: (38.793024, 33.371104)
|
|
DELETE FROM planet_osm_line WHERE name = 'Jordan - Syria Official Border';
|
|
|
|
INSERT INTO planet_osm_line (osm_id, boundary, admin_level, name, way)
|
|
VALUES (
|
|
-9999991,
|
|
'administrative',
|
|
'2',
|
|
'Jordan - Syria Official Border',
|
|
ST_Transform(
|
|
ST_Segmentize(
|
|
ST_GeomFromText('LINESTRING(36.839237 32.311852, 38.793024 33.371104)', 4326),
|
|
1000
|
|
),
|
|
3857
|
|
)
|
|
);
|
|
EOF
|
|
|
|
echo "🔄 Restarting Martin to refresh vector tiles..."
|
|
docker compose restart martin
|
|
|
|
echo "================================================================="
|
|
echo "✅ All OSM Roads restored and official border applied perfectly!"
|
|
echo "================================================================="
|