I have an automated system in QGIS that separates loops from GPX traces and works out their centroid using 'Polygonize' >> 'Keep N biggest parts' >> 'Centroids'.

However, quite often it includes part of the 'loop approach' in the polygon:

GPX trace


This distorts the centroid calculation.

I think there might be a way to use a line buffer to separate the loop from the GPX trace. I don't care about preserving the GPX data but I want to avoid 'dangles'.

I can use a buffer to make a polygon around the GPX trace: Buffered line

But I cannot work out how to make the area inside the 'buffer polygon' (shown in yellow) into a separate polygon that I can use to calculate the centroid.

Inner polygon

It is essential that the process can be automated. I have hundreds of files that need to be processed.

Negative buffers don't help:

enter image description here

They change the buffer but don't make a polygon from the area surrounded by the buffered line.

But maybe I am missing something.

here is the GPX trace for the simple square so you can test it:

<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="Open GPX Tracker for iOS">
            <trkpt lat="100.000" lon="100.000">
            <trkpt lat="100.000" lon="200.000">

            <trkpt lat="200.000" lon="200.000">

            <trkpt lat="200.000" lon="100.000">

            <trkpt lat="100.000" lon="100.000">
  • 1
    gis.stackexchange.com/q/366701/120129...check this link, maybe it will fit... Commented Oct 16, 2020 at 11:20
  • 2
    Agreed, just negative buffer that polygon, rather than buffering the line.
    – jcarlson
    Commented Oct 16, 2020 at 12:24
  • I'm not sure I understand what you mean. First I buffer the GPX trace with +0.0001° (in this case) to make the 'buffer polygon' and then buffer the 'buffer polygon' with -00001° to make the 'loop polygon'?
    – Peqi
    Commented Oct 16, 2020 at 13:35
  • Play negative values upwards so that they tighten the hole, for example: - 0.1 ° и т.д.... Commented Oct 16, 2020 at 18:48
  • Don't forget that I start with a line. The first buffer puffs up the line to make a new polygon (the buffer polygon). When I apply a negative buffer to this 'buffer polygon' it makes a smaller buffer - around the same line. I can't see how it will help me make a polygon out of the area defined by the loop. The area I am interested in is outside the buffer.
    – Peqi
    Commented Oct 16, 2020 at 20:53

1 Answer 1

  1. 'Polygonize' the line first
  2. 'Negative buffer' this polygonized layer enter image description here enter image description here enter image description here

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.