Skip to content

Commit

Permalink
Merge pull request #288 from volaya/type_property
Browse files Browse the repository at this point in the history
added type property for catalogs and collections
  • Loading branch information
lossyrob authored Apr 28, 2021
2 parents a59bfd1 + 2b54d1f commit b75f32e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions pystac/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def to_dict(self, include_self_link=True):
links = filter(lambda l: l.rel != 'self', links)

d = {
'type': self.STAC_OBJECT_TYPE.value.title(),
'id': self.id,
'stac_version': pystac.get_stac_version(),
'description': self.description,
Expand Down
31 changes: 19 additions & 12 deletions pystac/serialization/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,25 @@ def identify_stac_object_type(json_dict):
"""
object_type = None

# Identify pre-1.0 ITEMCOLLECTION (since removed)
if 'type' in json_dict and 'assets' not in json_dict:
if 'stac_version' in json_dict and json_dict['stac_version'].startswith('0'):
if json_dict['type'] == 'FeatureCollection':
object_type = STACObjectType.ITEMCOLLECTION

if 'extent' in json_dict:
object_type = STACObjectType.COLLECTION
elif 'assets' in json_dict:
object_type = STACObjectType.ITEM
else:
object_type = STACObjectType.CATALOG
if 'type' in json_dict: # Try to identify using 'type' property
for t in STACObjectType:
if json_dict['type'].lower() == t.value.lower():
object_type = t
break

if object_type is None: # Use old-approach based on other properties
# Identify pre-1.0 ITEMCOLLECTION (since removed)
if 'type' in json_dict and 'assets' not in json_dict:
if 'stac_version' in json_dict and json_dict['stac_version'].startswith('0'):
if json_dict['type'] == 'FeatureCollection':
object_type = STACObjectType.ITEMCOLLECTION

if 'extent' in json_dict:
object_type = STACObjectType.COLLECTION
elif 'assets' in json_dict:
object_type = STACObjectType.ITEM
else:
object_type = STACObjectType.CATALOG

return object_type

Expand Down

0 comments on commit b75f32e

Please sign in to comment.