1

Is there an algorithm or technique that allow me to decrease the number of vertices of a polygon while maintaining it at some acceptable aspect?

The problem: I have a functionality in my system (that uses PostGIS) that tests which polygons a given point is inside. Occurs that I have dozens of polygons that goes from 20 to thousands of vertices and this test is taking too long to run. One possible solution would be to decrease the number of vertices to a given maximum (let's say 100) while maintaining the format and removing the details.

  • 1
    it could be worth to post the actual queries you run to check for performance issues, including the EXPLAIN ANALYZE output, since 'dozens' usually shouldn't be a major time factor. are your tables indexed properly? note that, for point-in-polygon, order of the arguments to any spatial relation function might matter. – ThingumaBob Aug 21 '18 at 8:36
  • ST_Subdivide is often used to improve query performance in these cases. – dbaston Aug 21 '18 at 12:02
3

ST_SimplifyPreserveTopology — Returns a "simplified" version of the given geometry using the Douglas-Peucker algorithm. Will avoid creating derived geometries (polygons in particular) that are invalid.

geometry ST_SimplifyPreserveTopology(geometry geomA, float tolerance);

It returns a "simplified" version of the given geometry using the Douglas-Peucker algorithm. Will avoid creating derived geometries (polygons in particular) that are invalid. Will actually do something only with (multi)lines and (multi)polygons but you can safely call it with any kind of geometry. Since simplification occurs on a object-by-object basis you can also feed a GeometryCollection to this function.

  • 3
    you might want to add ST_SimplifyPreserveTopology to your answer. and a link to the citated doc page maybe. – ThingumaBob Aug 21 '18 at 8:28
  • this doc contains interesting graphics comparing st_simplify and ST_SimplifyPreserveTopology – JGH Sep 5 '18 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.