49 votes

How to call gdal_translate from Python code?

Since GDAL 2.1 (more info here), GDAL and OGR utilities can be used as library functions. For instance: from osgeo import gdal ds = gdal.Open('input.tif') ds = gdal.Translate('output.tif', ds, ...
Antonio Falciano's user avatar
32 votes

Scale 16 bit to 8 bit within range using GDAL

If you don' want the values above 255 to be cut, you need to scale them down. For that purpose gdal_translate provides the option -scale: From the Manual: -scale [src_min src_max [dst_min dst_max]]...
pLumo's user avatar
  • 6,489
25 votes
Accepted

Does gdal_translate support multi thread?

gdal_translate can not use Multithreading for computing. But it can use multithreaded compression for some formats e.g. for GeoTiff using -co NUM_THREADS=ALL_CPUS NUM_THREADS=number_of_threads/...
pLumo's user avatar
  • 6,489
22 votes
Accepted

Reducing File Size without losing quality

For aerial images like this, I suggest using TIFFs with JPEG compression. That way, there are no separate world files needed, all the metadata is stored in the TIFF as tags. Note, this will only work ...
Steven Kay's user avatar
  • 20.4k
19 votes
Accepted

Convert huge XYZ CSV to GeoTIFF

You can do this using GDAL, it directly supports XYZ format. It doesn't matter if your coordinates are UTM, gdal_translate will output in the same coordinate system. So to convert to GeoTIFF is as ...
user2856's user avatar
  • 65.8k
17 votes
Accepted

Clipping tiff raster image using bounding box with GDAL in python

Since GDAL 2.1 (more info here) GDAL and OGR utilities can be used as library functions, so this task is incredibly simple now: from osgeo import gdal ds = gdal.Open('original.tif') ds = gdal....
Antonio Falciano's user avatar
16 votes
Accepted

Can GDAL report if a .tiff is tiled or not?

I haven't found any specific commandline utility that can report if a tiff is tiled or striped. At least not directly or in a grepable form like TILED=YES. There should be enough information in ...
Logan Byers's user avatar
  • 2,849
14 votes
Accepted

Convert batch file using GDAL_Translate.

From the command line you can write for %i in (*.tif) do gdal_translate -of "ENVI" %i %i.bil The command above will convert all tif to bil in the actual directory. The output name will be some_name....
Zoltan's user avatar
  • 7,325
12 votes

osgeo.gdal.Translate - How to set compression on GDAL GTiff driver

You have "creationOptions" for this: translate_options = gdal.TranslateOptions(format = 'GTiff', creationOptions = ['TFW=YES', 'COMPRESS=LZW'] ...
sys49152's user avatar
  • 1,691
11 votes
Accepted

Translating raster from floating point to int16 increases size

Your 5 Mb inputs are compressed and your outputs are not. Your 40 Mb inputs may be compressed, but didn't compress well (very noisy data leads to poor compression, a random raster can actually ...
user2856's user avatar
  • 65.8k
10 votes
Accepted

Averaging overlapping rasters with GDAL

The following approach worked pretty well. First I build virtual raster. gdalbuildvrt raster.vrt -srcnodata 0 -input_file_list paths.txt paths.txt is file with following content: a.tif b.tif Then ...
Владислав Мокроусов's user avatar
9 votes
Accepted

How do I change the pixel size in GDAL without changing the extent?

Here's a quick script I put together to correct the cell size of a folder of GeoTiff rasters: import os, sys from osgeo import gdal from osgeo import gdalconst WorkingFolder = sys.argv[1] # first ...
Michael Stimson's user avatar
9 votes
Accepted

gdal_translate: Can I suppress the creation of auxiliary files?

I do not believe that you can avoid creating additional files with AAIGrid output. AAIGRid format does not have native internal support for projections and other metadata that GDAL needs in order to ...
user30184's user avatar
  • 65.4k
9 votes

osgeo.gdal.Translate - How to set compression on GDAL GTiff driver

I found the answer in this post. The post says GDAL supports three lossless compression algorithms for the GeoTiff format – Packbits, LZW and Deflate. You can use the compression methods with GDALs ...
fenfen123's user avatar
8 votes
Accepted

Can Gdal.Translate() return an object instead of writing a file?

gdal.Translate does return an object, it returns a gdal.Dataset object. from osgeo import gdal in_ds = gdal.OpenEx('path/to/input.tif') print(in_ds) <osgeo.gdal.Dataset; proxy of <Swig ...
user2856's user avatar
  • 65.8k
8 votes

Convert all files in a Linux directory from NITF to PNG using gdal_translate

The bash way You can try this directly in your shell (Linux based system assumed from the format of the path you provided, so it probably is bash): cd /home/john/WAMI/WPAFB_TRAIN/ mkdir pngs/ for f ...
swiss_knight's user avatar
  • 10.3k
8 votes
Accepted

How to show pixel boundaries of a given raster in QGIS?

Go to View - Decorations - Grid "Update intervals / Offsets from" click "Active Raster Layer" Then click the Line symbol and adjust the symbol. I made the lines 0.06 wide
BERA's user avatar
  • 72.6k
7 votes

Convert MODIS HDF file in sinusoidal projection into GeoTIFF using Python GDAL

You can either leave the -s_srs empty or use +proj=sinu +R=6371007.181 +nadgrids=@null +wktext gdalwarp -of GTIFF -s_srs '+proj=sinu +R=6371007.181 +nadgrids=@null +wktext' -r cubic -t_srs '+proj=...
Loïc Dutrieux's user avatar
7 votes

How to call gdal_translate from Python code?

Here is a quick code for anyone wanting to save bands from a composite multi-band TIF to individual files using GDAL Translate in Python. import gdal in_path = 'C:/GIS/Sample.tif' #input composite ...
15Step's user avatar
  • 2,440
7 votes
Accepted

Matching two rasters with different projections and resolution

First of all, I'd move the two raster layers in the same working directory in order to skip the long paths in command line. We can transform the elevation layer to the same CRS of the satellite image,...
Antonio Falciano's user avatar
7 votes

gdal_translate -a_ullr flag

After testing, the -a_ullr flag assigns the outermost coordinates of your raster. That is, the corners of grid cells located in the corners of the grid. The command: gdal_translate -of GTiff -a_srs ...
G. Deemer's user avatar
  • 111
7 votes

How to get gdal_translate to create world file for GeoTIFF

"WORLDFILE=YES" is a jpeg creation option, not a tiff option. The creation option you want is TFW=YES gdal_translate -co "TFW=YES" infile outfile See the geotiff documentation.
user2856's user avatar
  • 65.8k
7 votes
Accepted

File size inflation using GDAL

Your existing data is compressed. You're getting an increase in file-size because the default is uncompressed and you aren't specifying a compression option (-co compress=LZW). However, it's a ...
user2856's user avatar
  • 65.8k
7 votes
Accepted

GDAL translate in python - where do I find how to convert the command line arguments to use in python scripts?

You have two options here: Call the gdal_translate command line utility using Python: import subprocess subprocess.call('gdal_translate -of GTiff -ot Int16 input.tif output.tif') Or use gdal....
Marcelo Villa's user avatar
7 votes

What can I do with gdalwarp that I can't do with gdal_translate, and vice-versa?

In some ways gdalwarp is a generalization and improvement on gdal_translate. gdalwarp can reproject rasters, this covers much of what gdal_translate can do (resize, crop, resample, convert format etc)....
mdsumner's user avatar
  • 8,196
6 votes
Accepted

Convert MODIS HDF file in sinusoidal projection into GeoTIFF using Python GDAL

You might get unexpected results because your dataset crosses the 180° meridian. As a consequence, the tile is squeezed around the globe when reprojected to WGS84. To avoid that, you have to cut the ...
AndreJ's user avatar
  • 76.7k
6 votes

Convert TIFF file with multiple bands into a single CSV file

AFAIK gdal_translate is able to convert only one band into XYZ format, so I suggest the following workflow: use gdal_translate to convert each band into a CSV file; use ogr2ogr to append each CSV ...
Antonio Falciano's user avatar
6 votes
Accepted

Converting geotiff to kml with color gradient, GDAL

Found a solution to my problem: gdaldem color-relief -nearest_color_entry -alpha -co format=png -of KMLSUPEROVERLAY raster.tif color.txt raster-kml.kmz gdaldem color-relief converts a grayscale tiff ...
user20408's user avatar
  • 1,535
6 votes

osgeo.gdal.Translate - How to set compression on GDAL GTiff driver

Thanks fenfen123. I ended up using the following approach via the GDAL python api: # Write new tiffs with RGB palette gdalinput = tile+'.tif' gdaloutput = oFolder+'\\'+Path(tile).name+'.tif' ...
cmalmqui's user avatar
  • 161
6 votes
Accepted

Converting GeoTIFF into KMZ image using GDAL_translate returns empty, all black image

The answer is in the comments, namely adding -scale. The full command is: gdal_translate -scale -of KMLSUPEROVERLAY input.tif output.kmz
Tom's user avatar
  • 201

Only top scored, non community-wiki answers of a minimum length are eligible