Questions tagged [gdal-calc]

Command line raster calculator with numpy syntax. Use any basic arithmetic supported by numpy arrays such as +-*\ along with logical operators such as >. Note that all files must have the same dimensions, but no projection checking is performed. Often referred to as gdal_calc.py or just gdal_calc.

Filter by
Sorted by
Tagged with
37
votes
3answers
5k views

Creating transparent hillshade?

I get elegant transparent hillshades via a combination gdal and convert. Compare to grey-based hillshade commonly used, such transparent hillshades are very cool because they can be placed between the ...
15
votes
3answers
13k views

gdal_calc raster calculator syntax for logical operators and other functions

In documentation for gdal_calc it is stated Command line raster calculator with numpy syntax. Later on there are few examples where in one of them: gdal_calc.py -A input.tif --outfile=result.tif --...
11
votes
3answers
1k views

How to create composite hillshade?

The concept of composite hillshade is to combine multiple hillshades with different sunlight orientation to avoid blind spot. It requires to merge 3 hillshades images with 315⁰ (NW sunlight, default ...
9
votes
3answers
3k views

How to indicate nodata into gdal_calc formula

I have a recurrent problem with gdal_calc. Say I have two rasters I need to sum together, in which the same nodatavalue is set (e.g. --NoDataValue = 0). In order to account for the fact that nodata +...
7
votes
2answers
4k views

How to replace pixel values in a single band DEM?

I have a single band DEM as a GeoTiff. I would like to replace values above or below a certain threshold with 0. Can I do that with GDAL?
6
votes
1answer
3k views

How does gdal_calc numpy operators work?

Gdal_calc manual Gdal_calc is introduced as : gdal_calc.py - Command line raster calculator with numpy syntax gdal_calc.py [-A <filename>] [--A_band] [-B...-Z filename] [other_options] OPTIONS:...
5
votes
1answer
4k views

Conditional statement in gdal_calc with result as float, not boolean

Many examples on gis.se that refer to gdal_calc give a boolean example. example 1 example 2 If I need to calculate a conditional statement on a float: If Raster_Value >= 1024, then 1024; else ...
5
votes
0answers
1k views

Difference between gdal_calc and QGIS raster calculator

I am hoping someone can help me with an issue I am having with gdal_calc. I am looking to create NDVI rasters from 4 band 8 bit ortho tiles. I have processed the tiles using the following calculation: ...
5
votes
0answers
276 views

How do I get the maximum value of raster cells ignoring nodata with gdal_calc?

I have two integer rasters, A and B, with the same dimensions and cell sizes. I want to compare each cell in A with each cell in B and keep the maximum value. In cases where both have nodata, I want ...
4
votes
2answers
707 views

Reclassify raster in QGIS with GDAL raster calc

I'm trying to reclassify some categorical raster data in QGIS using GDAL raster calculator. My input Geotiff has four values, [26, 27, 31, 32] which I want reclassified to [1.25, 2.5, 3.75, 5] ...
4
votes
2answers
678 views

Raster Caculator Qgis 2.6 v/s Gdal_calc.py by Terminal

I need calculated monthly mean of Snowcover data by MODIS product, and then modify this script gdal_calc.py in this section # create alphabetic list for storing input layers AlphaList=["A","B","C","...
4
votes
1answer
708 views

Wrong values using gdal_calc.py

I'm using gdal_calc.py to do some raster operations. The raster files stores precipitation values that are between 0 - 40 l/m² aprox. in some cases and the operations i'm trying to do: Values greater ...
4
votes
1answer
880 views

Does gdal_calc only support 26 input raster files at a time?

In gdal_calc.py, input files are specified with letters A-Z. Here are two files, input.tif and input2.tif, being averaged into result.tif: gdal_calc.py -A input.tif -B input2.tif --outfile=result....
4
votes
0answers
808 views

Merging two overlapping rasters

There are two rasters A and B. A is smaller but within B and since A has more up-to-date pixel values, I was able to merge A and B with "Mosaic raster layers" tool in QGIS which replaces B pixel ...
3
votes
1answer
277 views

How to average gdal_hillshades?

For some unknow reason, my average of 3 hillshades is very dark : gdaldem hillshade input.tif hillshades_C.tmp.tif -s 111120 -z 5 -az 315 -alt 60 -compute_edges gdaldem hillshade input.tif ...
3
votes
1answer
885 views

How to use gdal_calc.py to process multiple bands

I have 2 rasters (raster1 and raster2) with 5 bands for each one. I want to do some calculation using all bands and write the output to a file with 5 bands. I try this command : gdal_calc.py -A ...
3
votes
0answers
65 views

Accessing MODIS subdatasets from the command line?

FYI I'm new to command-line geospatial operations. I'm working with the MODIS BRDF-Albedo Quality product (MCD43A2) and am trying to: 1) do a simple gdal_calc.py operation to mask certain QA values ...
3
votes
0answers
86 views

Python stops during band algebra in GDAL calculator within modeler in QGIS

I'm trying to calculate four greenness indices using the GDAL calculator within the graphic modeler in QGIS 2.14.7 Essen. The tool systematically crashes with a Windows message stating that Python ...
2
votes
1answer
163 views

gdal_calc raster calculcator : “any” syntax

I'm trying to combine 2 raster layers using gdal_calc in order to use them in QGIS 3.8. One of the condition that has to be met could be translated as "if the value of raster A is 1 and the value of ...
2
votes
1answer
1k views

Inserting python variables into gdal_calc expression?

Is it possible to insert a python variable into gdal_calc expression? For example: mean = [stats[2]] ##mean value gdal_calc.py -A Input.tif --outfile=Output.tif --calc="1*(A>=mean)" --NoDataValue=...
2
votes
1answer
175 views

Gdal Calc quiet option not working

So I'm trying to use the quiet option for gdal calc, this is a cut of my code: call([sys.executable, 'C:\Program Files (x86)\GDAL\gdal_calc.py', '-A', Outer_Output_Raster, "--outfile=" + ...
2
votes
1answer
194 views

Problem with algebra formulas for work with gdal_calc.py

I'm trying to update some values of a raster based on another raster. 1st raster (A): landuse data (values from 10 to 240) 2nd raster (B): mask data (only nodata values and a given value, for ...
2
votes
0answers
46 views

gdalwarp cuts off top and right edge of globe from gfs data

I am using data from this GFS forecast: https://nomads.ncdc.noaa.gov/data/gfs4/201905/20190502/gfs_4_20190502_1800_000.grb2 Specifically the bands 102 and 103 containing wind data. I first combine ...
2
votes
0answers
100 views

gdal_calc.py does not work under sbt

I run a command line gdal_calc.py in a scala script. I run this script with 'sbt run' on my terminal. I got this error : Traceback (most recent call last): File "/usr/local/bin/gdal_calc.py", line ...
1
vote
1answer
772 views

Raster calculator syntax to gdal_calc

I am looking to perform raster math on two large rasters (slope ~1.3GB and aspect ~2.4GB). When I use the GIS raster calculator code below, QGIS errors out (out of memory), which is odd considering ...
1
vote
1answer
479 views

Meaning of NULL when using condition in gdal_calc

I am confused with the results of using a condition in gdal_calc. Initially I thought that gdal_calc was setting pixels to nodata where a condition is not met. In the documentation (http://www.gdal....
1
vote
1answer
67 views

Can gdal_calc operate conditionally with values from two tifs

I am trying to correct some water table .tifs (WT) to the ground level elevation (DEM) so that water levels are not incorrectly presented as above ground. I have looked at many similar questions and ...
1
vote
1answer
475 views

QGIS-3.10 raster calculator crashing on Windows

Trying to add several rasters, all multiplied by certain factors (like (A@1*.8)+(B@1*.003)+(C@1*.2)...) in raster calculator in QGIS 3.10 the program crashes on Windows (that doesn't happen on Linux, ...
1
vote
1answer
1k views

Gdal_calc NDVI for many rasters

Can anybody help me to solve a problem with running gdal_calc for many rasters? I have several multispectral images and I need a batch to perform NDVI calculation. I started with gdal code for one ...
1
vote
1answer
239 views

gdal_calc calculation

I am attempting to use the gdal_calc function to perform a calculation against 2 image bands. I have a images a)B04.jp2 and b)B08.jp2. It is basically the red band and the NIR band. I want to ...
1
vote
1answer
186 views

`gdal_calc.py` only outputs as Int16 even though set to Float32

The following code only outputs integer even though set to float32. 'gdal_calc.py -A input_raster.tif --A_band 1 --outfile output_raster.tif --calc "0.005 * A.astype(float)" --NoDataValue -32767 --...
1
vote
1answer
41 views

GDAL Calc using different raster grid sizes

I have several GeoTIFFs (.tif) that I am conducting raster calculations on using gdal_calc.py, all three are of different sizes. These rasters can be best illustrated with the following image: All ...
1
vote
1answer
35 views

Convert transparent black to white with only GDAL

I have an RGBA foo.tif with NoData Value=0 on all 4 bands. Unfortunately values that are transparent black (0 0 0 0), when converting to jpg, become black instead of no data becoming white like I ...
1
vote
2answers
225 views

gdal_calc equation results in error: divide by zero

iIt is quite obvious to me that the rasterset A, B within the NDVI equation, --calc='"((A-B)/(A+B))"' with cell_value=0 will lead to the above error (division by zero). How can I avoid the error?
1
vote
1answer
486 views

Calculate Raster mean with gdal_calc - unexpected result

I have in input a single band 2 axis tif raster (float32 values). Using gdal_calc I need to produce an output raster (same dimensions of input) that contains in every pixel the mean value of the whole ...
1
vote
1answer
111 views

GDAL calculation without stop python.exe error?

I want to create a simple raster calculation using python and GDAL and specific gdal_calc.py in osgeo4w shell. BUT any time that before finish my script python stopping I take error : python.exe ...
1
vote
2answers
563 views

gdal_calc : fails with value 0?

I working to invert values of a one-band tif files (download sample). If i use 254 it works: $ gdal_calc.py -A ./shadedrelief.tmp.tif --outfile=whited.tmp.tif --calc="254*(A>180)" 0 .. 10 .. ...
1
vote
1answer
65 views

Getting 4-band raster from gdal_calc.py

I have 4 channel rasters in GeoTIFF. I need to find the average value of these rasters and present them in the form of another raster, also in RGB, and I get a black and white file. How can I get ...
1
vote
0answers
63 views

Combine two raster with PostGIS or gdal_calc

I want to combine two rasters (GeoTIFF or PostGIS raster) so that the result is a table showing each combination of values and their count. Example: raster 1 raster 2 1 2 3 40 40 10 2 3 3 10 20 ...
1
vote
2answers
112 views

gdal_calc raster calculation fails on 28 GB GeoTiff

I am trying to do a raster calculations on a 28 GB GeoTiff using gdal_calc.py (3.0.4) but the process fails gdal_calc.py -A DEM_0.tif --outfile=DEM_1.tif --calc="A+0.33" --format=GTiff --...
1
vote
0answers
64 views

Getting inconsistent raster output from gdal_calc.py raster calculation

I'm attempting to do what is generally a straightforward raster calculation when I do this in QGIS, but am trying to do this with gdal_calc.py in terminal. The output is close, but produces banding ...
1
vote
0answers
65 views

Get maximum value from two raster using gdal_calc.py with option Ignore NoData calculation enabled

I would like to get maximum value from two raster using gdal_calc.py with option Ignore NoData calculation enabled. My question is similar to this unsolved problem: How do I get the maximum value of ...
1
vote
2answers
116 views

What is the correct GDAL Calc Syntax?

I need to calculate in gdal_calc the following python script. if (A == 0 and B == 0): wd = 0.0 else: wd = np.arctan2(A,B) I have tried if(A = 0 && B = 0,(0.0), else,(...
1
vote
0answers
183 views

gdal_calc.py result are false and not the same as “direct” calculation

I need to do the raster calculator operation as "raster + constant" in Python. The input rasters are DEM data with float original type and -9999 for the NoData. The constant is float too. In 1st way, ...
1
vote
0answers
490 views

Run gdal_calc with more than 26 input bands

I'm trying to average 30 greyscale netCDF files pixel-by-pixel using gdal_calc.py. However the script seems to require the input files to be enumerated with letters A-Z, so I'm four letters short. ...
1
vote
0answers
157 views

gdal_calc - FutureWarning: comparison to `None` will result in an elementwise object comparison in the future

I use gdal_calc in the loop: for inp, out in zip(input, output): input_str = ''.join(inp) print input_str output_str = ''.join(out) print output_str gdal_calc = 'python ...
1
vote
0answers
228 views

Raster Calculation Using GDAL

I want to perform raster calculation from GDAL tool. I am using the formula as, gdal_calc.py -A Input_File.tif --outfile=yourOutput.tif -- calc="(A>=2200)*A" --NoDataValue=0 --type='Float32' But ...
1
vote
0answers
91 views

GDAL_CALC weird results

Can anyone explain why for gdal_calc results differ in the two cases below? case 1: (A>0)-(A<10)+(A>0)-(A<10) case 2: ((A>0)-(A<10)) + ((A>0)-(A<10)) Mathematically speaking, the two ...
0
votes
1answer
432 views

Binarise Raster within a range with gdal_calc.py [closed]

I am looking to utilise gdal_calc to batch binarise a few hundred rasters. My problem is in relation to gdal_calc and the correct syntax for --calc to do what I wish to achieve. Using QGIS Raster ...
0
votes
1answer
484 views

GDAL Calc Set Specific Values to Another Number

I have a GeoTiff raster with a format of Float32 and values 0.00 to 5.00. I am attempting to change all raster cells with a value below 0.10 to 0.10, and leave all other cells in the raster dataset ...