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:
- Mouse click 1 will write
52.516417, 13.378361
into the table - Moving the mouse
- Mouse click 2 will write
52.556877, 14.358861
into the table - Moving the mouse
- 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?
-
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– jbalk2021年09月10日 23:38:45 +00:00Commented Sep 10, 2021 at 23:38
-
1As 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).xunilk– xunilk2021年09月11日 00:33:33 +00:00Commented Sep 11, 2021 at 0:33
1 Answer 1
one simple solution would be to use Layeractions and log the clicked coordinates within the Log Messages from QGIS:
- Open the Properties of your OSM Street layer and go to the Actions tab
- Press Add
- Define a Python Action
- 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 %]")
- Choose the Action from the Toolbar and click in on the Roadlayer
- Open the message log
- 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...
-
1this is really a smart solution!2021年09月11日 16:51:22 +00:00Commented 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?Dave– Dave2021年09月12日 10:06:43 +00:00Commented Sep 12, 2021 at 10:06
-
@Dave: I edited my answer above.eurojam– eurojam2021年09月12日 15:50:35 +00:00Commented Sep 12, 2021 at 15:50
Explore related questions
See similar questions with these tags.