[postgis-users] Tolerance on ST_Union?

Mathieu Basille basille at ase-research.org
Sat Dec 15 20:39:05 PST 2012


Hi list,

I've been struggling around with ST_Union, which gave me a headache for a 
while. My example is quite simple: I have envelopes of 2 raster tiles 
(hence supposedly aligned), which I want to union using ST_Union. Here is 
what I'm able to do:

CREATE TABLE twotiles AS
SELECT
'0103000020E6100000010000000500000062105839B44854C06E3D0AD7A380394062105839B44854C06466666666563A4025068195431354C06466666666563A4025068195431354C06E3D0AD7A380394062105839B44854C06E3D0AD7A3803940'::geometry
UNION
SELECT 
'0103000020E6100000010000000500000024068195431354C06E3D0AD7A380394024068195431354C06466666666563A40E7FBA9F1D2DD53C06466666666563A40E7FBA9F1D2DD53C06E3D0AD7A380394024068195431354C06E3D0AD7A3803940'::geometry;

This creates the two envelopes with the exact geometries given by 
ST_Envelope. The expected result after ST_Union should have only 1 line 
(one polygon), but it's not the case:

SELECT ST_Dump(ST_Union(geometry)) AS geom FROM twotiles;

returns 2 lines. As a matter of fact, if you can zoom enough on the two 
polygons, there is a tiny difference between them, of about 
0.00000000000001 m, which is enough for ST_Union to not union the two 
polygons... With the help of Pierre Racine, I was able to solve this 
problem using ST_SnapToGrid with a very fine resolution (so that it doesn't 
really affect the output), but I wonder whether there shouldn't be a 
parameter of tolerance in ST_Union to make this more transparent and 
flexible to the user?

Sincerely,
Mathieu Basille.


-- 

~$ whoami
Mathieu Basille, PhD

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314
http://ase-research.org/basille

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard


More information about the postgis-users mailing list