1
0

OSM vector tile server setup with postgis and tegola

- 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
This commit is contained in:
2025-07-14 17:37:39 +02:00
commit a5d9e32d9b
7 changed files with 370 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
-- Initialize OSM database with PostGIS and hstore extensions
-- This script runs automatically when PostgreSQL container starts for the first time
-- Connect to the osm database
\c osm;
-- Enable PostGIS extension
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
-- Enable hstore extension for key-value storage
CREATE EXTENSION IF NOT EXISTS hstore;
-- Grant necessary permissions
GRANT ALL PRIVILEGES ON DATABASE osm TO postgres;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO postgres;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO postgres;
-- Set up proper ownership
ALTER DATABASE osm OWNER TO postgres;
-- Display confirmation
SELECT 'OSM database initialized successfully with PostGIS and hstore extensions' AS status;

View File

@@ -0,0 +1,28 @@
#!/bin/bash
# Install osm2pgsql and required tools
# This script runs during PostgreSQL container initialization
set -e
echo "Installing osm2pgsql and dependencies..."
# Update package list
apt-get update
# Install required packages
apt-get install -y \
osm2pgsql \
wget \
curl \
unzip \
ca-certificates \
--no-install-recommends
# Clean up to reduce image size
apt-get clean
rm -rf /var/lib/apt/lists/*
echo "osm2pgsql installation completed successfully"
# Verify installation
osm2pgsql --version

View File

@@ -0,0 +1,83 @@
#!/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!"