Skip to content

Commit 1857267

Browse files
authored
add DuckDB script for downloading monaco or a custom area from Overtu… (#571)
* add DuckDB script for downloading monaco or a custom area from Overture as Parquet file [#541] * add bash help text * query for latest Overture release from STAC catalog
1 parent 1d8c87c commit 1857267

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

tiles/download-overture.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
STAC_CATALOG="https://stac.overturemaps.org/catalog.json"
5+
DEFAULT_BBOX="7.408446,43.722901,7.4405,43.752481"
6+
DEFAULT_OUT="data/sources/monaco.parquet"
7+
8+
usage() {
9+
cat <<EOF
10+
Usage: $0 [RELEASE] [BBOX] [OUTPUT]
11+
12+
Downloads Overture Maps data for a bounding box as a Parquet file.
13+
14+
Arguments:
15+
RELEASE Overture release version (default: latest, from ${STAC_CATALOG})
16+
BBOX xmin,ymin,xmax,ymax in WGS84 (default: ${DEFAULT_BBOX})
17+
OUTPUT Output file path (default: ${DEFAULT_OUT})
18+
19+
Example:
20+
$0 2026-06-17.0 -122.52,37.70,-122.35,37.83 data/sources/sf.parquet
21+
EOF
22+
}
23+
24+
latest_release() {
25+
# A network failure yields empty output rather than aborting under `set -e`,
26+
# so the caller can report it.
27+
duckdb -noheader -list -c \
28+
"SELECT latest FROM read_json('${STAC_CATALOG}')" 2>/dev/null || true
29+
}
30+
31+
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
32+
usage
33+
exit 0
34+
fi
35+
36+
REL="${1:-$(latest_release)}"
37+
if [[ -z "$REL" ]]; then
38+
echo "Could not determine the latest release from ${STAC_CATALOG}; pass one explicitly." >&2
39+
exit 1
40+
fi
41+
BBOX="${2:-$DEFAULT_BBOX}"
42+
OUT="${3:-$DEFAULT_OUT}"
43+
44+
IFS=',' read -r XMIN YMIN XMAX YMAX <<< "$BBOX"
45+
46+
echo "Downloading release $REL: $BBOX to $OUT"
47+
48+
duckdb -c "
49+
COPY (
50+
SELECT *
51+
FROM read_parquet(
52+
's3://overturemaps-us-west-2/release/${REL}/**/*.parquet',
53+
hive_partitioning=1, filename=1, union_by_name=1
54+
)
55+
WHERE theme IN ('transportation','places','base','buildings','divisions')
56+
AND bbox.xmin <= ${XMAX}
57+
AND bbox.xmax >= ${XMIN}
58+
AND bbox.ymin <= ${YMAX}
59+
AND bbox.ymax >= ${YMIN}
60+
) TO '${OUT}' (FORMAT PARQUET);"
61+
62+
echo "Wrote ${OUT}"

0 commit comments

Comments
 (0)