geojson / schema

JSON Schema for GeoJSON

Home Page:https://www.npmjs.com/package/geojson-schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid Polygons and Points are reported valid

m-mohr opened this issue · comments

Polygons without coordinates and Points with multiple Points are reported as valid, but the spec says it's not.

Examples:

{
  "id": "ABC",
  "type": "Feature",
  "bbox": [-70.275032,-64.72924,-65.087479,-51.105831],
  "geometry": {
    "type": "Polygon",
    "coordinates": [
    ]
  }
}

Building on @m-mohr's example.
This example with a single point with a single coordinate passes validation:

test.json

{
  "id": "ABC",
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": 
        [-122.308150179]
  },
  "properties": {
    "name": "Dinagat Islands"
  }  
}

Python script to test validation using jsonschema library

import jsonschema
import json

# Geojson schema to validate against
with open('geojson.json')as fp:
    geojson = json.load(fp)

# Test geojson to validate
with open('test.json')as fp:
    test = json.load(fp)

jsonschema.validate(test, geojson)

This issue is rather old, but since I'm currently analysing the latest JSON Schema draft, and came across this issue, I had a closer look at the examples, the GeoJSON schemas, and the GeoJSON spec:

Regarding the polygon example from @m-mohr : Section 3.1 of the spec appears to allow empty coordinate arrays:

A GeoJSON Geometry object of any type other than "GeometryCollection" has a member with the name "coordinates". The value of the "coordinates" member is an array. The structure of the elements in this array is determined by the type of geometry. GeoJSON processors MAY interpret Geometry objects with empty "coordinates" arrays as null objects.

So the example appears to be valid GeoJSON, minus the missing "properties" key. This is valid on https://www.jsonschemavalidator.net/ against the Feature schema:

{
  "id": "ABC",
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
    ]
  },
  "properties" : null
}

Regarding the point example from @jbants : On https://www.jsonschemavalidator.net/ the example is invalid against the Feature schema.

Yes, polygons with empty coordinates are valid. And the current schema treats point coordinates with fewer than two values as invalid. #28 adds the above examples to the test fixtures.