- Set up docker-compose with PostgreSQL/PostGIS and Tegola services - Added initialization scripts for database setup and OSM data import - Configured Tegola with vector tile layers for roads and buildings - Included README with setup instructions and troubleshooting guide
83 lines
2.3 KiB
Bash
83 lines
2.3 KiB
Bash
#!/bin/bash
|
|
# Download and import OSM data for Bosnia and Herzegovina
|
|
# This script runs during PostgreSQL container initialization
|
|
|
|
set -e
|
|
|
|
echo "Starting OSM data download and import process..."
|
|
|
|
# Configuration
|
|
OSM_URL="https://download.geofabrik.de/europe/bosnia-herzegovina-latest.osm.pbf"
|
|
OSM_FILE="/osm-data/bosnia-herzegovina-latest.osm.pbf"
|
|
DB_NAME="osm"
|
|
DB_USER="postgres"
|
|
DB_HOST="127.0.0.1"
|
|
DB_PORT="5432"
|
|
|
|
# Wait for PostgreSQL to be ready
|
|
echo "Waiting for PostgreSQL to be ready..."
|
|
until pg_isready -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME; do
|
|
echo "PostgreSQL is not ready yet, waiting..."
|
|
sleep 5
|
|
done
|
|
|
|
echo "PostgreSQL is ready, proceeding with OSM data processing..."
|
|
|
|
# Download OSM data if not already present
|
|
if [ ! -f "$OSM_FILE" ]; then
|
|
echo "Downloading OSM data from $OSM_URL..."
|
|
wget -O "$OSM_FILE" "$OSM_URL"
|
|
echo "Download completed successfully"
|
|
else
|
|
echo "OSM file already exists, skipping download"
|
|
fi
|
|
|
|
# Verify file was downloaded successfully
|
|
if [ ! -f "$OSM_FILE" ]; then
|
|
echo "Error: OSM file not found after download attempt"
|
|
exit 1
|
|
fi
|
|
|
|
echo "OSM file size: $(du -h $OSM_FILE | cut -f1)"
|
|
|
|
# Import data using osm2pgsql
|
|
echo "Starting OSM data import with osm2pgsql..."
|
|
|
|
# osm2pgsql command with optimized settings for vector tiles
|
|
osm2pgsql \
|
|
--create \
|
|
--database $DB_NAME \
|
|
--username $DB_USER \
|
|
--host $DB_HOST \
|
|
--port $DB_PORT \
|
|
--hstore \
|
|
--style /usr/share/osm2pgsql/default.style \
|
|
--multi-geometry \
|
|
--number-processes 2 \
|
|
--cache 512 \
|
|
--flat-nodes /osm-data/nodes.cache \
|
|
"$OSM_FILE"
|
|
|
|
echo "OSM data import completed successfully"
|
|
|
|
# Verify import by checking table counts
|
|
echo "Verifying import - checking table row counts:"
|
|
psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -c "
|
|
SELECT
|
|
'planet_osm_point' as table_name, count(*) as row_count
|
|
FROM planet_osm_point
|
|
UNION ALL
|
|
SELECT
|
|
'planet_osm_line' as table_name, count(*) as row_count
|
|
FROM planet_osm_line
|
|
UNION ALL
|
|
SELECT
|
|
'planet_osm_polygon' as table_name, count(*) as row_count
|
|
FROM planet_osm_polygon
|
|
UNION ALL
|
|
SELECT
|
|
'planet_osm_roads' as table_name, count(*) as row_count
|
|
FROM planet_osm_roads;
|
|
"
|
|
|
|
echo "OSM data download and import process completed successfully!" |