I am testing the capabilities to run my R script in QGIS. I am facing a basic question.
I am defining a dropdown menu with all the parameters for a specific variable:
##test1=group
##Sensor?=selection S1;S2;S1 AND S2
Then I use this basic code to test if I can use the selection of the user within an if statement
if (S1){
print("It is working")
}
My script is not working and is reporting the following error. Any idea how this type of variables can be used in a if statement
. Shoud I use a reguluar boolean variable
. If so, how should it be implemented?
Sensor?=0
Error: unexpected '=' in "Sensor?="
Execution halted
Converting outputs
Loading resulting layers
Algorithm [Unnamed algorithm] finished
1 Answer 1
Just found the solution,
##test1=group
##Sensor=selection S1;S2;S1 AND S2
if (Sensor == "S1"){
print("It is working")
}
I think there is little information or non-unified place to find documentation about the implementation of R scripts in QGIS. If you find a good guide, please feel free to add it on the comments.
--- EDIT ---
Based on another post (Using if statement in R script within QGIS)
##test1=group
##Sensor=selection S1;S2;S1 AND S2
if (Sensor == 0){
print("It is working")
}
works as well taking into account the python
indexing rule
-
2Actually posting an answer to your own question so others can use it. Hero.TeddyTedTed– TeddyTedTed2019年02月26日 10:18:53 +00:00Commented Feb 26, 2019 at 10:18
-
2@TeddyTedTed, I think it happens to me as well. Sometimes the solution is much simpler than you expected. But when you are lost you are normally trying to implement any possible approaches to achieve the result that you are striving for. And then at some point, you see that miserable answer hidden in your
"Learn by falling, falling, ... , falling, trying, and achieving"
method. And IMHO it is always better when you find solution/answering your own question by yourself.2019年02月26日 11:52:19 +00:00Commented Feb 26, 2019 at 11:52 -
3@Taras I definitely agree, very satisfying to finally figure something out as well. My previous comment was meant as praise for GCGM posting an answer to their own question, sorry for any confusion.TeddyTedTed– TeddyTedTed2019年02月26日 12:25:27 +00:00Commented Feb 26, 2019 at 12:25
Explore related questions
See similar questions with these tags.