Skip to content

Commit

Permalink
made reobust to raster out of bounds error
Browse files Browse the repository at this point in the history
  • Loading branch information
rosepearson committed Sep 3, 2024
1 parent babcbba commit 4ad75dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/geoapis/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ def run(self, layer: int) -> pathlib.Path:
response = requests.post(
url=f"{self.base_url}/exports/", headers=headers, json=api_query
)
query_id = response.json()["id"]
json_query = response.json()
if not json_query["is_valid"]:
logging.warning(
"Invalid initial query. Check layer exists and is within bounds. "
f"json_query['invalid_reasons']: {json_query['invalid_reasons']}. "
f"json_query['items'][0]['invalid_reasons']: {json_query['items'][0]['invalid_reasons']}"
)
return []
query_id = json_query["id"]

# Check the state of your exports until the triggered raster exports completes
logging.info("Check status of download request")
Expand All @@ -173,7 +181,7 @@ def run(self, layer: int) -> pathlib.Path:
logging.warning(
f"Could not download raster. Ended with status {element['state']}"
)
return
return []
# Download the completed export
logging.info(f"Downloading {element['download_url']} to {self.cache_path}")
with requests.get(
Expand Down
8 changes: 5 additions & 3 deletions src/geoapis/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ def get_json_response_in_bounds(self, layer: int, bounds, geometry_name: str):
logging.info(
f"Layer: {layer} is not `geometry_name`: {geometry_name}."
)
assert False, (
f"No geometry types matching that of layer: {layer} tried. The"
" geometry_name's tried are: +{geometry_type_list}"
message = (
f"No geometry types matching that of layer: {layer}. "
f"The geometry_name's tried are: {geometry_type_list}."
)
logging.error(message)
raise ValueError(message)

def get_features_inside_catchment(
self, layer: int, geometry_name: str
Expand Down

0 comments on commit 4ad75dd

Please sign in to comment.