0

enter image description hereI've been trying to make rasters of the area within a certain elevation band of some elevation rasters I have. Simple enough. But when I do the raster calculation, the output is not what it should be (like in a raster with values 1000-2000 if I do "raster">1500 there should be some some areas >1500 that are one color and other areas that are another color, but the resultant raster is one solid block of a single color)

I attached some pictures of what I did and the result to hopefully show the problem better. As you can see, the resultant vector should be a mix of black and white, because some of the original raster is <1525, but it is not

I'm just trying to figure out how to get these kinds of calculations to work


This was my result

nan is from divide by zero, right? Why would this pop up here? I'm not even dividing anything

enter image description here

  • Don't forget to take the Tour to learn about our focussed Q&A format. As it stands I think your question would benefit from being revised some more to try and make what you are asking clearer. I recommend reviewing meta.gis.stackexchange.com/a/3353/115 for tips on how to structure a good question. I also recommend not deleting your questions, except in rare cases, because they carry some weight in the question ban algorithms. It is better to improve rather than delete questions. – PolyGeo Mar 29 '18 at 2:53
  • I've struggled with how to describe this problem because it's so bizarre and inconsistent. I'm open to suggestions of how to clarify it – Shane Mar 29 '18 at 4:01
  • Problems that cannot be reproduced reliably make poor questions for this site, and we have a close reason for them of "This problem cannot or can no longer be reproduced." The best chance of enabling potential answerers to reproduce your problem is if you record in detail the steps you took once to see the problem, then follow them again. If you see the issue each time you follow those steps then you have a problem suitable to ask about here and will be able to present those steps. – PolyGeo Mar 29 '18 at 4:16
  • The problem is actually readily reproducible, it always happens the same if you don't vary the zoom level, etc. Sorry I was unclear – Shane Mar 29 '18 at 4:40
  • I get a slightly different bad result depending on the zoom level and whether other rasters are loaded and a few other things, but it always gives the same result for the same conditions – Shane Mar 29 '18 at 4:43
1

Although I cannot see the raster value of 3110 maybe due to the min and max values in the raster statistics are not set properly, but anyway you can achieve what you want by applying the following expression:

("dblbnd@1" > 1525  AND  "dblbnd@1" < 3110)  *  "dblbnd@1"

Please note that the values below or equal to 1525 and above and equal to 3110 will assigned 0 because they don't meet the condition above.

Here is an example to extract the values above 800 and below 2000 from the image below:

enter image description here

Using raster calculator, I wrote the following expression:

("Test@1"  > 800  AND "Test@1" <2000) * "Test@1"

enter image description here

Here is the output:

enter image description here

You can set the zero value to null using r.null tool in GRASS and replace 0 with -9999 asfollows:

enter image description here

The final output raster will have values ranges from 801 to 1999 as extracted from raster calculator:

enter image description here

  • What version of QGIS are you using? Doing it the way you suggest still gives me the same result I was getting before – Shane Mar 29 '18 at 5:59
  • I used QGIS 2.18.17 – ahmadhanb Mar 29 '18 at 6:00
  • I used 2.18 too, and I copied what you did exactly. But somehow the result is different – Shane Mar 29 '18 at 6:01
  • "I cannot see the raster value of 3110" 1525-3110 was just the range I was using, not all the rasters I'm using exceed both bounds – Shane Mar 29 '18 at 6:02
  • I'm using USGS data as my inputs so it's not like the data should be bad or anything either – Shane Mar 29 '18 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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