-1

I am trying to find out which functions am I supposed to use, in order to get the values that I need.

The Table should look like this. I have all the values available, now I am trying to get different form of values in a column text.

enter image description here

What I am trying to achieve is next:

When objekt is "Nivelation", then text should have a value of height with added letter "m".

When objekt is "GR-A", then text should have the value "A".

When objekt is "Point" and there is Value in column number, then the text should have a combined value of "P-number"

When objekt is Line and there is Value in column number, then the text should combine those two and add a direction (North, Northeast etc..)

I was trying to use different functions, like if and when, but I am not familiar with QGIS that much.

Which functions should I use and how should I write these functions in order to achieve these results?

I am using QGIS version 3.22.9 Bialowieza

I tried writing when and if functions, however, I am not sure that I even know how these functions should I use to get what I need.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 14, 2023 at 12:38
5
  • Welcome to Geographic Information Systems! Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour for more about how the site works Commented Aug 14, 2023 at 12:43
  • "number" field is a compass bearing? Why should 33 get the value E? Commented Aug 14, 2023 at 14:06
  • 1
    Have you had a look at the tooltips in the fieldcalculator for if() and case when? Commented Aug 14, 2023 at 14:24
  • case when should work Commented Aug 15, 2023 at 5:55
  • @Bera "number" field is sort of an ID of this line. It should get the value E, in order to know the direction from which it was photographed. I found the code for calculating bearing (atan((xat(-1)-xat(0))/(yat(-1)-yat(0)))) * 180/3.14159 + (180 *(((yat(-1)-yat(0)) < 0) + (((xat(-1)-xat(0)) < 0 AND (yat(-1) - yat(0)) >0)*2))) It is the direction of a line, and the direction of photographing is a whole other problem. That is a whole new set of values to import. Or somehow modifying the line to show the direction of the photo with starting and end points. Commented Aug 29, 2023 at 13:21

1 Answer 1

0

After some time, I got back to this problem. Seems like CASE WHEN solves partially my problem. This is the result for the first two lines of a table. || are needed in order to solve multiple values.

CASE WHEN objekt = 'Nivelation' THEN "height" ELSE '' END || CASE WHEN objekt = 'GR-A' THEN 'A' ELSE '' END

For some reason in a "text" which has string value, my height gets point instead of comma. So I used expression replace.

replace( "text", '.', ',' )

To add m as in meter, I found next solution, with the end of a expression being important, in order not to annulate all other values.

CASE WHEN objekt = 'Nivelation' THEN concat ( "text", ' m' ) ELSE "text" END

answered Aug 29, 2023 at 13:11
1
  • You dont need to repeat the CASE each time, you just have to put it at first then as many WHEN ...THEN...as you want, if needed one ELSE after the last and you finish the case statement by END. See this question for an exemple of proper syntax gis.stackexchange.com/questions/416884/… Commented Aug 29, 2023 at 16:22

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.