3

I am trying to calculate a bearing from each point in a layer to a single target using the graphical modeller as its part of some other processing I need to do. I can do the bearing calculation (below) but is there a way to get X,Y coordinates from a mouse click and use that as the target?

(atan2((targetx-$x),(targety-$y)))*57.295779513082320876798154814105

1
  • I suggest you use the azimuth expression of the field calculator instead of your custom expression.
    – Erik
    Commented Feb 23, 2021 at 11:28

1 Answer 1

6

Yes, you can use "Point"-Input in your model:

enter image description here

It expects a user given point by clicking on the canvas and return x,y [EPSG:xxxx] e.g. -0.12,12.4 [EPSG:4326]. You can turn this into a geometry-point by using regular expressions like

make_point(
array_get(string_to_array((regexp_substr(to_string('-0.12,12.4 [EPSG:4326]'),'[^\\s]*'))),0),
array_get(string_to_array((regexp_substr(to_string('-0.12,12.4 [EPSG:4326]'),'[^\\s]*'))),1)
)

Where you should use @point as variable accessing this input instead of -0.12,12.4 [EPSG:4326]. Its your original input name without whitespaces and an @ in front. so your expression could be

(atan2((to_real(array_get(string_to_array((regexp_substr(to_string(@point),'[^\\s]*'))),0)-$x)),(to_real(array_get(string_to_array((regexp_substr(to_string(@point),'[^\\s]*'))),1)-$y))))*57.295779513082320876798154814105

Note, that you wont be able to test this when you run the model from the model builder. You need to save it first and run it from your processing toolbox, otherwise you wont get a chance to click on your canvas.

5
  • Cheers for the advice, I tried using the point input but I didn't get any option to click on screen when I ran the model and clicked the 3 dots so I assumed I was heading in the wrong direction, maybe it isn't running right or I have done something wrong elsewhere
    – Sethinacan
    Commented Feb 23, 2021 at 11:53
  • @Sethinacan You can only click one point, not 3. If you need three points, you need 3 Point-Inputs. Also its a little annoying that you need to save your model first and run it from processing toolbox. If you run it from inside the model builder you wont be able to click on the canvas...
    – MrXsquared
    Commented Feb 23, 2021 at 12:03
  • 1
    Not running it from the processing toolbox was the issue, and that might be the case for another model I have - many thanks
    – Sethinacan
    Commented Feb 23, 2021 at 12:05
  • The Point Input is not available as Model Input in any algorithm I tried. Which algorithm would you use to create an actually usable geometry from it? Commented Apr 8, 2022 at 7:47
  • Nevermind, there is a Create Layer from Point algorithm exactly for this. Commented Apr 8, 2022 at 7:49

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.