I have a polygon layer containing habitat types. It looks something like this: enter image description here where dark green is forest, yellow are open lands and the other signatures different other habitat types. In order to get something like a forest edge-line, I'd like to create a line shapefile representing those linear structures where forest and open land touch each other. I could of course use the polygons to lines tool in QGIS and then select the forest edge lines by hand - however, my data are too large for this procedure.

Any suggestions on how to approach this problem in QGIS or R? Please note that - unfortunately - I am not familiar with python at all.

  • Would it suffice to dissolve the internal boundaries where the code is the same on both sides, leaving you with polygon features? st_union from the sf package?
    – Spacedman
    Nov 22, 2017 at 21:38
  • Dissolve as a first step is a very good idea. I tried in QGIS with promising results. I wonder whether there is a QGIS-option to create the forest edge lines.
    – yenats
    Nov 22, 2017 at 23:49

1 Answer 1


In the end, I followed this workflow:

first step:

  • dissolve original polygons using fields
  • polygons to lines on the resulting layer
  • delete all non-forest lines

enter image description here

second step in order to delete the outlines where the original layer extend ends:

  • dissolve original polygons without using fields
  • tiny negative buffer on the resulting layer
  • clip lines layer with buffer layer

The result looks like this:

enter image description here

  • Nice, you did this in Q? Can you share the data or a similar example, it'd be interesting to get the R code for this.
    – mdsumner
    Nov 29, 2017 at 20:28
  • Yes, this was done in QGIS. You could use any set of overlaying polygon layers, I suppose.
    – yenats
    Dec 1, 2017 at 8:46

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.