[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:


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?

Mathieu Basille.


~$ whoami
Mathieu Basille, PhD

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314

~$ 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