diff --git a/Earthfile b/Earthfile index 88b1851e8..a92cfc2dd 100644 --- a/Earthfile +++ b/Earthfile @@ -35,7 +35,7 @@ save: BUILD +save-mbtiles --area=${area} IF [ ! -z "${transit_feeds}" ] BUILD +save-gtfs --area=${area} --transit_feeds=${transit_feeds} - BUILD +save-otp --area=${area} --transit_feeds=${transit_feeds} --clip_to_gtfs=0 + BUILD +save-otp-graph --area=${area} --transit_feeds=${transit_feeds} --clip_to_gtfs=0 END BUILD +save-valhalla --area=${area} BUILD +save-pelias --area=${area} --countries=${countries} @@ -98,14 +98,15 @@ save-gtfs: save-otp-zones: FROM +save-base ARG --required area + # List of filenames. Each file corresponds to an OTP graph to output. Each row in each file references a GTFS feeds input to that OTP graph. ARG --required transit_zones ARG otp_build_config FOR transit_feeds IN $transit_zones - BUILD +save-otp --area=${area} --transit_feeds=${transit_feeds} --clip_to_gtfs=1 --otp_build_config=${otp_build_config} + BUILD +save-otp-graph --area=${area} --transit_feeds=${transit_feeds} --clip_to_gtfs=1 --otp_build_config=${otp_build_config} BUILD +save-otp-router-config --transit_feeds=${transit_feeds} END -save-otp: +save-otp-graph: FROM +save-base ARG --required area ARG --required transit_feeds @@ -128,7 +129,7 @@ save-otp: COPY +cache-buster/todays_date . ARG cache_key=$(cat todays_date) - COPY (+otp-build/graph.obj --area=${area} \ + COPY (+otp-build-graph/graph.obj --area=${area} \ --clip_to_gtfs=${clip_to_gtfs} \ --transit_feeds=${transit_feeds} \ --cache_key=${cache_key} \ @@ -517,7 +518,7 @@ otp-base: RUN mkdir /var/opentripplanner -otp-build: +otp-build-graph: FROM +otp-base ARG --required area @@ -542,20 +543,54 @@ otp-build: COPY "${otp_build_config}" /var/opentripplanner/build-config.json END + # Note: This bounds all directions to the extent of the transit feeds, so e.g. you can't get OTP + # bike routing anywhere outside the bounds of the transit feeds. This should usually be fine, but it'd + # be nice to handle the case where someone wants biking outside of their transit graph bbox. + COPY (+gtfs-compute-bbox/bbox.txt --transit_feeds=${transit_feeds} --cache_key=${cache_key}) bbox.txt + ARG gtfs_bbox=$(cat bbox.txt) + IF [ -n "$clip_to_gtfs" ] - COPY (+gtfs-compute-bbox/bbox.txt --transit_feeds=${transit_feeds} --cache_key=${cache_key}) bbox.txt - ARG clip_bbox=$(cat bbox.txt) - COPY (+extract/data.osm.pbf --area=${area} --clip_bbox=${clip_bbox}) /var/opentripplanner + COPY (+extract/data.osm.pbf --area=${area} --clip_bbox=${gtfs_bbox}) /var/opentripplanner ELSE COPY (+extract/data.osm.pbf --area=${area}) /var/opentripplanner END + COPY (+elevation/elevation-tifs --bbox=${gtfs_bbox}) /var/opentripplanner + COPY (+gtfs-build/gtfs --transit_feeds=${transit_feeds} --cache_key=${cache_key}) /var/opentripplanner RUN --entrypoint -- --build --save SAVE ARTIFACT /var/opentripplanner/graph.obj /graph.obj +download-elevation: + FROM +valhalla-base-image + + # e.g. '-122.462 47.394 -122.005 47.831' + # Note: this is the bbox format we use everywhere, but we need to convert it to the comma separated one that valhalla uses + ARG --required bbox + + ARG valhalla_bbox=$(echo ${bbox} | sed 's/ /,/g') + RUN valhalla_build_elevation --outdir elevation-hgts --from-bbox=${valhalla_bbox} + + SAVE ARTIFACT elevation-hgts + +elevation: + FROM debian:bookworm-slim + ARG --required bbox + + RUN apt-get update \ + && apt-get install -y --no-install-recommends gdal-bin \ + && rm -rf /var/lib/apt/lists/* + + COPY services/otp/dem-hgt-to-tif . + + COPY (+download-elevation/elevation-hgts --bbox=${bbox}) elevation-hgts/ + + RUN ./dem-hgt-to-tif elevation-hgts elevation-tifs + + SAVE ARTIFACT elevation-tifs + otp-init-image: FROM +downloader-base COPY ./services/otp/init.sh /app/init.sh diff --git a/services/otp/dem-hgt-to-tif b/services/otp/dem-hgt-to-tif new file mode 100755 index 000000000..b9f7b9eaa --- /dev/null +++ b/services/otp/dem-hgt-to-tif @@ -0,0 +1,22 @@ +#!/bin/bash -ex + +HGT_DIR=$1 +if [ -z "$HGT_DIR" ]; then + echo "Missing param for input directory of .hgt files" + exit 1 +fi + +TIF_DIR=$2 +if [ -z "$TIF_DIR" ]; then + echo "Missing param for output directory of .tif files" + exit 1 +fi + +mkdir "$TIF_DIR" + +find "$HGT_DIR" -type f | while read -r file; do + gunzip "$file" + BASENAME=$(basename "$file") + TIF_NAME="${BASENAME%.*.*}.tif" + gdal_translate "${file%.*}" "${TIF_DIR}/${TIF_NAME}" +done