Skip to content

Commit 2b54d1f

Browse files
committed
identify stac objects using 'type' property
1 parent 1d2b7c1 commit 2b54d1f

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

pystac/serialization/identify.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,25 @@ def identify_stac_object_type(json_dict):
264264
"""
265265
object_type = None
266266

267-
# Identify pre-1.0 ITEMCOLLECTION (since removed)
268-
if 'type' in json_dict and 'assets' not in json_dict:
269-
if 'stac_version' in json_dict and json_dict['stac_version'].startswith('0'):
270-
if json_dict['type'] == 'FeatureCollection':
271-
object_type = STACObjectType.ITEMCOLLECTION
272-
273-
if 'extent' in json_dict:
274-
object_type = STACObjectType.COLLECTION
275-
elif 'assets' in json_dict:
276-
object_type = STACObjectType.ITEM
277-
else:
278-
object_type = STACObjectType.CATALOG
267+
if 'type' in json_dict: # Try to identify using 'type' property
268+
for t in STACObjectType:
269+
if json_dict['type'].lower() == t.value.lower():
270+
object_type = t
271+
break
272+
273+
if object_type is None: # Use old-approach based on other properties
274+
# Identify pre-1.0 ITEMCOLLECTION (since removed)
275+
if 'type' in json_dict and 'assets' not in json_dict:
276+
if 'stac_version' in json_dict and json_dict['stac_version'].startswith('0'):
277+
if json_dict['type'] == 'FeatureCollection':
278+
object_type = STACObjectType.ITEMCOLLECTION
279+
280+
if 'extent' in json_dict:
281+
object_type = STACObjectType.COLLECTION
282+
elif 'assets' in json_dict:
283+
object_type = STACObjectType.ITEM
284+
else:
285+
object_type = STACObjectType.CATALOG
279286

280287
return object_type
281288

0 commit comments

Comments
 (0)