0

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 second raster will be kept when the first raster has values from 4 to 6. How could I do this using gdal_calc.py?

I tried:

gdal_calc.py -A first_raster.tif -B second_raster.tif --outfile=Result.tif --calc="B*(3<=A>=7)" --NoDataValue=0

But I get a Value Error:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Is that the correct way to introduce this condition in to the raster calculator? I thought that follows the same logic than the raster calculator used in QGIS, where the value in the ouput we want goes together with the * simbol and the condition goes in parenthesis.

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Sep 7, 2020 at 10:28

1 Answer 1

0

I believe gdal_calc.py doesn't cope well with combined relations such as (3<=A>=7). It might be better to split it up:

--calc="B*logical_and(3 <= A, A >= 7)"
answered Sep 7, 2020 at 11:19
1
  • AND is not a thing. You mean logical_and(3 <= A, A >= 7) Commented Aug 18, 2021 at 0:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.