Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

## [v0.5.2]

### Added

- `update_extent_from_items` method to Collection for updating Extent objects within a collection based on the contained items. ([#168](https://github.com/stac-utils/pystac/pull/168))
### Added

- `update_extent_from_items` method to Collection for updating Extent objects within a collection based on the contained items. ([#168](https://github.com/stac-utils/pystac/pull/168))

### Fixed

- Fix bug that caused get_children to miss some links. ([#172](https://github.com/stac-utils/pystac/pull/172))

## [v0.5.1]

Expand Down
37 changes: 23 additions & 14 deletions pystac/stac_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,32 @@ def set_root(self, root, link_type=None):
object to set. Passing in None will clear the root.
link_type (str): The link type (see :class:`~pystac.LinkType`)
"""
root_link_index = next(iter([i for i, link in enumerate(self.links) if link.rel == 'root']),
None)

# Remove from old root resolution cache
root_link = self.get_root_link()
if root_link is not None:
if root_link_index is not None:
root_link = self.links[root_link_index]
if root_link.is_resolved():
root_link.target._resolved_objects.remove(self)

if not link_type:
prev = self.get_single_link('root')
if prev is not None:
link_type = prev.link_type
else:
link_type = LinkType.ABSOLUTE
if link_type is None:
link_type = root_link.link_type

if link_type is None:
link_type = LinkType.ABSOLUTE

self.remove_links('root')
if root is not None:
self.add_link(Link.root(root, link_type=link_type))
if root is None:
self.remove_links('root')
else:
new_root_link = Link.root(root, link_type=link_type)
if root_link_index is not None:
self.links[root_link_index] = new_root_link
new_root_link.set_owner(self)
else:
self.add_link(new_root_link)
root._resolved_objects.cache(self)

return self

def get_parent(self):
Expand Down Expand Up @@ -346,9 +355,9 @@ def get_stac_objects(self, rel):
Generator[STACObjects]: A possibly empty generator of STACObjects that are
connected to this object through links with the given ``rel``.
"""

for i in range(0, len(self.links)):
link = self.links[i]
links = self.links[:]
for i in range(0, len(links)):
link = links[i]
if link.rel == rel:
link.resolve_stac_object(root=self.get_root())
yield link.target
Expand Down
119 changes: 119 additions & 0 deletions tests/data-files/catalogs/cbers-partial/CBERS4AWFI/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"id": "CBERS4AWFI",
"stac_version": "1.0.0-beta.2",
"description": "CBERS4 AWFI camera catalog",
"links": [
{
"rel": "root",
"href": "../catalog.json",
"type": "application/json"
},
{
"rel": "parent",
"href": "../catalog.json",
"type": "application/json"
}
],
"stac_extensions": [
"eo",
"item-assets"
],
"providers": [
{
"name": "Instituto Nacional de Pesquisas Espaciais, INPE",
"roles": [
"producer"
],
"url": "http://www.cbers.inpe.br"
},
{
"name": "AMS Kepler",
"description": "Convert INPE's original TIFF to COG and copy to Amazon Web Services",
"roles": [
"processor"
],
"url": "https://github.com/fredliporace/cbers-on-aws"
},
{
"name": "Amazon Web Services",
"roles": [
"host"
],
"url": "https://registry.opendata.aws/cbers/"
}
],
"properties": {
"gsd": 64.0,
"platform": "CBERS-4",
"instruments": [
"AWFI"
]
},
"item_assets": {
"thumbnail": {
"title": "Thumbnail",
"type": "image/jpeg"
},
"metadata": {
"title": "INPE original metadata",
"type": "text/xml"
},
"B13": {
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"eo:bands": [
{
"name": "B13",
"common_name": "blue"
}
]
},
"B14": {
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"eo:bands": [
{
"name": "B14",
"common_name": "green"
}
]
},
"B15": {
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"eo:bands": [
{
"name": "B15",
"common_name": "red"
}
]
},
"B16": {
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"eo:bands": [
{
"name": "B16",
"common_name": "nir"
}
]
}
},
"extent": {
"spatial": {
"bbox": [
[
-180.0,
-83.0,
180.0,
83.0
]
]
},
"temporal": {
"interval": [
[
"2014-12-08T00:00:00Z",
null
]
]
}
},
"license": "CC-BY-SA-3.0"
}
119 changes: 119 additions & 0 deletions tests/data-files/catalogs/cbers-partial/CBERS4MUX/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"id": "CBERS4MUX",
"stac_version": "1.0.0-beta.2",
"description": "CBERS4 MUX camera catalog",
"links": [
{
"rel": "root",
"href": "../catalog.json",
"type": "application/json"
},
{
"rel": "parent",
"href": "../catalog.json",
"type": "application/json"
}
],
"stac_extensions": [
"eo",
"item-assets"
],
"providers": [
{
"name": "Instituto Nacional de Pesquisas Espaciais, INPE",
"roles": [
"producer"
],
"url": "http://www.cbers.inpe.br"
},
{
"name": "AMS Kepler",
"description": "Convert INPE's original TIFF to COG and copy to Amazon Web Services",
"roles": [
"processor"
],
"url": "https://github.com/fredliporace/cbers-on-aws"
},
{
"name": "Amazon Web Services",
"roles": [
"host"
],
"url": "https://registry.opendata.aws/cbers/"
}
],
"properties": {
"gsd": 20.0,
"platform": "CBERS-4",
"instruments": [
"MUX"
]
},
"item_assets": {
"thumbnail": {
"title": "Thumbnail",
"type": "image/jpeg"
},
"metadata": {
"title": "INPE original metadata",
"type": "text/xml"
},
"B5": {
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"eo:bands": [
{
"name": "B5",
"common_name": "blue"
}
]
},
"B6": {
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"eo:bands": [
{
"name": "B6",
"common_name": "green"
}
]
},
"B7": {
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"eo:bands": [
{
"name": "B7",
"common_name": "red"
}
]
},
"B8": {
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"eo:bands": [
{
"name": "B8",
"common_name": "nir"
}
]
}
},
"extent": {
"spatial": {
"bbox": [
[
-180.0,
-83.0,
180.0,
83.0
]
]
},
"temporal": {
"interval": [
[
"2014-12-08T00:00:00Z",
null
]
]
}
},
"license": "CC-BY-SA-3.0"
}
Loading