[postgis-devel] Fixed precision for ST_Intersection, ST_Union, etc.

Sandro Santilli strk at keybit.net
Tue Mar 15 04:22:09 PDT 2016


On Tue, Mar 15, 2016 at 05:52:10AM -0400, Daniel Baston wrote:

> The cost of the checking is the same as ST_IsValid,

Are you sure ? Do you have numbers to show ?
Had you considered improving GEOS to make it irrelevant if
none of the coordinates were really changed ?
(as that would be your use case).

> Here's a query that I think illustrates the problem:
> 
> -- No preicsion model
> postgres=# SELECT ST_AsText(ST_Intersection('POINT (0 0)', 'POLYGON ((0 0,
> 1 0, 0 1, 1 1, 0 0))'));
> ERROR:  Error performing intersection: TopologyException: Input geom 1 is
> invalid: Self-intersection at or near point 0.5 0.5 at 0.5 0.5
> CONTEXT:  SQL function "st_intersection" statement 1
> 
> -- With precision model, GEOSGeom_setPrecision flags GEOS_PREC_NO_TOPO |
> GEOS_PREC_KEEP_COLLAPSED
> postgres=# SELECT ST_AsText(ST_Intersection('POINT (0 0)', 'POLYGON ((0 0,
> 1 0, 0 1, 1 1, 0 0))', op_precision := 1e-12));
> ERROR:  Error performing intersection: TopologyException: Input geom 1 is
> invalid: Self-intersection at or near point 0.5 0.5 at 0.5 0.5
> 
> -- WIth precision model, no flags to GEOSGeom_setPrecision
> postgres=# SELECT ST_AsText(ST_Intersection('POINT (0 0)', 'POLYGON ((0 0,
> 1 0, 0 1, 1 1, 0 0))', op_precision := 1e-12));
>         st_astext
> --------------------------
>  GEOMETRYCOLLECTION EMPTY

The final result is unexpected, how was the polygon changed ?
Reduction should have not moved any vertex, right ?

I guess I just don't like how the handling is performed by
GEOS. Ideally, it should only fix what was broken by precision
reduction, not what was broken in the input.

Remember the GEOS side of this is recent, so might need to
still be tweaked.

--strk;



More information about the postgis-devel mailing list