Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#1698 closed task (fixed)

Review polygon collapse policy in ST_Simplify

Reported by: strk Owned by: strk
Priority: medium Milestone: PostGIS 2.0.0
Component: postgis Version: trunk
Keywords: Cc:

Description

Current ST_Simplify transforms collapsed polygons into EMPTY polygons, but that's not necessarely a good idea. The goal being generalizing features, _dropping_ the whole location information from them isn't really useful.

This is really depended on use case so we may define policy parameters. A planar subdivision ends up having "holes" if we drop small components. But a central big body with a lot of satellite islands would not get simplified much if we keep all islands.

Attachments (4)

style-simpNCD2.png (1.4 KB) - added by strk 8 years ago.
at least 3 vertex polys
style-snap-simpNCD.png (1.4 KB) - added by strk 8 years ago.
some 3-vertex, some 1-vertex poly
style-simp.png (1010 bytes) - added by strk 8 years ago.
all collapsed polys dropped
style-simpNCD.png (1.0 KB) - added by strk 8 years ago.
some 3-vertex, some 1-vertex poly

Download all attachments as: .zip

Change History (12)

comment:1 Changed 8 years ago by strk

I've also verified that ST_Simplify may return collapsed components of collections as EMPTY. This means creating collection with some empty and some non-empty elements, which is suboptimal and surely NOT simplified form.... see also #1700 as a consequence of this on further operations.

comment:2 Changed 8 years ago by strk

An example of the above:

$ select st_asewkt(st_simplify('GEOMETRYCOLLECTION(MULTIPOLYGON(((0 0, 1 0, 1 1, 0 1, 0 0)),((20 0, 20 20, 40 20, 40 0, 20 0))),POINT(10 10))', 2));
 GEOMETRYCOLLECTION(MULTIPOLYGON( EMPTY,((20 0,20 20,40 20,40 0,20 0))),POINT(10 10))

By the way, the parser is unable to understand the WKT version of the above. See #1703.

comment:3 Changed 8 years ago by strk

Milestone: PostGIS 2.0.1PostGIS 2.0.0
Owner: changed from pramsey to strk
Status: newassigned

comment:4 Changed 8 years ago by strk

Resolution: fixed
Status: assignedclosed

With r9527 r9528 r9529 this is now retaining collapsed shells (but not holes) and keeping at least 3 vertexes when possible for polygons (thus collapsing a most to line but not to point).

I'm pretty satisfied with the results so far. Would be nice to have a user-defined policy but won't do for 2.0.0 for sure.

comment:5 Changed 8 years ago by pramsey

Why retain 3-point rings? They are by nature self-intersecting and invalid. Drop them too!

comment:6 Changed 8 years ago by strk

Ok, the whole point of ST_Simplify was (as originally developed) to reduce vectors for sending to clients for rendering. True, a 3-points ring is invalid as is the single-point one.

But they can still have an use ! For example you can _see_ something rendered (modulo rendering limitations as in mapnik/AGG case: https://github.com/mapnik/mapnik/issues/1140) and you know _where_ the feature is located (if you want to zoom to it, which may send more vectors, less simplified, etc).

The other thing is that you can always strip non-valids later. We know we may be introducing non-valids so why having 1-class invalids that we drop lightly and 2-class invalids which we don't drop (complex self-intersections).

I've to say that I'm tempted to revert this to really keep a single vertex rather than 3 vertices, but knowing that AGG won't render them makes me belive we're doing a better service returning at least 3 points than 1. For all AGG users (mapserver,mapnik,what else?).

I'm attaching 2 images of mapnik rendering a set of ~8k simplified polygons representing italian municipalities. The version you don't see much is the one with 1-vertex polygons, the other is with 3-vertex polygons. You can see you can recognize the country by only the collapsed versions of polygons rendered.

Changed 8 years ago by strk

Attachment: style-simpNCD2.png added

at least 3 vertex polys

Changed 8 years ago by strk

Attachment: style-snap-simpNCD.png added

some 3-vertex, some 1-vertex poly

Changed 8 years ago by strk

Attachment: style-simp.png added

all collapsed polys dropped

Changed 8 years ago by strk

Attachment: style-simpNCD.png added

some 3-vertex, some 1-vertex poly

comment:7 Changed 8 years ago by strk

Sorry but the polygon boundaries are rendered in white, so you'll need a good reader to see them (it's white on transparent). Se the difference between before and after the patch is between knowing the shape and extent of italy and not knowing it.

Forget style-snap-simpNCD.png which is not directly related.

comment:8 Changed 7 years ago by strk

For the record: this change was reverted due to #1987 -- a more flexible implementation is being discussed in #2093

Note: See TracTickets for help on using tickets.