stac-spec icon indicating copy to clipboard operation
stac-spec copied to clipboard

Geometry validation error on Item spec

Open g-demarco opened this issue 3 years ago • 8 comments

Hi, I'm getting an error using the item schema (https://github.com/radiantearth/stac-spec/blob/master/item-spec/json-schema/item.json) I'm trying to create an item with a geometry equal to null, but with a populated bbox. Looking at the definition it should work, but i'm getting back this error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/jsonschema/validators.py", line 353, in validate
    raise error
ValidationError: {u'assets': {}, u'links': [], u'geometry': None, u'properties': {u'datetime': u'+00:00'}, u'stac_version': u'1.0.0', u'bbox': [1, 1, 1, 1], u'type': u'Feature', u'id': u'q12e'} is not valid under any of the given schemas

Failed validating u'oneOf' in schema[u'allOf'][0][u'allOf'][1]:
{
   "u""oneOf":[
      {
         "u""properties":{
            "u""bbox":{
               "u""items":{
                  "u""type":"u""number"
               },
               "u""oneOf":[
                  {
                     "u""maxItems":4,
                     "u""minItems":4
                  },
                  {
                     "u""maxItems":6,
                     "u""minItems":6
                  }
               ],
               "u""type":"u""array"
            },
            "u""geometry":{
               "u""$ref":"u""https://geojson.org/schema/Geometry.json"
            }
         },
         "u""required":[
            "u""geometry",
            "u""bbox"
         ],
         "u""type":"u""object"
      },
      {
         "u""properties":{
            "u""bbox":{
               "u""not":{
                  
               }
            },
            "u""geometry":{
               "u""type":"u""null"
            }
         },
         "u""required":[
            "u""geometry"
         ],
         "u""type":"u""object"
      }
   ]
}
On instance:
    {
           u'assets': {},
           u'bbox': [1, 1, 1, 1],
           u'geometry': None,
           u'id': u'q12e',
           u'links': [],
           u'properties': {u'datetime': u'+00:00'},
           u'stac_version': u'1.0.0',
           u'type': u'Feature'
}

I'm using a Draft7 compliant validator (https://github.com/Julian/jsonschema)

Any hint for how to address this problem?

g-demarco avatar Dec 23 '21 17:12 g-demarco

Indeed, the spec says

bbox REQUIRED if geometry is not null

but it is missing a constraint that it should not be specified if geometry is null. IMO, an item with a bbox has necessarily a geometry that is at least the polygon represented by the bbox.

emmanuelmathot avatar Dec 24 '21 09:12 emmanuelmathot

Yep, I agree. I believe the intention was that if you have a bbox, you must also provide a geometry with at least the extent of the bounding box. The JSON Schema seems to already follow this, but we'll likely need to clarify this in the written spec. Or do people prefer to fix the JSON Schema? @cholmes

Anyway, to "solve" the issue in 1.0.0, you'd need to provide a geometry that is equivalent to the bbox.

m-mohr avatar Jan 03 '22 16:01 m-mohr

Yes @m-mohr, the problem was found "explorating" the schema, it is clear that with a full geometry everything works fine. The problem should be just the mismatch between the schema and the specification.

Also, the clause:

"bbox": { 
    "not": {}
}

doesn't really seem to be working, but I don't know if it is a problem with the validator or something else.

g-demarco avatar Jan 10 '22 09:01 g-demarco

@matthewhanson To do the Markdown PR, @m-mohr to do the JSON Schema.

If there is a bbox you must have a geometry. We couldn't find a use case for having a bbox and not a geometry as you could always provide the bbox also as geometry. If you have use cases, please let us know.

m-mohr avatar Sep 26 '23 19:09 m-mohr

The JSON Schema seems to already follow this, but we'll likely need to clarify this in the written spec. Or do people prefer to fix the JSON Schema?

I agree that updating the written spec to state that bbox should be non-null if and only if geometry is non-null (otherwise, just set the geometry to the bbox).

It seems to be like the JSON schema is already enforcing this.

TomAugspurger avatar Apr 19 '24 14:04 TomAugspurger