3

Assumed I click around on a map, while I need to export the coordinates of the points where I have clicked into a simple text file. In best case, writing into the text file should be performed automatically.

Example:

  1. Mouse click 1 will write 52.516417, 13.378361 into the table
  2. Moving the mouse
  3. Mouse click 2 will write 52.556877, 14.358861 into the table
  4. Moving the mouse
  5. Mouse click 3 will write current coordinates into the table

Background:

OpenStreetMap is using polygon lines to visualize streets. I want to create a custom route along specific streets and hereby export the coordinates of the points where I have clicked.

Is this possible in OpenStreetMap or QGIS?


The approach of eurojam is great! Unfortunately, it does not work on my very old version of QGIS as I receive the following error:

Is this caused due to old python or due to old QGIS? Would it be possible to refactore the python code so it works on QGIS 2.14.11 as well?

enter image description here

Dave
  • 181
  • 4
  • It's possible to load the openstreetmap basemap into QGIS. Then you can create a new vector layer (lines). You can then create lines by tracing routes, which you can export to a text file, or you can explode the lines to points and export the points to a text file. – jbalk Sep 10 '21 at 23:38
  • 1
    As it was pointed out by @jbalk, you can load the openstreetmap basemap into QGIS and to code in Python, as in following link: https://gis.stackexchange.com/questions/253733/how-to-get-co-ordinates-of-points-on-mouse-click-in-pyqgis , for creating a custom route along specific streets and hereby export the coordinates of the points where you have clicked (to the python console, to a Qt display object or to a text file). – xunilk Sep 11 '21 at 00:33

1 Answers1

4

one simple solution would be to use Layeractions and log the clicked coordinates within the Log Messages from QGIS:

  1. Open the Properties of your OSM Street layer and go to the Actions tab
  2. Press Add
  3. Define a Python Action
  4. Enter the Code

The Code fragment:

QgsMessageLog.logMessage( "[% @click_x %] ,[% @click_y %]", tag='Coordinates', level=Qgis.Info)

QGIS2.14 you can try:

QgsMessageLog.logMessage( "[% @click_x %] ,[% @click_y %]") 

enter image description here

  1. Choose the Action from the Toolbar and click in on the Roadlayer
  2. Open the message log
  3. In the message logs there will be a new tab: coordinates where the clicked positions will be listet. you can copy and paste them from there...

enter image description here

eurojam
  • 10,762
  • 1
  • 13
  • 27
  • 1
    this is really a smart solution! – Taras Sep 11 '21 at 16:51
  • Thank you very much for this great approach! Unfortunately I am using a very old version of QGIS (2.1.4.11) which is probably the reason why your Python-code does not work as expected (see error screenshot in my question post). Would it be possible to get it work with older versions as well? – Dave Sep 12 '21 at 10:06
  • @Dave: I edited my answer above. – eurojam Sep 12 '21 at 15:50