[postgis-devel] [PostGIS] #1292: ST_SnapToGrid returns a value out of range
PostGIS
trac at osgeo.org
Mon Jan 30 13:35:28 PST 2012
#1292: ST_SnapToGrid returns a value out of range
---------------------------+------------------------------------------------
Reporter: realityexists | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone: PostGIS 2.0.0
Component: postgis | Version: trunk
Keywords: |
---------------------------+------------------------------------------------
Comment(by pramsey):
OK, so this is tricky. Ignore the text for the moment. SnapToGrid builds a
virtual grid out from the origin and then snaps your coordinates to it.
The net result is things move, for example
{{{postgis20=# SELECT
sT_astext(ST_SnapToGrid(ST_Transform(ST_GeomFromText('POINT(179.8 50)',
4269), 4326), 0.00007)::geography);
st_astext
---------------------------
POINT(179.79997 50.00002)
}}}
Now, when you print out doubles, you only see a small portion of their
total precision. The fact is that snapping even to 0.00001 is perturbing
the coordinates slightly. And sometimes slightly positively. Now you might
say "0.00001 fits evening into 180" and you'd be right, but that's in base
10, and the computer is working in base 2. So the grid formed by 0.00001
might actually snap 180 to something slightly larger than 180. This is
legal and correct.
The question is what to do about it. One possibility would be to provide a
function to wrap the coordinates to the geodetic bounds. This would have
the effect of translating your perturbed points from 180plusabit to
-180plusabit. But once you got into geographics it would all be the same,
effectively.
I don't think we want the cast to do the wrap automatically (at least,
people have told me that would be bad). Although I'm increasingly unsure
of that.
--
Ticket URL: <http://trac.osgeo.org/postgis/ticket/1292#comment:3>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-devel
mailing list