radiantearth / stac-spec

SpatioTemporal Asset Catalog specification - making geospatial assets openly searchable and crawlable
https://stacspec.org
Apache License 2.0
777 stars 178 forks source link

Geometry validation error on Item spec #1164

Closed g-demarco closed 2 months ago

g-demarco commented 2 years ago

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?

emmanuelmathot commented 2 years ago

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.

m-mohr commented 2 years ago

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.

g-demarco commented 2 years ago

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.

m-mohr commented 11 months ago

@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.

TomAugspurger commented 4 months ago

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.

jsignell commented 4 months ago

It seems like the written spec is correct on the dev branch: image https://github.com/radiantearth/stac-spec/blob/dev/item-spec/item-spec.md

TomAugspurger commented 4 months ago

Good catch, thanks!

m-mohr commented 4 months ago

So we can close this? :-)

m-mohr commented 2 months ago

Just testing this:

Geometry BBox Result
Polygon missing Fails
Polygon null Fails
Polygon BBox Valid
null missing Valid
null null Fails
null BBox Fails

The results is compliant to image https://github.com/radiantearth/stac-spec/blob/dev/item-spec/item-spec.md