I've got the following vector Shapefiles (not .shp format but some .xml formats):
.gml-File of Linz, .xsd-File of Linz

They represent the areas of the statistcal districts of Linz, Austria. I want to them into line segements, where each line segment expands from one intersection to the next intersection of a the district's boundary nodes. These line segments finally should be exported into a .shp or even better into a .gpx File (QGIS-lines should be tracks and trackpoints within the .gpx).
The reason is, I want to import this .gpx into JOSM, an editor for OpenStreetMap, to use them for creating and improving boundaries (in this example the districts of Linz). Therefor the lines have to be split from intersection to intersection as I explained above.

Now to my question: How to do this mostly automatically using QGIS? I already found out how to do it with several manual steps. But that's not very comfortable if the number of source polygons is much higher compared to the 16 of Linz.

My steps are:

  1. Add Vector Layer, choose .gml file
  2. Vector > Geometry tools > polygons to lines
  3. Toolbox > Grass > v.clean: "bpol"-tool
  4. now most of the line-segements are created but still there are some individual lines, sharing the same start/end-vertex which should belong to to the same segement, for example the node on the bottom right (see Screenshot 2)
  5. manual selection of 2 lines, Toggle Editing, Merge Selected Features
  6. click on vector name, Save as..., .GPX, next dialog: Layer name= "tracks" (to create a GPX-track with trackpoints instead of single waypoints or Routepoints)


The lines should be split at each corner (= where the line contacts with at least 2 other line segments). And there shouldn't be overlappping duplicate line segements above each other in the resulat, the duplicates should be removed.

result look like this

  • 3 Screenshots 1. Source file areas 2. after v.clean: still some unwanted line ends, f.e the very right one. 3. Final result. Line segements from intersection to intersection Commented Jun 16, 2017 at 14:39

1 Answer 1


I don't know if I have understood what you are looking for, but there is the Line-polygon intersection SAGA tool that should do the job.

The following is a workflow which you could simply implement in a model or in a PyQGIS script:

  1. convert the polygon to lines with the Polygons to lines tool;
  2. run the Line-polygon intersection SAGA tool setting keep original line attributes as parameter;
  3. run the Dissolve tool (uncheck the Dissolve all (do not use fields) parameter and move the Stb field in the Selected box).

You will obtain this result (16 line features):

enter image description here

I styled it with a different color for each feature (you can't see some lines because they overlap, but they exist).

  • I folllowed you instructions, but couldn't reproduce your result. Already after step 2. the created "intersection" layer looks quite wrong (broken lines,...). I opened the original polygon layer and run tool of step 1. then I opened too of step 2 (with polygon layer and the created line layer of step 1 as parameters). When running tool I get another line layer with chopped, broken lines as resalt. May I ask you to tell me exactely which inputs I should use for tool 2? Commented Jun 23, 2017 at 12:46
  • @wernerschka In the first step you must to use the original layer. In the step 2, the output from the step 1 as lines and the original layer as Polygons; in the last step, you must to use the output from step 2. I just reproduced my workflow and it returns what I described in my answer.
    – mgri
    Commented Jun 23, 2017 at 13:11
  • I tried it again exactly using your tools (for step 1 I used SAGA "convert polygons to lines". 2 days I ago I used QGIS "polygones to lines". But both leading to identical results after step 2. Please take a look at the following screenshot. (Btw: how to add an image into a comment? Or is it just possible to add links to an image but not the image itself?) i.sstatic.net/nDUld.png Commented Jun 24, 2017 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.