Raster Format Conversion Using gdal translate: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(20 intermediate revisions by 2 users not shown)
Line 13:
<pre>gdal_translate.exe -of AAIGrid -co SIGNIFICANT_DIGITS=8 DEM_M01_5m.tif DEM_M01_5m.asc</pre>
 
==Adding Compression toTo GeoTIFF==
<Br>
'''Using DEFLATE Compression on Output GeoTIFF'''
Line 31:
<br>
'''ASC to GeoTIFF'''<Br>
:* ''<ttt>-a_srs <srs_def></tt>'': Override the projection of the output file (no transformations performed). Srs_def can be an EPSG or WKT CRS definition.
<pre>gdal_translate.exe -of GTiff -a_srs "EPSG:32760" DEM_M01_5m.asc DEM_M01_5m.tif</pre>
 
==Cloud Optimised GeoTIFFs==
==Converting to/from GPKG==
<br>
Cloud Optimised GeoTIFFs (COGs) are a format of GeoTIFF which are set up to allow easy storage and distribution via the Cloud. The GeoTIFFs are formatted slightly differently with internal tiling, overviews and compression which makes it easier to access and download parts of the data corresponding to the particular study area of interest, without the requirement to download the entire file first. COGs aren't currently supported by the 2023 version of TUFLOW. Currently they would need to be converted using gdal translate.<Br>
 
'''COG to GeoTIFF'''<Br>
<pre>gdal_translate.exe -of GTiff DEM_M01_5m_COG.tif DEM_M01_5m.tif</pre>
 
You can also do the conversion with the compression options described '''<u>[[Raster_Format_Conversion_Using_gdal_translate#Adding_Compression_To_GeoTIFF | above]]</u>'''.
 
==Converting toTo/fromFrom GPKG==
<br>
'''Convert to a new GPKG Database Where Layer Name is Different Than Database Name'''<Br>
Line 57 ⟶ 66:
<pre>gdal_translate.exe -of EHdr DEM_M01_5m.tif DEM_M01_5m.flt</pre>
<li> The output ".flt" is identical to the "FLT" supported by TUFLOW so no updates to this file are required. The ".hdr" however is slightly different and requires manual updating.<br>
<br>
The output ".hdr" will look something like below:<br>
<pre>
Line 73 ⟶ 83:
YDIM 0.5
NODATA -9999
</pre>
The format supported by TUFLOW needs to look something like:<br>
<pre>
ncols <n>
nrows <n>
xllcorner <decimal no.>
yllcorner <decimal no.>
cellsize <decimal no.>
NODATA_value <decimal no.>
byteorder LSBFIRST
</pre>
The conversion is mostly a matter of renaming the header text (it should not be case sensitive in TUFLOW). There is one exception to this, the "tie-point" is different in the "EHdr" format. The "EHdr" format references the middle of the top-left cell, whereas the "FLT" format supported in TUFLOW expects the lower-left corner (similar to the ASC format).<Br>
<br>
[[File: ehdr_flt_tie_point_comparison.PNG|800px]]<Br>
<br>
Therefore the following conversions are required:
<pre>xllcorner = ULXMAP - (XDIM / 2)</pre>
<pre>yllcorner = ULYMAP - (NROW * YDIM) + (YDIM / 2)</pre>
If using the ".hdr" created by gdal_translate.exe from above, the resulting converted "TUFLOW Supported .hdr" will look like:<Br>
<Br>
: <b>''Note:''</b> Spaces are required between the text and value (do not use tabs)
: <b>''Note 2:''</b> "byteorder LSBFIRST" is only applicable if "BYTEORDER=I" in the exported ".hdr"
: <b>''Note 3:''</b> TUFLOW currenlty only supports square grid cells (XDIM = YDIM)
: <b>''Note 4:''</b> "FLT" only suppots single band rasters, "EHdr" supports multiple bands and so does "GeoTIFF", therefore be careful if converting to an "EHdr" from a "GeoTIFF" that contains multiple bands.
<pre>
ncols 1895
nrows 2137
xllcorner 292786.25
yllcorner 6177386.25
cellsize 0.5
NODATA_value -9999
byteorder LSBFIRST
</pre>
</ol>
<br>
<Br>
{{Tips Navigation
|uplink=[[GDAL_Tips_and_Tricks#GDAL_Programs| Back to GDAL Tips and Tricks]]
}}