Skip to content

Commit

Permalink
fix: fail if capture-area does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfouquet committed Feb 7, 2025
1 parent fca02f1 commit d0372eb
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions scripts/stac/imagery/create_stac.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import json
import os
from typing import Any, TypeAlias, cast
from typing import Any, TypeAlias

from linz_logger import get_log
from shapely.geometry import shape
from shapely.geometry.base import BaseGeometry

from scripts.files import fs
from scripts.files.files_helper import get_file_name_from_path
from scripts.files.fs import NoSuchFileError, read
from scripts.files.fs import NoSuchFileError, exists, read
from scripts.files.geotiff import get_extents
from scripts.gdal.gdal_helper import gdal_info
from scripts.gdal.gdalinfo import GdalInfo
Expand All @@ -25,6 +25,7 @@


# pylint: disable=too-many-arguments
# pylint: disable=too-many-locals
def create_collection(
collection_id: str,
linz_slug: str,
Expand Down Expand Up @@ -63,8 +64,10 @@ def create_collection(
collection = ImageryCollection.from_file(
os.path.join(odr_url, "collection.json"), collection_metadata, current_datetime
)
capture_area = json.loads(read(os.path.join(odr_url, "capture-area.geojson")))
item_polygons.append(shape(capture_area["geometry"]))
capture_area_path = os.path.join(odr_url, "capture-area.geojson")
if exists(capture_area_path):
capture_area = json.loads(read(capture_area_path))
item_polygons.append(shape(capture_area["geometry"]))
else:
collection = ImageryCollection(
metadata=collection_metadata,
Expand Down Expand Up @@ -216,7 +219,3 @@ def create_or_load_base_item(
)

return ImageryItem(id_, stac_asset, stac_processing)


def get_published_file_contents(odr_url: str, filename: str) -> JSON_Dict:
return cast(JSON_Dict, json.loads(read(os.path.join(odr_url, f"{filename}.json")).decode("UTF-8")))

0 comments on commit d0372eb

Please sign in to comment.