QGIS – How to Export Coordinates When Clicking on Points

coordinatesexportopenstreetmapqgistable

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

Best Answer

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