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.

  • What is your success by so far?
    – Taras
    Sep 19 '19 at 16:31
  • I know how to convert polygons into lines. But not how to exclude the ocean/nothing edges.
    – Tom
    Sep 19 '19 at 16:35
  • 1
    Am I correctly understanding that you want to leave only those parts of borders that do not intersect with the ocean? Why not try some sort of Vector > Geoprocessing Tools > Difference ...?
    – Taras
    Sep 19 '19 at 16:38
  • Nothing intersects, all my polygons are flush with each other. I don't have a polygon where the ocean is, though I could possibly create one if that would help.
    – Tom
    Sep 19 '19 at 16:54
  • Create or acquire a polygon of the ocean. Then use the Difference tool as suggested by Taras.
    – csk
    Sep 20 '19 at 16:25

Let's assume we have the following layers "borders" (line) and "ocean" (polygon), see image below.


With the following geoalgorithm 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


Keep on mind that this object is a MULTILINESTRING.


In case, it should be treated as a simple LINESTRING, please proceed with Vector > Geometry Tools -> Multipart to singleparts. There is a useful subject on this topic, see Convert MultiLineString to LineString using QGIS

  • Note: This also works if the polygons are touching, but not overlapping (e.g. in my use-case, they share a line, exact coordinates identical, I just didn't use topology) and Difference cuts out those shared lines.
    – Tom
    Sep 23 '19 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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