Opened 4 years ago
Closed 4 years ago
#4831 closed defect (wontfix)
Incorrect precision of ST_AsGeoJSON output in PostGIS 2.x and 3.0
Reported by: | Ariki | Owned by: | pramsey |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS 3.0.4 |
Component: | postgis | Version: | 3.0.x |
Keywords: | Cc: |
Description
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.
Note:
See TracTickets
for help on using tickets.
Yes, there is a bug in all stable releases before 3.1 but backporting the format improvements done there would be a total nightmare.
Unless somebody wants to provide a minimal patch that fixes this in older releases, I'm afraid that updating to 3.1 is the way to go.