50
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, ...
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]]...
26
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/...
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 ...
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 ...
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....
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 ...
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....
13
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']
...
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 ...
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 ...
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 ...
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 ...
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 ...
9
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
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 ...
8
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....
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 ...
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 ...
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,...
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 ...
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.
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 ...
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)....
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 ...
6
votes
Accepted
Round gdal_translate AAIGrid output to 4 decimal places
It can be done by adding -co DECIMAL_PRECISION=4 in gdal_translate command.
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 ...
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'
...
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
6
votes
Accepted
How to install MrSID support for GDAL on Ubuntu
I also tried to build gdal to support mrsid driver, but it failed. So the alternative solution for me was to use mrsiddecode from Extensis and the regular gdal binaries (2.4.x) for Ubuntu. The tool ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
gdal-translate × 575gdal × 397
gdalwarp × 155
geotiff-tiff × 106
python × 78
qgis × 60
raster × 48
coordinate-system × 34
gdalbuildvrt × 24
gdal2tiles × 21
netcdf × 18
georeferencing × 13
gdal-merge × 13
r × 12
geopackage × 12
vrt × 12
pyqgis × 11
mbtiles × 11
sentinel-2 × 10
raster-conversion × 10
wms × 9
dem × 9
clip × 9
kmz × 8
nodata × 8