2

I have a raster layer which illustrates land use in Rwanda. I would like to be able to extract the cropland and make it a raster by itself. I have tried to extract it using the raster calculator, however it does not work for me.

I tried using these two formulas:

(9 <= "Landcover_raster" <= 10)*1 + ((9 > "Landcover_raster") AND ("Landcover_raster" > 10))*0

and

("Landcover_raster" = 0.21)*1 + ("Landcover_raster" != 0.21)*0

I was unsure whether I could extract it based on the value of the attribute or the label of the attribute.

Am I using the raster calculator wrong or is there another way to extract a certain attribute from a raster file?

2
  • What is the rastervalue of cropland?
    – Bera
    Commented May 5, 2021 at 8:08
  • There are two different kind of cropland, so the raster value is both 9 and 10. And then I have given them both the label 0.21, because that is the value that cropland should have in my formula.
    – anneke
    Commented May 5, 2021 at 8:21

1 Answer 1

1
(("Landcover_raster"=9)+("Landcover_raster"=10))*.21

should work. It multiplies X by .21 where X is either 0 or 1, depending on whether it is land cover (9 or 10).

It is helpful to remember that with 1 and 0,

  • OR is +,
  • AND is *
3
  • Thank you so much! That's exactly what I needed! :-)
    – anneke
    Commented May 5, 2021 at 8:50
  • You can multiply by a million. The final number is unimportant :-)
    – wingnut
    Commented May 5, 2021 at 8:53
  • @anneke: if an answer helped you solve your problem, you should accept it (hit the checkbox) and/or upvote it: gis.stackexchange.com/help/someone-answers
    – Babel
    Commented Jun 6, 2021 at 10:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.