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
1 answer
17 views

gdal_cal.py with subprocess in python

I tried to do raster calculation and save the file to a new raster with subprocess in Python: subprocess.run(['python', 'gdal_calc.py', '-A', image1, '-B', 'MSL_TEMP.tif', '--outfile = DEMNAS_MSL.tif',...
HKF's user avatar
  • 1
0 votes
0 answers
29 views

Why gdal_calc.py returns 0 (Zeros) instead of NaN in the output?

Why this gdal command returns 0 (zeros) instead of NaN in the outfile? gdal_calc.py -A aa.tif --outfile="out.tif" --type=Float64 --NoDataValue=nan --co="COMPRESS=DEFLATE" --format ...
jurajb's user avatar
  • 1,192
3 votes
1 answer
64 views

Fixing errors in old DTM in QGIS

I'm currently working on fixing some errors in some old DTMs. The issue is there are pixels with a value of "-1.4013e-45" which are all over the rasters. I'm looking for a way to remove ...
Richard McDonnell's user avatar
1 vote
0 answers
43 views

gdal python gdal_calc function not giving same results as command line

I have an interpolated file which looks like this The Z values in it are positive, so I want to use gdal_calc to make them negative. This works on the command line with gdal_calc -a interpolated.tif -...
Guest_question_1087626532's user avatar
2 votes
1 answer
61 views

gdal_calc returning incorrect value in decimal part

I am using gdal_calc to fill some of the no-data values of one raster from another raster. Here is my command. Both have the same projection, cell size, etc. The output value in the resultant raster ...
ar-siddiqui's user avatar
  • 1,708
1 vote
0 answers
83 views

Create a continuous new DEM using bathymetry and topography

I have two rasters. One is the topography map and the other one is the bathymetry. I would like to create a new DEM where everything below the sea level will come from bathymetry.tif, while everything ...
ELO STERN's user avatar
0 votes
1 answer
58 views

Trouble Converting gdal_calc.py output to Floating Point

I am new to coding. I'm looking to create an NDVI on S2 data using gdal_calc.py in a Jupyter Notebook. I've downloaded imagery from GEE using code provided by the JRC, European Commission. I selected ...
OpenGeo's user avatar
2 votes
1 answer
201 views

What could go wrong using gdal_calc to sum pixel values of a multiband raster?

I have a raster, input.tif. I can open it using rasterio and read 3 bands: import rasterio with rasterio.open('input.tif') as src: data1 = src.read(1) data2 = src.read(2) data3 = src.read(...
zabop's user avatar
  • 1,624
0 votes
1 answer
58 views

How do you reclassify a single integer band raster to keep only the last digit for each cell value?

I need to reclassify a raster with values in the form xxxxx1, xxxxx2, or xxxxx3. Each digit of cells values encodes a categorical information (e.g. first digit is the land cover, second digit the ...
Dim''s user avatar
  • 313
0 votes
0 answers
186 views

Unable to divide rasters through gdal_calc.py because of unicode error

I am trying to use python in Jupyter Notebook to divide raster file A by raster file B. I am trying to use the gdal_calc.py program in a Jupyter Notebook cell, and not in the command line, and so I am ...
LostinSpatialAnalysis's user avatar
0 votes
2 answers
388 views

gdal_calc.py: error: the following arguments are required: --outfile

I'm trying to perform an operation using gdal calculator: 90*logical_and(A==111, B==3) + 92*logical_and(A==111, B==4) + 81*logical_and(A==112, B==3) + 86*logical_and(A==112, B==4) but I get the ...
Antonio Barone's user avatar
0 votes
0 answers
81 views

Reclassifying 1 band TIFF with gdal_calc

I have a single band 8 bit TIFF and want to reclassify the following cell values to 1 as follows: OLD NEW 26 1 71 1 20 1 24 1 I have tried the following which as far as I can ...
Robert Buckley's user avatar
2 votes
0 answers
214 views

gdal_calc --hideNoData not working in python script

I am trying to convert the following GDAL code which works perfectly in the command shell into a python script gdal_calc --calc "(A == 0) * B + (A != 0) * A" --format GTiff --type Float32 -A ...
user196963's user avatar
1 vote
1 answer
174 views

GDAL - Convert QGIS raster calc expression to valid syntax for gdal_calc

I have been using QGIS Raster Calculator to patch Raster Bs values in where Raster As are 0 using the below expression ("A@1" = 0) * "B@1" + ("A@1" != 0) * "A@1"...
user196963's user avatar
2 votes
2 answers
357 views

Using gdal_calc.py from the OSGeoW4 Shell [duplicate]

I want to run gdal_calc.py from within the OSGeoW4 shell but am having only limited success. Firstly, if I type in -o help gdal_calc does not appear in the list, as show below, whereas I have seen ...
AndyH's user avatar
  • 61
1 vote
1 answer
797 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 ...
TornadoEric's user avatar
1 vote
1 answer
443 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 ...
Константин 's user avatar
1 vote
1 answer
588 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 ...
eddygeek's user avatar
  • 155
1 vote
0 answers
202 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 ...
Pemburu's user avatar
  • 71
0 votes
1 answer
187 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 ...
almrog's user avatar
  • 169
3 votes
2 answers
400 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 --...
EOF's user avatar
  • 71
0 votes
1 answer
359 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 ...
brentiemapper's user avatar
0 votes
0 answers
203 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 ...
user2102823's user avatar
1 vote
1 answer
783 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 ...
Nathan Raley's user avatar
1 vote
1 answer
342 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 ...
Casivio's user avatar
  • 339
1 vote
1 answer
721 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, ...
Elio Diaz's user avatar
  • 3,454
2 votes
0 answers
68 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 ...
Manas Sharma's user avatar
3 votes
0 answers
140 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 ...
GeoCat333's user avatar
2 votes
1 answer
290 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 ...
Mefimefi's user avatar
  • 586
2 votes
2 answers
587 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?
Andreas's user avatar
  • 21
1 vote
0 answers
164 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 ...
sreiny's user avatar
  • 21
1 vote
0 answers
116 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 ...
user97103's user avatar
  • 537
1 vote
2 answers
276 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,(...
Julio Almeida's user avatar
1 vote
1 answer
1k 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 ...
TornadoEric's user avatar
0 votes
2 answers
203 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 ...
STO's user avatar
  • 317
0 votes
1 answer
300 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-...
wondim's user avatar
  • 1,363
1 vote
1 answer
401 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 ...
Antonio's user avatar
  • 321
1 vote
0 answers
242 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, ...
Anna's user avatar
  • 11
1 vote
1 answer
539 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 --...
wondim's user avatar
  • 1,363
0 votes
0 answers
449 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....
joaoal's user avatar
  • 891
4 votes
1 answer
2k 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 ...
Sami's user avatar
  • 41
1 vote
1 answer
810 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....
tvoirand's user avatar
  • 254
5 votes
0 answers
1k 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 ...
Curtis's user avatar
  • 213
1 vote
1 answer
798 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 ...
user122734's user avatar
2 votes
0 answers
913 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. ...
zinfandel's user avatar
  • 161
1 vote
1 answer
165 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 ...
Chris Papas's user avatar
4 votes
2 answers
1k 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] ...
Nick Underwood's user avatar
1 vote
0 answers
179 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 ...
kamfulebu's user avatar
  • 351
2 votes
1 answer
2k 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=...
kamfulebu's user avatar
  • 351
6 votes
0 answers
2k 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: ...
Ryan Garnett's user avatar
  • 9,461