diff --git a/README.md b/README.md index a7e5dc0..d6934c1 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,9 @@ sh scripts/load_buildings.sh data/osm/northwestern-fed-district-latest.osm.pbf docker compose restart api worker ``` +The script builds a local `radio-osm2pgsql:latest` image from +`scripts/Dockerfile.osm2pgsql` on first run. + The import writes a `buildings` table with `geom`, `height_m`, `levels`, `building_type`, and `source`. Heights come from `height`, then `building:levels * 3.0`, then an estimated default by building type. diff --git a/scripts/Dockerfile.osm2pgsql b/scripts/Dockerfile.osm2pgsql new file mode 100644 index 0000000..4fdb9e7 --- /dev/null +++ b/scripts/Dockerfile.osm2pgsql @@ -0,0 +1,7 @@ +FROM debian:bookworm-slim + +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates osm2pgsql \ + && rm -rf /var/lib/apt/lists/* + +ENTRYPOINT ["osm2pgsql"] diff --git a/scripts/load_buildings.sh b/scripts/load_buildings.sh index 491647a..df538d4 100644 --- a/scripts/load_buildings.sh +++ b/scripts/load_buildings.sh @@ -23,7 +23,7 @@ DB_NAME=${POSTGRES_DB:-radio} DB_USER=${POSTGRES_USER:-radio} DB_PASSWORD=${DB_PASSWORD:-radio} POSTGIS_SERVICE=${POSTGIS_SERVICE:-postgis} -OSM2PGSQL_IMAGE=${OSM2PGSQL_IMAGE:-osm2pgsql/osm2pgsql:latest} +OSM2PGSQL_IMAGE=${OSM2PGSQL_IMAGE:-radio-osm2pgsql:latest} SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) REPO_DIR=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd) @@ -40,6 +40,14 @@ NETWORK=$(docker inspect "$POSTGIS_CONTAINER" \ --format '{{range $name, $_ := .NetworkSettings.Networks}}{{println $name}}{{end}}' \ | head -n 1) +if ! docker image inspect "$OSM2PGSQL_IMAGE" >/dev/null 2>&1; then + echo "Build local osm2pgsql image: $OSM2PGSQL_IMAGE" + docker build \ + -t "$OSM2PGSQL_IMAGE" \ + -f "$SCRIPT_DIR/Dockerfile.osm2pgsql" \ + "$SCRIPT_DIR" +fi + echo "Ensure PostGIS extension exists" docker compose exec -T "$POSTGIS_SERVICE" psql -U "$DB_USER" -d "$DB_NAME" \ < "$REPO_DIR/db/init/01_postgis.sql"