Search code examples
csvexportcoordinatesshapefileqgis

What is the way to create/export x,y,z coordinates of roads from a shp file in QGIS?


What is the way to create/export x,y,z coordinates of roads from a shp file in QGIS ?

In my specific case, I have tried with the swiss road network, by taking the following steps:

Step 1

Download

swisstlm3d_2022-03_2056_5728.shp.zip

from https://www.swisstopo.admin.ch/en/geodata/landscape/tlm3d.html

Step 2

In QGIS go to Layer > Add Layer > Add Vector Layer

and adding the following file as Source / Vector Dataset:

swissTLM3D_TLM_STRASSE.shp

Step 3

Once the file is loaded, go to the just added layer , click the right button of the mouse, and then go to

Export > Save Features As

and use the following options:

  • Format: Comma Separated Value (CSV)
  • Geometry: As_XYZ
  • Separator: Comma

Step 4

With Excel open the just created CSV file. It contains the following fields, but not the x,y,z coordinates of the roads endpoints, nor the intermediary points forming the polylines of the roads....

UUID DATUM_AEND DATUM_ERST ERSTELL_J ERSTELL_M REVISION_J REVISION_M GRUND_AEND HERKUNFT HERKUNFT_J HERKUNFT_M OBJEKTART REVISION_Q KUNSTBAUTE WANDERWEGE BEFAHRBARK EROEFFNUNG STUFE RICHTUNGSG STR_NAME_U NAME BELAGSART KREISEL VERKEHRSBE EIGENTUEME VERKEHRSBD STRNAME


Solution

  • Try using the Extract Vertices tool (QGIS Version 3.20.2). This may be called Extract Nodes in previous versions.

    Once you have the output from the nodes, you can use Add Coordinates to Points to get the X, Y, and Z values.

    enter image description here

    The attributes from the original line data will be carried through to the vertices, which means you could join the data back to the original line file although this would be a 1:M join resulting in a lot of rows - one row per vertex.

    Extract the data using the same method as before.