Difference between revisions of "Raster Format Conversion Using gdal translate"

From Tuflow
Jump to navigation Jump to search
Line 1: Line 1:
 
This page lists useful batch file examples for using gdal_translate.exe. For complete documentation on this tool please visit '''<u>[https://gdal.org/programs/gdal_translate.html#gdal-translate gdal.org/programs/gdal_translate]</u>'''<Br>
 
This page lists useful batch file examples for using gdal_translate.exe. For complete documentation on this tool please visit '''<u>[https://gdal.org/programs/gdal_translate.html#gdal-translate gdal.org/programs/gdal_translate]</u>'''<Br>
  
==Basic Format Conversion===
+
==Basic Format Conversion==
 
Format conversion can be done using "<tt>-of <format_name></tt>" then specifying the "<tt><source_dataset> <destination_dataset></tt>".<br>
 
Format conversion can be done using "<tt>-of <format_name></tt>" then specifying the "<tt><source_dataset> <destination_dataset></tt>".<br>
 
<Br>
 
<Br>
Line 9: Line 9:
 
<pre>gdal_translate.exe -of GPKG DEM_M01_5m.asc DEM_M01_5m.gpkg</pre>
 
<pre>gdal_translate.exe -of GPKG DEM_M01_5m.asc DEM_M01_5m.gpkg</pre>
 
'''GeoTIFF to ASC'''<br>
 
'''GeoTIFF to ASC'''<br>
:* ''<tt>-co</tt>'': (Creation Option) - output format specific option
+
:* ''<tt>-co</tt>'': (Creation Option) - output format specific option. Flag must be used for eachcreation option used. - '''<u>[https://gdal.org/drivers/raster/aaigrid.html More Details]</u>'''
 
:** ''<tt>SIGNIFICANT_DIGITS=<n></tt>'': limits the precision of the output
 
:** ''<tt>SIGNIFICANT_DIGITS=<n></tt>'': limits the precision of the output
 
<pre>gdal_translate.exe -of AAIGrid -co SIGNIFICANT_DIGITS=8 DEM_M01_5m.tif DEM_M01_5m.asc</pre>
 
<pre>gdal_translate.exe -of AAIGrid -co SIGNIFICANT_DIGITS=8 DEM_M01_5m.tif DEM_M01_5m.asc</pre>
 +
 +
==Adding Compression to GeoTIFF==
 +
<Br>
 +
'''Using DEFLATE Compression on Output GeoTIFF'''
 +
:* ''<tt>-co</tt>'': (Creation Option) - output format specific option. Flag must be used for each creation option used -'''<u>[https://gdal.org/drivers/raster/gtiff.html More Details]</u>'''
 +
:** ''<tt>COMPRESS=<method></tt>: "NONE", "DEFLATE", "LZW", and "PACKBITS" are currently supported by TUFLOW
 +
<pre>gdal_translate.exe -of GTiff -co COMPRESS=DEFLATE DEM_M01_5m.asc DEM_M01_5m.tif</pre>
 +
'''Specifying the Compression Level for the DEFLATE Compression Method'''<br>
 +
:* ''<tt>-co</tt>'': (Creation Option) - output format specific option. Flag must be used for each creation option used -'''<u>[https://gdal.org/drivers/raster/gtiff.html More Details]</u>'''
 +
:** ''<tt>ZLEVEL=[1-9]</tt>
 +
<pre>gdal_translate.exe -of GTiff -co COMPRESS=DEFLATE -co ZLEVEL=9 DEM_M01_5m.asc DEM_M01_5m.tif</pre>
 +
'''Adding a Horizontal Predictor to the Compression'''<br>
 +
:* ''<tt>-co</tt>'': (Creation Option) - output format specific option. Flag must be used for each creation option used -'''<u>[https://gdal.org/drivers/raster/gtiff.html More Details]</u>'''
 +
:** ''<tt>PREDICTOR=[1/2/3]</tt>'': 1 (No Predictor) and 2 (Horizontal Predictor) currently supported by TUFLOW
 +
<pre>gdal_translate.exe -of GTiff -co COMPRESS=DEFLATE -co ZLEVEL=9 -co PREDICTOR=2 DEM_M01_5m.asc DEM_M01_5m.tif</pre>

Revision as of 23:00, 11 April 2022

This page lists useful batch file examples for using gdal_translate.exe. For complete documentation on this tool please visit gdal.org/programs/gdal_translate

Basic Format Conversion

Format conversion can be done using "-of <format_name>" then specifying the "<source_dataset> <destination_dataset>".

ASC to GeoTIFF

gdal_translate.exe -of GTiff DEM_M01_5m.asc DEM_M01_5m.tif

ASC to GPKG

gdal_translate.exe -of GPKG DEM_M01_5m.asc DEM_M01_5m.gpkg

GeoTIFF to ASC

  • -co: (Creation Option) - output format specific option. Flag must be used for eachcreation option used. - More Details
    • SIGNIFICANT_DIGITS=<n>: limits the precision of the output
gdal_translate.exe -of AAIGrid -co SIGNIFICANT_DIGITS=8 DEM_M01_5m.tif DEM_M01_5m.asc

Adding Compression to GeoTIFF


Using DEFLATE Compression on Output GeoTIFF

  • -co: (Creation Option) - output format specific option. Flag must be used for each creation option used -More Details
    • COMPRESS=<method>: "NONE", "DEFLATE", "LZW", and "PACKBITS" are currently supported by TUFLOW
gdal_translate.exe -of GTiff -co COMPRESS=DEFLATE DEM_M01_5m.asc DEM_M01_5m.tif

Specifying the Compression Level for the DEFLATE Compression Method

  • -co: (Creation Option) - output format specific option. Flag must be used for each creation option used -More Details
    • ZLEVEL=[1-9]
gdal_translate.exe -of GTiff -co COMPRESS=DEFLATE -co ZLEVEL=9 DEM_M01_5m.asc DEM_M01_5m.tif

Adding a Horizontal Predictor to the Compression

  • -co: (Creation Option) - output format specific option. Flag must be used for each creation option used -More Details
    • PREDICTOR=[1/2/3]: 1 (No Predictor) and 2 (Horizontal Predictor) currently supported by TUFLOW
gdal_translate.exe -of GTiff -co COMPRESS=DEFLATE -co ZLEVEL=9 -co PREDICTOR=2 DEM_M01_5m.asc DEM_M01_5m.tif