Opened 10 years ago

Closed 10 years ago

#2742 closed task (worksforme)

Rounding bug using ST_GeomFromGeojson()

Reported by: jakeorr Owned by: pramsey
Priority: medium Milestone: PostGIS 2.1.4
Component: postgis Version: 2.1.x
Keywords: Cc:

Description

Let's say I have the following geographical point represented in GeoJSON:

{"type":"Point","coordinates":[-109.0,35.292506]}

When I run the following conversion, things work as expected:

    SELECT ST_AsText(ST_GeomFromGeojson('{"type":"Point","coordinates":[-109.0,35.292506]}'));
       st_astext
    -----------------------
     POINT(-109 35.292506)
    (1 row)

The problem occurs if the string passed to ST_GeomFromGeojson() omits the trailing decimal on -109.0:

    SELECT ST_AsText(ST_GeomFromGeojson('{"type":"Point","coordinates":[-109,35.292506]}'));
       st_astext
    ----------------
     POINT(-109 35)
    (1 row)

Notice how in this case rounding to an Integer value occurs on both latitude and longitude. The loss of precision on the latitude value in this case is very significant (32.53 km).

Note: I left out the CRS field for clarify, the problem occurs either way.

The same problem does not occur using the ST_GeomFromText() function. Both numbers are not rounded to Integers if the first looks like an integer.

Here is my postGIS full version: POSTGIS="2.1.0 r11822" GEOS="3.4.2-CAPI-1.8.2 r3921" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.10.1, released 2013/08/26" LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER

Change History (3)

comment:1 by robe, 10 years ago

Milestone: PostGIS 2.1.4

Hmm this is a bit odd. I thought I had tried this on 2.1.3 and got the same problem but maybe I didn't on 2.1.3 windows 64-bit.

On windows 64-bit I get the following:

SELECT postgis_full_version() || ' ' || version();

POSTGIS="2.1.3 r12547" GEOS="3.4.2-CAPI-1.8.2 r3924" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.10.0, released 2013/04/24" LIBXML="2.7.8" LIBJSON="UNKNOWN" RASTER PostgreSQL 9.3.3, compiled by Visual C++ build 1600, 64-bit
  SELECT ST_AsText(ST_GeomFromGeojson('{"type":"Point","coordinates":[-109,35.292506]}'));

POINT(-109 35.292506)

I also tried on 2.1.2 and also seems fine. My 2.2.0dev older dev exhibits the issue but is a very early 2.2.0dev so might have been before the fix was put in.

jakeorr if you can upgrade can you give2.1.2 or 2.1.3 a try. Might be fixed on that.

comment:2 by jakeorr, 10 years ago

Tried this on a machine running 2.1.2 and ST_GeomFromGeojson() works as expected. An upgrade should fix the problem. Thanks!

comment:3 by robe, 10 years ago

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.