3

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.

My question is this: Am I missing something regarding the GeoJSON conversion function, or is this really unexpected behaviour? If it is a bug, where should I report it? Thanks!

  • I think it's a bug. Please add to our ticket tracker instructions here: postgis.net/support Thanks, Regina – LR1234567 May 17 '14 at 5:18
1

jakeorr,

I saw the ticket you put in. I thought I had tried on 2.1.3 and 2.1.2 but I guess not and I was trying on an early 2.2.0dev. Anryate I'm not seeing the issue 2.1.2 or 2.1.3. Try upgrading to one of those and see if the problem goes away.

Regina.

  • I tried this on another one of our installs using 2.1.2 and the problem does not occur. I will see about updating the problem machine. Thanks for your help! – jakeorr May 19 '14 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.