7

I'm looking for the QGIS equivalent of TopoJSON's mesh function which goes through a vector layer and only keeps borders that are shared between multiple features. Here's an example of the output -- the black lines are only drawn for internal borders between states:

enter image description here

Is there a way of achieving this in QGIS, without going through TopoJSON? The reason I'm asking is that I'm working with extremely detailed shapefiles and would like to avoid converting from SHP to TopoJSON and back to SHP if possible.

The shapefiles I'm using are topologically correct, ie the arcs of the features line up perfectly.

2
  • Do you need this for further processing, or only for visualization purposes?
    – Erik
    Commented Feb 3, 2020 at 10:49
  • Mostly for rendering/viz purposes, so if this is just a matter of using the right style settings that'd do it
    – zinfandel
    Commented Feb 3, 2020 at 10:54

5 Answers 5

5

QGIS should be bundled with the SAGA's "Shared Polygon Edges" module which does exactly what you want:

pink the original polygons, black the internal borders.

pink the original polygons, black the internal borders

2

You need the difference between the outer lines and all the lines.

  1. Get all the polygon segments as lines with Vector > Geometry Tools > Polygons to Lines.
  2. Get the external polygon borders with Vector > Geoprocessing Tools > Dissolve. Convert to lines with Vector > Geometry Tools > Polygons to Lines.
  3. Find line segments which are not external by finding the difference between Step 2 and Step 1 (Vector > Geoprocessing Tools > Difference).
1

If you can't find a way to do that with QGIS you can use OpenJUMP. For perfect result the common boundaries must match exactly and have vertices at the same locations but that should be fine for you.

enter image description here

The tool is named "Extract common boundrary between Polygons" but the name is partly misleading because actually also non-common boundaries are extracted as we will see.

enter image description here

The result is a new line layer where each line is categorized as shared or nonshared.

enter image description here

Select the shared ones and you have your result. You can save the result as JUMP JML, shapefile, or GeoJSON. QGIS can read all those formats.

1

You can create a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer....

The query joins the layer to itself if their boundaries touch (they are adjacent), then intersects the polygon to produce the boundary line.

Add all the columns you want to keep to the second line (I keep fid and NAME), and change world to the name of your layer:

SELECT  row_number() over() AS id,
        a.fid, a.NAME, 
        st_intersection(a.geometry, b.geometry) as geometry
FROM world AS a
JOIN world AS b
ON st_touches(a.geometry, b.geometry)
WHERE Dimension(st_intersection(a.geometry, b.geometry))=1

enter image description here

The virtual layer is probably going to be slow. Right-click and Export it to the file and use the exported layer.

0
0

Let's assume there is a vector layer of the whole world, see the image below.

input

Step 1. Install the "QGIS Resource Sharing" plugin. ⚠️ Keep in mind, that it is an experimental plugin

step1

Step 2. Open the plugin via its logo, find the "Polygon Tools", and install this tool. Afterwards, two models will be added to the Processing Toolbox (Ctrl+Alt+T)

step2

Step 3. Apply the "Borders" model with a desired input layer

step3

and get the output like this

output

There are two polyline layers will be created i.e. 'internal borders' and 'external borders'. The first one is the required one


Resources:

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.