[postgis-users] Confused about st_snaptogrid and precision.

Paul moen pmoen at offroadsoftware.com
Tue Mar 23 07:37:59 PDT 2010


On Mar 23, 2010, at 7:10 AM, strk wrote:

> On Tue, Mar 23, 2010 at 01:05:52PM +0100, strk wrote:
>> On Tue, Mar 23, 2010 at 06:57:41AM -0500, Paul Moen wrote:
>>
>>> UPDATE the_control SET the_geom=st_snaptogrid(the_geom,.0000001);
>>>
>>> After setting the precision, shouldn't I be able to find the  
>>> point, POINT(1881581.0894989 638200.5564884), at that precision,  
>>> in the table by using
>>>
>>> SELECT * FROM the_control WHERE  
>>> st_equals(st_geomfromewkt('POINT(1881581.0894989  
>>> 638200.5564884)'),the_geom);
>>
>> You are NOT snapping the return from st_geomfromewkt.
>>
>> Try this:
>>  SELECT * FROM the_control WHERE st_equals(
>>  st_snaptogrid(st_geomfromewkt('POINT(1881581.08949
>>  89 638200.5564884)', .0000001)),the_geom);


Bottom line, when I store a geometry using  
st_geomFromEWKT('POINT(1881581.089489 638200.5564884)'), is is not  
actually storing a geometry with an X of 1881581.089489 and a Y of  
638200.5564884.  It is storing a geometry with an X =  some number  
that rounds to 1881581.089489 and a Y =  some number that rounds to  
638200.5564884.

> Also, note that if the geometries you're comparing do not
> have the same structure (number of points in the same place)
> snapping to the grid may have the unexpected result of making
> them different than they were.
>
> This is because snapToGrid doesn't add new vertices, but only
> snaps the existing ones.
>

> --strk;
>
>  ()   Free GIS & Flash consultant/developer
>  /\   http://strk.keybit.net/services.html
> _______________________________________________
> 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