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

asked Sep 10, 2021 at 22:49
2
  • 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. Commented Sep 10, 2021 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: gis.stackexchange.com/questions/253733/… , 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). Commented Sep 11, 2021 at 0:33

1 Answer 1

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

answered Sep 11, 2021 at 10:58
3
  • 1
    this is really a smart solution! Commented Sep 11, 2021 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? Commented Sep 12, 2021 at 10:06
  • @Dave: I edited my answer above. Commented Sep 12, 2021 at 15:50

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.