Raster Format Conversion Using gdal translate

From Tuflow
Revision as of 23:11, 11 April 2022 by Ellis Symons (talk | contribs)
Jump to navigation Jump to search

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 each creation 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

Assigning a Projection


ASC to GeoTIFF

  • <t>-a_srs <srs_def>: Override the projection of the output file (no transformations performed). Srs_def can be an EPSG or WKT CRS definition.
gdal_translate.exe -of GTiff -a_srs "EPSG:32760" DEM_M01_5m.asc DEM_M01_5m.tif

Converting to/from GPKG


Convert to a new GPKG Database Where Layer Name is Different Than Database Name

  • -co: (Creation Option) - output format specific option. Flag must be used for each creation option used - More Details
    • RASTER_TABLE=<name>: The name of the output layer within database
gdal_translate.exe -of GPKG -co RASTER_TABLE=DEM_M01_5m DEM_M01_5m.asc DEM_database.gpkg

Convert to an existing GPKG Database Where Layer Name is Different Than Database Name

  • -co: (Creation Option) - output format specific option. Flag must be used for each creation option used - More Details
    • APPEND_SUBDATASET=[YES/NO]: If "YES" the existing GPKG will not be priorly destroyed.
gdal_translate.exe -of GPKG -co RASTER_TABLE=DEM_M01_5m -co APPEND_SUBDATASET=YES DEM_M01_5m.asc DEM_database.gpkg

GPKG to GeoTIFF Where the Layer Name is Different Than the Database Name

  • -oo: (Opening Option) - input format specific option. Flag must be used for each opening option used - More Details
    • TABLE=<name>: Name of the layer within GPKG to be converted.
gdal_translate.exe -of GTiff -oo TABLE=DEM_M01_5m DEM_database.gpkg DEM_M01_5m.tif