Opened 9 years ago

Closed 7 years ago

#3533 closed defect (wontfix)

Invalid GeoJSON inconsistencies

Reported by: mwtoews Owned by: pramsey
Priority: medium Milestone: PostGIS Fund Me
Component: postgis Version: master
Keywords: Cc:

Description

It seems that non-closed polygons can be created from GeoJSON. No errors are raised from this example:

SELECT ST_IsClosed(g), ST_IsValid(g), ST_IsValidReason(g), ST_AsText(g), g::text
FROM (
  SELECT ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[15,12]],[[50,80]],[[80,10]]]}') AS g
) f;
NOTICE:  IllegalArgumentException: point array must contain 0 or >1 elements

-[ RECORD 1 ]----+-------------------------------------------------------------------------------------------------------------------------------------------
st_isclosed      | t
st_isvalid       | f
st_isvalidreason | IllegalArgumentException: point array must contain 0 or >1 elements                                                                       +
                 |
st_astext        | POLYGON((15 12),(50 80),(80 10))
g                | 010300000003000000010000000000000000002E40000000000000284001000000000000000000494000000000000054400100000000000000000054400000000000002440

Here are a few concerning things:

  1. ST_GeomFromGeoJSON does not raise an error, while SELECT 'POLYGON((15 12),(50 80),(80 10))'::geometry raises an error "geometry requires more points". Note that the GeoJSON Specification says "A LinearRing is closed LineString with 4 or more positions", therefore the example is an invalid GeoJSON.
  2. ST_IsClosed returns true, but I would expect it to be false. The documentation for ST_IsClosed does not mention anything about LinearRing or Polygon geometry types.
  3. The invalid reason raised as a notice and shown with ST_IsValidReason is does not describe the issue at hand. It also has a terminating newline, which is why there are two lines in the output.
  4. Invalid WKT and WKB outputs cannot be used with other software, like JTS or GEOS. Within PostGIS, the WKB can be read without error or notice, but the WKT raises an error (as described in 1.). Perhaps at least a NOTICE should be raised for parsing invalid WKB?

I'm seeing identical behaviour from PostGIS 2.0 to 2.2, so this does not appear to be new behaviour.

Change History (4)

comment:1 by mwtoews, 9 years ago

Oh, I just realized that that LinearRing in both the WKT and GeoGSON consists of points, and not a single LineString. So perhaps the ST_IsClosed behaviour is correct. The message is somewhat revealing, since thee point arrays have length 1.

comment:2 by robe, 7 years ago

Milestone: PostGIS FuturePostGIS Fund Me

Milestone renamed

comment:3 by pramsey, 7 years ago

Enforcing validity on input is a little controversial, and also can screw people over (since we've had this behaviour for a while). This is one of the reasons you can sneak invalid structure in via WKB but not via WKT. Question is whether geojson users, like WKB/shapefile loaders, have a use case that requires storing invalid things from time-to-time. I'd err on the side of "not changing things", since we've had this behaviour for a long time.

comment:4 by pramsey, 7 years ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.