Opened 7 years ago

Closed 7 years ago

#3061 closed defect (fixed)

ST_GeomFromGeoJSON strips coordinates

Reported by: slaskis Owned by: pramsey
Priority: medium Milestone: PostGIS 2.1.6
Component: postgis Version: 2.1.x
Keywords: geojson, linestring Cc:


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:


Originally posted to

Change History (6)

comment:1 by pramsey, 7 years ago

Yes, the geojson input code is definitely throwing away duplicate points,

the point append call is asking for duplicate removal. I wonder how this compares to other inputs…

comment:2 by pramsey, 7 years ago

Milestone: PostGIS 2.1.6
  • WKT input preserves duplicate points
  • WKB input preserves duplicate points
  • GML input strips duplicate points
  • KML input strips duplicate points
  • GeoJSON input strips duplicate points

So… what to do?

comment:3 by strk, 7 years ago

My vote goes for NOT removing duplicates on input. The ST_RemoveRepeatedPoints exists since 2.0.0 for those who want to clean up the data.

comment:4 by robe, 7 years ago

same here. If specs don't say what to do, DO NOT remove duplicates on input.

comment:5 by pramsey, 7 years ago

OK, since also the specs don't say anything about dupes

  • GML doesn't
  • KML doesn't
  • GeoJSON doesn't

I will patch 2.1 and trunk

comment:6 by pramsey, 7 years ago

Resolution: fixed
Status: newclosed

Fixed in 2.1 at r13339, in trunk at r13340

Note: See TracTickets for help on using tickets.