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
0
votes
0answers
17 views

Running Batch Files with QGIS .asc/.tif files

I have the following two batch files and the following error message in the run window. What I want the Trimming Depths.bat file to do is to create a new .tif file that shows values larger than 0.05m ...
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
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
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 ...
0
votes
0answers
72 views

GDAL: sum of all bands in a raster

I'm familiar with using gdal_calc.py to sum individual raster bands. However, I am curious whether there is an easy way to programmatically sum all bands of a raster into a single value. I have a list ...
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 ...
0
votes
0answers
71 views

How to sum pixels of two overlapping rasters with different extents

I have two DEM rasters which overlap and have different extents. I would like to create a new raster which sums the pixels where there is an overlap. I tried using gdal_calc first by doing A+B but ...
0
votes
1answer
29 views

Problem with raster calculator gdal_calc.py

I have two rasters. One with the following values: 0,1,2,3,4,5,6,7,8,9,10 and the other one with continuous values ranging from 0 to 10000. I would like to create a raster where only values of the ...
1
vote
2answers
111 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 --...
0
votes
1answer
98 views

gdal_calc.py SyntaxError

I tried to use gdal_calc.py to avoid using the manual GUI raster calculator in QGIS. However, I'm not yet familiar with it and having errors with my code: gdal_calc.py -A perennials.tif -B annuals.tif ...
0
votes
0answers
43 views

Mirroring raster using gdal_calc

I am trying to flip (mirror) a raster upside-down. Using following command incoporating numpy function flipud() gdal_calc.py -A input.tif --calc="flipud(A)" --output output.flipud.tif resulted with ...
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 ...
0
votes
0answers
48 views

gdal_calc in C#

I am writing a .NET core application and have been trying to utilize the Gdal libraries. I have added Gdal.Core and Gdal.Core.WindowsRuntime NuGet packages to my project. I have been able to ...
1
vote
1answer
66 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, ...
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 ...
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 ...
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 ...
1
vote
2answers
224 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
0answers
63 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
64 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
115 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,(...
0
votes
1answer
483 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 ...
0
votes
2answers
116 views

Classify DEM pixels

I have a differential surface model dataset. That was made: DSM subtracted from DTM, so for example trees have negative height. It is a raster (TIFF) dataset, Type=Float32. I want to create a ...
0
votes
1answer
150 views

Gdal_calc outputs image with no projection

I am trying to convert a pixel value above 0.02 to be nodata. However, the output file comes out with no projection. When I assign projection, QGIS loads it in the wrong place. gdal_calc.py -A "000-...
0
votes
1answer
187 views

Calculate max of all cells of a raster with gdal_calc.py

I want to calculate max of all cells of a raster, i.e. the result should be a scalar. Regardless of what I call amax, max, numpy.max(A, axis=0) I always get a raster with the same WxH as the original ...
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
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 --...
0
votes
0answers
231 views

Error using gdal_calc.py with gdal 2.2.1 on linux (undefined symbol: GDALCreateDriver)

My gdal libraries work properly with any other function used. However, using gdal_calc.py I run into troubles. I use gdal from the shell (linux) with this command: gdal_calc.py -A /somepath/somefile....
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 ...
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....
4
votes
0answers
806 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 ...
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
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
1answer
110 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 ...
4
votes
2answers
705 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] ...
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 ...
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=...
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: ...
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
506 views

gdal calc to convert multiple values

I'm trying to use GDAL calc to convert values in a .tif file, I've done this before with GDAL calc but for converting to a single value. Now I'm trying to convert multiple values in this fashion: 0.0 ...
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=" + ...
0
votes
0answers
559 views

python GDAL raster calculation error message

hello I try to follow this post and Friend commend : import os gdal_calc = 'python C:/PROGRA~2/GDAL/gdal_calc.py -A d:/mnt_5x5.tif --outfile=d:/test.tif --calc="A+1"' os.system(gdal_calc) but I ...
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
771 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
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 ...
5
votes
0answers
274 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 ...
0
votes
0answers
398 views

calculate percentiles with gdal_calc

I am trying to calculate percentiles with gdal_calc.py using my command line. I have a raster stack (11bands) and I would like to calculate the 0.85 percentile for each pixel over the entire stack (...
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 +...
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 ...