Skip to content

Commit

Permalink
Merge branch 'mkirk/otp-dem-2'
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkirk committed Aug 19, 2024
2 parents 1cc942f + 29c30c8 commit 7f6df64
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
51 changes: 43 additions & 8 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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} \
Expand Down Expand Up @@ -517,7 +518,7 @@ otp-base:

RUN mkdir /var/opentripplanner

otp-build:
otp-build-graph:
FROM +otp-base

ARG --required area
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions services/otp/dem-hgt-to-tif
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7f6df64

Please sign in to comment.