QGIS – Extracting Borders from Country Polygons

linelinestringpolygonqgisqgis-3

I'm trying to convert a polygon GeoJSON of countries into a line layer that contains only the borders. It should not contain the edges of the polygons that border the ocean (in my polygon dataset, nothing).

How can I in QGIS 3.8 do that? Basically, "give me the linestring of this polygon data, but only where there is a polygon on both sides of it".

I've checked similar answers and they don't cover this case. Most importantly, I actually want the data, not just set the display fill style to none.

Best Answer

Let's assume there are two layers 'borders' (line) and 'ocean' (polygon), see image below.

input

With the "Difference" geoalgorithm can be found under Vector > Geoprocessing Tools > Difference, it is possible to delete edges of the polygons that border the ocean.

The output new 'borders' layer will look as following

result

Keep on mind that this object is a MULTILINESTRING.

object

In case, these features should be treated as a simple LINESTRING, please proceed with "Multipart to singleparts" can be found under Vector > Geometry Tools > Multipart to singleparts.

There is a useful subject on this topic, see Convert MultiLineString to LineString using QGIS

Related Question