Skip to content

Instantly share code, notes, and snippets.

@jsta
Created November 19, 2021 02:21
Show Gist options
  • Save jsta/986a71229fb1c2fd5d3c44e31bab4d90 to your computer and use it in GitHub Desktop.
Save jsta/986a71229fb1c2fd5d3c44e31bab4d90 to your computer and use it in GitHub Desktop.
Create a GTiff from an ascii grid with no raster metadata
#!/bin/bash
# Create a GTiff from an ascii grid with no raster metadata
#
# Examples
# # 4320: ncols
# # 2124: nrows
# # -180: xllcorner
# # -88.5: yllcorner
# # 0.0833333: cellsize
# touch test.txt
# txt2tif 4320 2124 -180 -88.5 0.0833333 test.txt test.tif
echo ncols $1 | cat - $6 > temp && mv temp $6
echo nrows $2 | cat - $6 > temp && mv temp $6
echo xllcorner $3 | cat - $6 > temp && mv temp $6
echo yllcorner $4 | cat - $6 > temp && mv temp $6
echo cellsize $5 | cat - $6 > temp && mv temp $6
# cat $6
gdal_translate -of GTiff $6 $7
@jsta
Copy link
Author

jsta commented Dec 10, 2021

:: txt2tif.bat - Windows Version
echo ncols %1 | cat - %6 > temp && mv temp %6
echo nrows %2 | cat - %6 > temp && mv temp %6
echo xllcorner %3 | cat - %6 > temp && mv temp %6
echo yllcorner %4 | cat - %6 > temp && mv temp %6
echo cellsize %5 | cat - %6 > temp && mv temp %6
:: cat %6
gdal_translate -of GTiff %6 %7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment