Opened 7 years ago

Closed 7 years ago

#3690 closed defect (worksforme)

ST_AsGeoJSON can produce invalid geometry collections

Reported by: jyutzler Owned by: pramsey
Priority: medium Milestone: PostGIS 2.4.0
Component: postgis Version: 2.3.x
Keywords: Cc:

Description

After a slew of geometric operations, I ended up with an empty geometry collection. This was output as

"geometry":{  
            "type":"GeometryCollection",
            "geometries":null
         }

which is invalid. The "geometries" member must be the empty array [], not null.

https://tools.ietf.org/html/rfc7946#section-3.1.8

If you need I can try to reproduce this, but the scenario was complicated and it might not be easy to do.

Change History (4)

comment:1 by dbaston, 7 years ago

Describing the slew of operations might be helpful.

comment:2 by robe, 7 years ago

well our processing of empty geometry collections seems okay:

SELECT ST_AsGeoJSON('GEOMETRYCOLLECTION EMPTY'::geometry);

-- yields--
{"type":"GeometryCollection","geometries":[]}

And ingesting the above with null is invalid:

SELECT ST_GeomFromGeoJSON('{"type":"GeometryCollection", "geometries":null}');

-- yields

ERROR:  Unable to find 'geometries' in GeoJSON string

Is the "geometry: part something you are getting back? If getting back I'm assuming that is being tacked on by some post processor you have going and not part of what PostGIS is doing. If so your post processor might also be converting [] to nulls.

comment:3 by robe, 7 years ago

Milestone: PostGIS 2.3.2PostGIS 2.4.0

comment:4 by pramsey, 7 years ago

Resolution: worksforme
Status: newclosed

Since we cannot reproduce I'm going to close out. Post the hexwkb of the offending feature if you happen to be able to re-generate it.

Note: See TracTickets for help on using tickets.