From 4ad75dd13b0a7465cb179d940865c28a319da7e0 Mon Sep 17 00:00:00 2001 From: rosepearson Date: Tue, 3 Sep 2024 14:17:38 +1200 Subject: [PATCH] made reobust to raster out of bounds error --- src/geoapis/raster.py | 12 ++++++++++-- src/geoapis/vector.py | 8 +++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/geoapis/raster.py b/src/geoapis/raster.py index 3f76e7d..477e9f4 100644 --- a/src/geoapis/raster.py +++ b/src/geoapis/raster.py @@ -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") @@ -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( diff --git a/src/geoapis/vector.py b/src/geoapis/vector.py index 6e80f19..76ac87d 100644 --- a/src/geoapis/vector.py +++ b/src/geoapis/vector.py @@ -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