Skip to content

Instantly share code, notes, and snippets.

@timbunce
Created November 20, 2013 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timbunce/7560988 to your computer and use it in GitHub Desktop.
Save timbunce/7560988 to your computer and use it in GitHub Desktop.
Postgis GeoJSON silent massive loss of precision with coordinates specified as string values
This works as expected:
corp=> SELECT ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[-48.23456,20.12345]}')) As wkt;
wkt
---------------------------
POINT(-48.23456 20.12345)
but this doesn't:
corp=> SELECT ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":["-48.23456","20.12345"]}')) As wkt;
wkt
---------------
POINT(-48 20)
It seems that when coordinates are provided as strings they are truncated to integers.
Significant and silent data loss!
I'd prefer that it "just work", but I'd much prefer an exception being thrown rather than the current silent data loss.
@kashif
Copy link

kashif commented Dec 1, 2013

hi @timbunce I see the issue is because of this in liblwgeom/lwin_geojson.c

...
  if (iType == json_type_double)
    pt.x = json_object_get_double( poObjCoord );
  else
    pt.x = json_object_get_int( poObjCoord );
...

and the corresponding statement for pt.y and pt.z. I will get it fixed. Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment