@@ -31,6 +31,15 @@ class OldExtensionShortIDs(Enum):
3131 FILE = "file"
3232
3333
34+ class STACType (str , Enum ):
35+ def __str__ (self ) -> str :
36+ return str (self .value )
37+
38+ CATALOG = "Catalog"
39+ COLLECTION = "Collection"
40+ ITEM = "Feature"
41+
42+
3443@total_ordering
3544class STACVersionID :
3645 """Defines STAC versions in an object that is orderable based on version number.
@@ -180,17 +189,34 @@ def identify_stac_object_type(
180189 Args:
181190 json_dict : The dict of JSON to identify.
182191 """
183- # Try to identify using 'type' property, if present
184- if "type" in json_dict :
185- # Try to find 'type' property in known STACObjectType values
186- for t in pystac .STACObjectType :
187- if json_dict ["type" ].lower () == t .value .lower ():
188- return t
189-
192+ stac_version = (
193+ STACVersionID (json_dict ["stac_version" ])
194+ if "stac_version" in json_dict
195+ else None
196+ )
190197 obj_type = json_dict .get ("type" )
191198
199+ # Try to identify using 'type' property for v1.0.0-rc.1 and higher
200+ introduced_type_attribute = STACVersionID ("1.0.0-rc.1" )
201+ if stac_version is not None and stac_version >= introduced_type_attribute :
202+
203+ # Since v1.0.0-rc.1 requires a "type" field for all STAC objects, any object
204+ # that is missing this attribute is not a valid STAC object.
205+ if obj_type is None :
206+ return None
207+
208+ # Try to match the "type" attribute
209+ if obj_type == STACType .CATALOG :
210+ return pystac .STACObjectType .CATALOG
211+ elif obj_type == STACType .COLLECTION :
212+ return pystac .STACObjectType .COLLECTION
213+ elif obj_type == STACType .ITEM :
214+ return pystac .STACObjectType .ITEM
215+ else :
216+ return None
217+
192218 # For pre-1.0 objects for version 0.8.* or later 'stac_version' must be present
193- if " stac_version" in json_dict :
219+ if stac_version is not None :
194220 # Pre-1.0 STAC objects with 'type' == "Feature" are Items
195221 if obj_type == "Feature" :
196222 return pystac .STACObjectType .ITEM
0 commit comments