[postgis-tickets] [PostGIS] #3061: ST_GeomFromGeoJSON strips coordinates
PostGIS
trac at osgeo.org
Fri Feb 27 04:44:53 PST 2015
#3061: ST_GeomFromGeoJSON strips coordinates
---------------------------------+------------------------------------------
Reporter: slaskis | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone:
Component: postgis | Version: 2.1.x
Keywords: geojson, linestring |
---------------------------------+------------------------------------------
I'm storing some geo paths in PostGIS using GeoJSON and the
ST_GeomFromGeoJSON()-function but I just found an issue with it:
{{{
SELECT
ST_NumPoints(ST_GeomFromGeoJSON('{"type":"LineString","coordinates":[[0,0],[1,1],[1,1],[2,2]]}'))
= 4; -- FALSE
SELECT ST_NumPoints(ST_GeomFromText('LINESTRING (0 0,1 1,1 1,2 2)')) = 4;
-- TRUE
}}}
It seems to strip the two 'middle' coordinates because they are the same.
And I can buy that it would do that but it doesn't do it consistently,
like when I use ST_GeomFromText() with the same list of coordinates. It
also does not strip the coordinates when using "type": "MultiPoints"
instead, but it would be the wrong semantics.
It's a problem for me because I need the points to match a sequence of
timestamps as well or data will be lost. And the reason I'm using GeoJSON
is that the app server is written in Javascript so it just seems natural.
I'm running Postgres 9.4.1 and {{{SELECT PostGIS_Full_Version()}}} gives
me:
{{{
POSTGIS="2.1.5 r13152" GEOS="3.4.2-CAPI-1.8.2 r3921" PROJ="Rel. 4.8.0, 6
March 2012" GDAL="GDAL 1.11.1, released 2014/09/24" LIBXML="2.9.1"
LIBJSON="UNKNOWN" RASTER
}}}
I currently workaround this issue by changing the type to MultiPoint and
then converting it to LineString but it seems like a hack to me:
{{{
ST_LineFromMultiPoint(ST_GeomFromGeoJSON('{"type":"MultiPoint","coordinates":[[0,0],[1,1],[1,1],[2,2]]}'))
}}}
Originally posted to http://gis.stackexchange.com/questions/136629/st-
geomfromgeojson-strips-coordinates-is-it-a-bug/136966#136966
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/3061>
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