1

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 Feb 23 at 11:28
4

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.

3
  • 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 Feb 23 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 Feb 23 at 12:03
  • Not running it from the processing toolbox was the issue, and that might be the case for another model I have - many thanks – Sethinacan Feb 23 at 12:05

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.