Skip to content

Commit b75f32e

Browse files
authored
Merge pull request #288 from volaya/type_property
added type property for catalogs and collections
2 parents a59bfd1 + 2b54d1f commit b75f32e

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

pystac/catalog.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ def to_dict(self, include_self_link=True):
389389
links = filter(lambda l: l.rel != 'self', links)
390390

391391
d = {
392+
'type': self.STAC_OBJECT_TYPE.value.title(),
392393
'id': self.id,
393394
'stac_version': pystac.get_stac_version(),
394395
'description': self.description,

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)