[postgis-users] St_snaptogrid doesn't seem to snap all the time.

rmrodriguez at carto.com rmrodriguez at carto.com
Mon Sep 14 08:39:41 PDT 2020


Hi,

your issue is not with ST_SnapToGrid but with floating point precision.
There is no floating point number that represents 44.0588 exactly, instead
it might be represented by the binary 0x40460786c226809e, which, when
transformed into text, returns the exact result 44.058800000000005.

If you want a max number of digits in your output, you should consider
using ST_AsText(geometry, precision), in your case using a precision of 4.
That does enforce a maximum number of decimal digits on the output.

On Mon, Sep 14, 2020 at 5:25 PM Alexandre Neto <senhor.neto at gmail.com>
wrote:

> Hi,
>
> I am using st_snaptogrid to reduce the number of relevant decimals places
> in a linetringZ geometry.
>
> I am using variant 4, where I give also an origin geometry, which was set
> to 0,0,0,0
>
> SELECT st_snaptogrid(geometria, st_makepoint(0,0,0,0), 0.0001, 0.0001,
> 0.0001, 0) as geom
> FROM seg_via_rodov
>
> Here's an example:
>
> SELECT st_astext(geometria)
> from seg_via_rodov
> LIMIT 1
>
> st_astext
>
>
>                              |
>
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
> LINESTRING Z (-30237.8998031556 267117.061188696
> 44.1488024536882,-30236.3648673971 267121.174528336
> 44.1488024536882,-30234.8299319437 267125.287868282
> 44.1488024536882,-30233.1869835505 267129.149672231
> 44.1233890804773,-30231.2234287545 267132.86408063|
>
>
> SELECT st_snaptogrid(geometria, st_makepoint(0,0,0,0), 0.0001, 0.0001,
> 0.0001, 0) as geom
> FROM seg_via_rodov
> LIMIT 1
>
> geom
>
>
>                             |
>
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
> LINESTRING(-30237.899800000003 267117.0612 44.1488,-30236.3649 267121.1745
> 44.1488,-30234.8299 267125.2879 44.1488,-30233.187 267129.1497
> 44.123400000000004,-30231.223400000003 267132.8641
> 44.058800000000005,-30228.5936 267137.1744 43.9301,-30225.93810000|
>
>
> I found this old bug report, but I wonder if there's a workaround for it.
>
> https://trac.osgeo.org/postgis/ticket/3929
>
> Thanks,
>
> Alexandre Neto
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users



-- 
Raúl Marín Rodríguez
carto.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20200914/25320ee5/attachment.html>


More information about the postgis-users mailing list