[postgis-tickets] [PostGIS] #4831: Incorrect precision of ST_AsGeoJSON output in PostGIS 2.x and 3.0
PostGIS
trac at osgeo.org
Tue Jan 12 08:21:51 PST 2021
#4831: Incorrect precision of ST_AsGeoJSON output in PostGIS 2.x and 3.0
---------------------+---------------------------
Reporter: Ariki | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone: PostGIS 3.0.4
Component: postgis | Version: 3.0.x
Keywords: |
---------------------+---------------------------
I use PostGIS 3.0.3 on Linux x64, GEOS 3.8.1. Also tried with PostGIS 2.5
docker image, which is also affected.
PostGIS 3.1 doesn't have this bug.
SQL query:
{{{
select
maxdecimaldigits,
ST_AsGeoJSON(
ST_Point(123456789.123456, 123459.123456789),
maxdecimaldigits,
0
)
from generate_series(0, 16) maxdecimaldigits;
}}}
Output (CSV):
{{{
0 "{""type"":""Point"",""coordinates"":[123456789,123459]}"
1 "{""type"":""Point"",""coordinates"":[123456789.1,123459.1]}"
2 "{""type"":""Point"",""coordinates"":[123456789.12,123459.12]}"
3 "{""type"":""Point"",""coordinates"":[123456789.123,123459.123]}"
4
"{""type"":""Point"",""coordinates"":[123456789.1235,123459.1235]}"
5
"{""type"":""Point"",""coordinates"":[123456789.12346,123459.12346]}"
6
"{""type"":""Point"",""coordinates"":[123456789.123456,123459.123457]}"
7
"{""type"":""Point"",""coordinates"":[123456789.123456,123459.1234568]}"
8
"{""type"":""Point"",""coordinates"":[123456789.123456,123459.12345679]}"
9
"{""type"":""Point"",""coordinates"":[123456789,123459.123456789]}"
10 "{""type"":""Point"",""coordinates"":[123456789.1,123459.1235]}"
11 "{""type"":""Point"",""coordinates"":[123456789.12,123459.12346]}"
12
"{""type"":""Point"",""coordinates"":[123456789.123,123459.123457]}"
13
"{""type"":""Point"",""coordinates"":[123456789.1235,123459.1234568]}"
14
"{""type"":""Point"",""coordinates"":[123456789.12346,123459.12345679]}"
15
"{""type"":""Point"",""coordinates"":[123456789.123456,123459.123456789]}"
16
"{""type"":""Point"",""coordinates"":[123456789.123456,123459.123456789]}"
}}}
Notice that in some cases the number of decimal places in the output is
not what you can expect. In guess, it depends on length of the integer
part of the number. So when the geometry is in degrees, the bug is harder
to notice, but it still exists.
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4831>
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-tickets
mailing list