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
    Commented Sep 19, 2019 at 16:31
  • I know how to convert polygons into lines. But not how to exclude the ocean/nothing edges.
    – Tom
    Commented Sep 19, 2019 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
    Commented Sep 19, 2019 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
    Commented Sep 19, 2019 at 16:54
  • Create or acquire a polygon of the ocean. Then use the Difference tool as suggested by Taras.
    – csk
    Commented Sep 20, 2019 at 16:25

2 Answers 2


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


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


Keep on mind that this object is a MULTILINESTRING.


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

  • 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
    Commented Sep 23, 2019 at 8:32

If you have no ocean polygons, the following should still work if the country polygons are perfect (no gaps).

  1. Dissolve the countries to create "land"

  2. Convert the country polygons to lines

  3. Keep only intersections with "land"

In case you have issues with gaps between countries, add a tiny positive buffer to the "land" layer before intersecting it. If, conversely, you would still be picking up the shoreline borders after intersecting, do a small negative buffer of the "land" layer.

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.