TransWikia.com

XY coords for clicked point QGIS graphical modeller

Geographic Information Systems Asked on June 15, 2021

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

One Answer

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.

Correct answer by MrXsquared on June 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP