3

I have a topographic layer for a country. I want to select topographic lines of a certain altitude and transform the lines to polygons. All work fine except one thing: since the lines of the topographic map are not properly closed, the polygon are awful looking. See the image below. enter image description here

As you can see, since the "topographic lines" are not joining the Country borders, it creates polygons that are closed from the perspective of the lines and not the country border. The blue line that I drew is the resulting polygon that I'd be looking for. So is there a way to tell QGIS to first close the topographic line to the border (small red line) and then to apply the line to polygon algorithm? Obviously, the small polygon would have the same treatment, but the image would be too cluttered if I drew another polygon to show what I'm looking for.

1

1 Answer 1

2

There are four simple steps that you can perform at once using the expression from below with Geometry generator or Geomtry by expression (see how here). In brackets you see on which line of the expression this task is performed:

  1. Extend the line (lines 4 to 8) so that it continues well over the boundary of the polygon. Change the length the line is extended (200 in my case).

  2. Close the line (connect the two dangles, line 3/9).

  3. Convert this line to a polygon (line 2/10)

  4. Intersect the resulting polygon with the original polygon (country, lines 11 to 16). Replace 'polygon' in line 13 with the name of your (original, country) polygon layer.

Be aware: the function overlay_within() is available since QGIS 3.16.

The expression to use:

intersection ( 
    make_polygon( 
        close_line( 
            extend(
                $geometry, 
                200, 
                200
            )
        )
    ),
    array_first (
        overlay_within( 
            'polygon',
            $geometry
        )
    )
)

Screenshot: yellow polygon-layer named polygon and line-layer in red. On this line-layer, apply the expression from above that creates the blue polygons:

enter image description here

2
  • 1
    Beautiful! I had to change the "200" for "2" in order to see it. Since it was just a test, I didn't look for a proper scale or coordinates. But this is exactly what I'm going to be using for the topographic lines! Thanks! Commented May 17, 2021 at 21:08
  • 1
    Indeed, some values have to be changed. Geometry generator is great that you can interactively adapt settings and see the effect immediately.
    – Babel
    Commented May 17, 2021 at 21:12

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.