Skip to content

Commit

Permalink
refactor: simplify add_item()
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfouquet committed Feb 4, 2025
1 parent a3dd3cd commit 5a9030f
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions scripts/stac/imagery/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,11 @@ def add_item(self, item: dict[Any, Any]) -> None:
file_content=dict_to_json_bytes(item),
).stac

# Check if the Item to add already exists in the collection
exist = False
for link in self.stac["links"]:
if link["href"] == link_to_add["href"]:
if link["file:checksum"] == link_to_add["file:checksum"]:
exist = True
break
# If the item has been updated, remove the old link
self.stac["links"].remove(link)
break

if not exist:
self.stac["links"].append(link_to_add)
# Remove old link if it exists
self.stac["links"] = [link for link in self.stac["links"] if link["href"] != link_to_add["href"]]
# Add the new link
self.stac["links"].append(link_to_add)

self.update_temporal_extent(item["properties"]["start_datetime"], item["properties"]["end_datetime"])
self.update_spatial_extent(item["bbox"])

Expand Down

0 comments on commit 5a9030f

Please sign in to comment.