[Qgis-user] Raster Calculator Error Questions

Thayer Young thayeray at yahoo.com
Sat Feb 13 07:53:05 PST 2021


 Hi Wanda,  
Please try removing the spaces between the operators, the tool should not run with those spaces:     they should be: <= and >= not < = and > = 
Also make sure that the name of the raster layer is EXACTLY the same as what you have in your Layers panel (what the ESRI work calls Table of Contents). The double quotes around the name are there just in case you have a space in the name of the raster Layer. You can safely remove them if there are no spaces. The parenthesis are also not necessary, because of the order of operations (the same as in basic algebra). The <= and >= will calculate before the OR, so there is no need for parenthesis. You would only need parenthesis if the expression were more complicated.The following should work equally well:
Aspect at 1<=90 OR Aspect at 1>=270 Aspect at 1 <= 90 OR Aspect at 1 >= 270 
"Aspect at 1" <= 90 OR "Aspect at 1" >= 270 
("Aspect at 1" <= 90) OR ("Aspect at 1" >= 270)

But if your layer is named "Aspect" but you enter "aspect", the raster calculator will say the expression is valid but then show a red banner error after it is run.This is because the expression looks fine to the raster calculator tool, but it does not check for the existence of the layer until you press OK. In this case it can not find a layer "aspect" because the layer is named "Aspect".
I have tried reproducing your problem using the OSGeo4W Network Installer QGIS 10.10 without GRASS, but I am not able to. If the recommendations above are not helpful, you may need to give more specifics about the errors you are seeing and which installation you are using. I hope this helps :-)

-Thayer
P.S. I did have a problem with the extent not being set correctly when I had more than one DEM. Everything ran without errors, but the result was empty, except for a thin band where the two DEMs overlapped. You may need to be careful to set this to the correct extent, so click on your Aspect layer and then Selected Layer Extent.


======================================================Date: Fri, 12 Feb 2021 14:12:49 -0500
From: Wanda Norman <wanda.mnorman2015 at gmail.com>
To: Nicolas Cadieux <njacadieux.gitlab at gmail.com>
Cc: qgis-user <qgis-user at lists.osgeo.org>
Subject: Re: [Qgis-user] Raster Calculator Error Questions
Message-ID:
    <CAFN0wn0gq9wJY3=URkK0MHDuJCE_BvwEowH2_L7hbxeX6kM0vA at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks Nicolas for the quick response.  But I am still having issues.

I did upgrade to the 3.16 version and I am still unable to write the
formula.  I tried:  ( "aspect at 1" < = 90) OR ( "aspect at 1" > = 270) - I get
Expression is not valid. As soon as I put anything other than "aspect at 1" I
get a message that the expression is not valid.

This is the first time using the raster calculator and it looks as if I
can't move forward with the lesson without this step.

Any other suggestions?

Thanks for your help!
Wanda



On Fri, Feb 12, 2021 at 10:08 AM Nicolas Cadieux <
njacadieux.gitlab at gmail.com> wrote:

> Hi,
> I have not used the raster calculator in a while but I am not sure about
> you use of the \.
> Examples in the user manual (
> https://docs.qgis.org/3.16/en/docs/user_manual/working_with_raster/raster_analysis.html#raster-calculator)
> use this as examples.
>
> ("elevation at 1" < 50) * 1 + ("elevation at 1" >= 50) * 2
>
>
> I would try (expression 1) OR (expression 2).  Layers names must be placed
> between quotes ??.
>
> You could also update your QGIS version to 3.16.
>
> Nicolas Cadieux
> https://gitlab.com/njacadieux
>
> Le 12 f?vr. 2021 ? 09:09, Wanda Norman <wanda.mnorman2015 at gmail.com> a
> ?crit :
>
> ?
>
> Greetings friends:
>
>
>
> I am working on lesson 7.3.5 in the User Guide / Manual (QGIS 3.10) ?
> Following along: Using the Raster Calculator.
>
>
>
> I am having difficulty with the calculation formula as indicated below:
>
>
>
> The manual states this formula should be used:
>
>                Aspect at 1 <=90 OR Aspect at 1 >= 270
>
> Which I am assuming is incorrect because a) I get an error when I run it;
> and b) when I set the parameters using the expression operators the formula
> looks like this:
>
>                ?Aspect at 1? <=90 OR ?Aspect at 1? >=270
>
> However, I still get the error:
>
> Error parsing formula
>
> Execution failed after 0.02 seconds
>
>
>
> With some help ? I then tried this formula
>
> \?Aspect at 1?\ <=90 OR \?Aspect at 1?\ >=270
>
> Which worked for this assignment.
>
>
>
> However, moving on to lesson 7.3.6 ? More criteria: which takes me to
> 21.12.2. Calculate slope (less than 2 and 5 degrees)
>
> I get the same error as above again.
>
>
>
> I am steadily working my way through the Manual and would appreciate any
> help.  I am using QGIS version 3.10.9-A Coruna (64 bit) on a Windows PC.
>
>
>
> Thank you!
>
> Wanda Norman
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210212/83089c60/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Qgis-user mailing list
Qgis-user at lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


------------------------------

End of Qgis-user Digest, Vol 180, Issue 35
******************************************
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210213/fcd01f85/attachment.html>


More information about the Qgis-user mailing list