6

I am aware you are able to simplify polygons in QGIS based on distance tolerance but my questions is, is there a way to simplify based on a set maximum number of desired points?

For example, if the number 1000 was entered, the polygon would be trimmed to 1000 points regardless of any distance thresholds. Does anyone know of any ways to do this?

Taras
  • 32,823
  • 4
  • 66
  • 137
Brandon Schmidt
  • 169
  • 1
  • 2
  • 13

2 Answers2

3

Along the boundary of the polygon, create points in a regular interval (1/1000 of the boundary's total length) and connect these points to line / convert to polygon:

  1. Run "Points along geometry" and for Distance, use data driven override with the expression:

    length(boundary($geometry))/1000
    
  2. Run "Points to Path" to connect the points to a line.

  3. Run "Lines to polygons" to convert the lines to a polygon.

Blue: initial polygon, red: simplified polygon: enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Babel
  • 71,072
  • 14
  • 78
  • 208
1

You can use the following QGIS expression to create a simplified polygon with a freely definable number of vertices (here: 20; change this value at the end of line 7). Use the expression with "Geometry generator" or "Geometry by expression" (see here for details):

make_polygon(
    make_line(
        array_foreach(
            generate_series(
                0, 
                length(boundary($geometry)),
                length(boundary($geometry))/20 --change this value
            ),
            line_interpolate_point(boundary($geometry), @element)
        )
    )
)

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Babel
  • 71,072
  • 14
  • 78
  • 208
  • 1
    And a solution #3 from you to be on fire – Taras Jan 10 '22 at 16:42
  • I think two solutions are enough for a question asked almost 8 years before... ;-) - in mean, that makes one answer per 4 years. So maybe in 2026, someone will add an answer involving virtual layers...? – Babel Jan 10 '22 at 16:44