diff --git a/scripts/initialise_stac_collection.py b/scripts/initialise_stac_collection.py new file mode 100644 index 000000000..a3999feac --- /dev/null +++ b/scripts/initialise_stac_collection.py @@ -0,0 +1,38 @@ +import argparse +import json +import os + +from linz_logger import get_log + +from scripts.files.fs import write +from scripts.logging.time_helper import time_in_ms +from scripts.stac.imagery.collection import ImageryCollection + + +def initialise_imagery_collection(title: str, description: str) -> None: + start_time = time_in_ms() + get_log().info("finalise_stac_collection_imagery_start", title=title, description=description) + + collection = ImageryCollection(title=title, description=description) + + tmp_file_path = os.path.join("/tmp/", "collection.json") + write(tmp_file_path, json.dumps(collection.stac).encode("utf-8")) + + get_log().info("create_stac_collection_imagery_complete", title=title, duration=time_in_ms() - start_time) + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("--title", dest="title", required=True) + parser.add_argument("--description", dest="description", required=True) + + arguments = parser.parse_args() + + title = arguments.title + description = arguments.description + + initialise_imagery_collection(title, description) + + +if __name__ == "__main__": + main() diff --git a/scripts/stac/imagery/collection.py b/scripts/stac/imagery/collection.py new file mode 100644 index 000000000..2af74aa1e --- /dev/null +++ b/scripts/stac/imagery/collection.py @@ -0,0 +1,38 @@ +from typing import Any, Dict, List, Optional + +import ulid + +from scripts.stac.util.STAC_VERSION import STAC_VERSION + +PYSTAC_VERSION = "1.0.0" + + +class ImageryCollection: + stac: Dict[str, Any] + + def __init__(self, title: Optional[str] = None, description: Optional[str] = None) -> None: + self.stac = { + "type": "Collection", + "stac_version": STAC_VERSION, + "id": str(ulid.ULID()), + "title": title, + "description": description, + "license": "CC-BY-4.0", + "links": [{"rel": "self", "href": "./collection.json", "type": "application/json"}], + } + + def add_link(self, href: str, rel: str = "item", file_type: str = "application/json") -> None: + # Will be implemented in Future PR + pass + + def update_spatial_extent(self, item_bbox: List[float]) -> None: + # Will be implemented in Future PR + pass + + def update_temporal_extent(self, item_start_datetime: str, item_end_datetime: str) -> None: + # Will be implemented in Future PR + pass + + def update_extent(self, bbox: Optional[List[float]] = None, interval: Optional[List[str]] = None) -> None: + # Will be implemented in Future PR + pass diff --git a/scripts/stac/tests/collection_test.py b/scripts/stac/tests/collection_test.py new file mode 100644 index 000000000..50ca500c8 --- /dev/null +++ b/scripts/stac/tests/collection_test.py @@ -0,0 +1,10 @@ +from scripts.stac.imagery.collection import ImageryCollection + + +def test_imagery_stac_collection_initialise() -> None: + title = "Test Urban Imagery" + description = "Test Urban Imagery Description" + collection = ImageryCollection(title, description) + + assert collection.stac["title"] == title + assert collection.stac["description"] == description diff --git a/scripts/stac/util/STAC_VERSION.py b/scripts/stac/util/STAC_VERSION.py new file mode 100644 index 000000000..da99fa74c --- /dev/null +++ b/scripts/stac/util/STAC_VERSION.py @@ -0,0 +1 @@ +STAC_VERSION = "1.0.0"