[GIS] Splitting area polygons into line segments in QGIS for using to edit OpenStreetMap

administrative-boundariesopenstreetmapqgisshapefile

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)

Edit:

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

Best Answer

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).