[postgis-tickets] [PostGIS] #3533: Invalid GeoJSON inconsistencies

PostGIS trac at osgeo.org
Mon Apr 25 16:44:55 PDT 2016


#3533: Invalid GeoJSON inconsistencies
---------------------+----------------------------
 Reporter:  mwtoews  |      Owner:  pramsey
     Type:  defect   |     Status:  new
 Priority:  medium   |  Milestone:  PostGIS Future
Component:  postgis  |    Version:  trunk
 Keywords:           |
---------------------+----------------------------
 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 [http://geojson.org/geojson-spec.html 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.

--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/3533>
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