[postgis-users] bug in st_difference() ?

Ralf Suhr Ralf.Suhr at itc-halle.de
Wed Mar 9 07:04:33 PST 2011


Hi Birgit,

this is only a topoligie Problem. Your secound polygon is computed outside 
PostGIS and numeric precision are lost by import. In this case ST_Difference() 
and other PostGIS function can have results with very small errors.

You can clean the second polygon by move all points to the borders from first. 
3597691.18360053 5323329.04452537 becomes 
3597691.183600531425327 5323329.044525371864438 and so on.

Gr
Ralf

Am Mittwoch 09 März 2011, 15:05:43 schrieb Birgit Laggner:
>   Dear list,
> 
> when I am using ST_Difference(), I often have the problem, that the
> resulting geometries contain vertexes lying outside of the supposed
> geometry extent. My impression is that the function tries to preserve
> vertexes of the input geometries and does not check properly, whether
> the point lies inside the extent of the new geometry or not.
> 
> Here an example:
> 
> select st_astext(st_difference(a_geom, b_geom)) from
> st_geomfromtext('POLYGON((3580359 5328360,3588529 5330935,3597943
> 5323120,3606024 5322587,3612951 5315217,3608155 5306691,3603804
> 5305093,3596166 5306159,3591105 5310244,3584799 5310688,3576540
> 5317437,3580359 5328360))',31467) as a_geom,
> st_geomfromtext('POLYGON((3597691.18360053 5323329.04452537,3597943
> 5323120,3606024 5322587,3611561.81746298 5316695.02444028,3611480
> 5316582,3605931 5322425,3597573 5323069,3597691.18360053
> 5323329.04452537))',31467) as b_geom;
> 
> results in:
> "POLYGON((3580359 5328360,3588529 5330935,3597943
> 5323120,3597691.18360053 5323329.04452537,3597573 5323069,3605931
> 5322425,3611480 5316582,3611561.81746298 5316695.02444028,3606024
> 5322587,3612951 5315217,3608155 5306691,3603804 5305093,3596166
> 5306159,3591105 5310244,3584799 5310688,3576540 5317437,3580359 5328360))"
> 
> Vertexes 4 (3597691.18360053 5323329.04452537) and 8 (3611561.81746298
> 5316695.02444028) are out of the supposed geometry extent.
> 
> I am using PostGIS 1.5.2 with GEOS 3.2.2 on a 8.4.5 PostgreSQL-DB on
> 64-bit SUSE Linux.
> 
> Maybe, there is a simple explanation, why this behavior might be wanted
> - if not, I would like to complain this as a bug (or at least suggest an
> improvement of the function in future versions)...
> 
> Regards,
> 
> Birgit.
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list