Last active
July 2, 2024 14:55
-
-
Save bertspaan/418b53d886f02b95c5f0e98dfbb16299 to your computer and use it in GitHub Desktop.
Output of Allmaps CLI GDAL script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
mkdir -p . | |
if ! command -v gdalinfo &> /dev/null | |
then | |
echo "Error: gdalinfo could not be found. Please install GDAL." | |
exit 1 | |
fi | |
if ! command -v gdalbuildvrt &> /dev/null | |
then | |
echo "Error: gdalbuildvrt could not be found. Please install GDAL." | |
exit 1 | |
fi | |
if ! command -v gdal_translate &> /dev/null | |
then | |
echo "Error: gdal_translate could not be found. Please install GDAL." | |
exit 1 | |
fi | |
if ! command -v gdalwarp &> /dev/null | |
then | |
echo "Error: gdalwarp could not be found. Please install GDAL." | |
exit 1 | |
fi | |
if ! command -v jq &> /dev/null | |
then | |
echo "Error: jq could not be found. Please install jq: https://jqlang.github.io/jq/." | |
exit 1 | |
fi | |
required_width_096f57b5ff35b3eb=4141 | |
required_height_096f57b5ff35b3eb=5796 | |
width_096f57b5ff35b3eb=( $(gdalinfo -json 2eebcf00c43aec7a.jpg | jq '.size[0]') ) | |
height_096f57b5ff35b3eb=( $(gdalinfo -json 2eebcf00c43aec7a.jpg | jq '.size[1]') ) | |
if [ "$width_096f57b5ff35b3eb" -eq "$required_width_096f57b5ff35b3eb" ] && | |
[ "$height_096f57b5ff35b3eb" -eq "$required_height_096f57b5ff35b3eb" ]; then | |
echo "Found image with correct size: 2eebcf00c43aec7a.jpg" | |
else | |
echo "Error: found image with incorrect size" | |
echo " Image: 2eebcf00c43aec7a.jpg" | |
echo " Expected: $required_width_096f57b5ff35b3eb x $required_height_096f57b5ff35b3eb" | |
echo " Found: $width_096f57b5ff35b3eb x $height_096f57b5ff35b3eb" | |
exit 1 | |
fi | |
gdal_translate -of vrt \ | |
-a_srs EPSG:4326 \ | |
-gcp 1844 3763 -122.1480511 42.9118382 \ | |
-gcp 698 5241 -122.2666122 42.8010016 \ | |
-gcp 1849 3473 -122.1472846 42.9334667 \ | |
-gcp 956 1509 -122.2363611 43.0801867 \ | |
-gcp 1801 3475 -122.1522704 42.9332129 \ | |
-gcp 3643 4560 -121.9661637 42.84986 \ | |
-gcp 1853 3307 -122.1470519 42.9456506 \ | |
2eebcf00c43aec7a.jpg \ | |
./096f57b5ff35b3eb.vrt | |
echo '{"type":"Polygon","coordinates":[[[-122.33310420579332,43.11960993730178],[-122.33773213209975,42.76050938626561],[-121.91698181968323,42.75797919008322],[-121.91235817941033,43.11678011898471],[-122.33310420579332,43.11960993730178]]]}' > ./096f57b5ff35b3eb.geojson | |
gdalwarp \ | |
-of COG -co COMPRESS=JPEG -co QUALITY=75 \ | |
-dstalpha -overwrite \ | |
-cutline ./096f57b5ff35b3eb.geojson -crop_to_cutline \ | |
-t_srs "EPSG:3857" \ | |
-order 1 \ | |
./096f57b5ff35b3eb.vrt \ | |
./096f57b5ff35b3eb-warped.tif | |
gdalbuildvrt ./096f57b5ff35b3eb.vrt \ | |
./096f57b5ff35b3eb-warped.tif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment