Skip to content

Instantly share code, notes, and snippets.

@ted-piotrowski
Created May 9, 2024 03:34
Show Gist options
  • Save ted-piotrowski/51b02f6f822b45d9196573b6cc3bc07f to your computer and use it in GitHub Desktop.
Save ted-piotrowski/51b02f6f822b45d9196573b6cc3bc07f to your computer and use it in GitHub Desktop.
Overture buildings partition script
#!/bin/bash
#bbox.ymin <= 0
#S=/Volumes/T7/OvertureMaps/theme=buildings/type=building/part-*-530a22ea-6b33-45e9-961b-567f661900b0-c000.zstd.parquet
#D=/Volumes/T7/OvertureMaps/South.fgb
#bbox.ymin >= 0 AND bbox.xmin <= 0
#S=/Volumes/T7/OvertureMaps/theme=buildings/type=building/part-*-530a22ea-6b33-45e9-961b-567f661900b0-c000.zstd.parquet
#D=/Volumes/T7/OvertureMaps/NW.fgb
#bbox.ymin >= 0 AND bbox.xmin >= 90
#S=/Volumes/T7/OvertureMaps/theme=buildings/type=building/part-*-530a22ea-6b33-45e9-961b-567f661900b0-c000.zstd.parquet
#D=/Volumes/T7/OvertureMaps/NEE.fgb
#bbox.ymin >= 0 AND bbox.xmin >= 45 AND bbox.xmax <= 90
#S=/Volumes/T7/OvertureMaps/theme=buildings/type=building/part-*-530a22ea-6b33-45e9-961b-567f661900b0-c000.zstd.parquet
#D=/Volumes/T7/OvertureMaps/NWE.fgb
#bbox.ymin >= 0 AND bbox.xmin >= 0 AND bbox.xmax <= 45
S=/Volumes/T7/OvertureMaps/theme=buildings/type=building/part-*-530a22ea-6b33-45e9-961b-567f661900b0-c000.zstd.parquet
D=/Volumes/T7/OvertureMaps/NWW.fgb
date
SQL=$(cat << EOF
LOAD spatial;
COPY (
SELECT
CASE
WHEN height IS NOT NULL THEN height
WHEN num_floors IS NOT NULL THEN num_floors * 3.1
WHEN level IS NOT NULL THEN level * 3.1
ELSE 3.1
END as height,
CASE
WHEN min_height IS NOT NULL THEN min_height
WHEN min_floor IS NOT NULL THEN min_floor * 3.1
ELSE 0
END as min_height,
ST_GeomFromWKB(geometry) as geometry
FROM read_parquet('$S')
WHERE bbox.ymin >= 0 AND bbox.xmin >= 0 AND bbox.xmax <= 45)
TO '$D' WITH (FORMAT GDAL, DRIVER 'FlatGeoBuf', SRS 'EPSG:4326');
EOF)
echo "$SQL" | duckdb -noheader -json
date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment