[postgis-users] snapToGrid strange behaviour

Michael Fuhr mike at fuhr.org
Fri Jan 27 14:09:40 PST 2006


On Fri, Jan 27, 2006 at 11:04:06AM -0800, Kevin Neufeld wrote:
> Hmmm. That's interesting. Thanx for your input Michael. For some reason, 
> I assumed the snapToGrid(...) function simply rounded off geometry 
> points at a specified precision by using a simple "floor(point / 
> precision + 0.5) * precision" algorithm. Unfortunately, this means for 
> me that I can't rely on spatial queries performed on snapped geometries, 
> ie. touching geometries snapped to 0.001 may actually be 0.00000001 
> apart and consequently, not spatially touching. I'll have to investigate 
> this further.

The difference is likely to be much smaller than 0.00000001; as I
mentioned, it'll probably be smaller than a double's stated accuracy
of about 15 decimal digits.  Here's another query from the example
in my last post:

test=> SELECT d4, d5, d4 = d5, d5 - d4 FROM foo;
  d4   |  d5   | ?column? |       ?column?       
-------+-------+----------+----------------------
 0.001 | 0.001 | f        | 8.67361737988404e-19
(1 row)

I was thinking about raising the issue of tolerances in comparisons,
as Martin did.  Programmers who work with floating point have learned
to do things like "if (fabs(x - y) < tolerance)" instead of testing
for equality; it might be convenient if geometry functions that test
for equality had a way to specify a tolerance.

-- 
Michael Fuhr



More information about the postgis-users mailing list