Skip to content

Commit

Permalink
fix: fix issue where STAC Geometry wasn't a closed LineRing (#19)
Browse files Browse the repository at this point in the history
* fix: ensure stac geometries are valid
* fix: bump cwl docker image

Signed-off-by: Ciaran Sweet <ciaran@developmentseed.org>
  • Loading branch information
ciaransweet committed Nov 5, 2024
1 parent 8718ecd commit 7b69e87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hazard_workflow.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ $graph:

hints:
DockerRequirement:
dockerPull: public.ecr.aws/c9k5s3u3/os-hazard-indicator:cb86f35
dockerPull: public.ecr.aws/c9k5s3u3/os-hazard-indicator:ed6f5d1

requirements:
ResourceRequirement:
Expand Down
16 changes: 15 additions & 1 deletion src/hazard/inventory.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import datetime
import itertools
import json
from copy import deepcopy
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union

import pystac
import shapely
from pydantic import BaseModel, Field


# region HazardModel


Expand Down Expand Up @@ -186,7 +189,12 @@ def to_stac_item(
rel="collection", media_type="application/json", target="./collection.json"
)

coordinates = self.map.bounds if self.map else None
coordinates = deepcopy(self.map.bounds) if self.map else None

# GeoJSON requires the coordinates of a LineRing to have the same beginning and end
if coordinates:
coordinates.append(coordinates[0])

bbox = self.map.bbox if self.map else None
stac_item = pystac.Item(
id=item_id,
Expand All @@ -204,6 +212,12 @@ def to_stac_item(

stac_item.validate()

is_valid_response = shapely.is_valid_reason(
shapely.from_geojson(json.dumps(stac_item.to_dict()))
)
if is_valid_response != "Valid Geometry":
raise Exception(f"STAC Item is not valid: {is_valid_response}")

templated_out_item = self._expand_template_values_for_stac_record(
combined_parameters, stac_item
)
Expand Down

0 comments on commit 7b69e87

Please sign in to comment.