diff --git a/openeo_driver/ProcessGraphDeserializer.py b/openeo_driver/ProcessGraphDeserializer.py index 280b8a08..0a2a31da 100644 --- a/openeo_driver/ProcessGraphDeserializer.py +++ b/openeo_driver/ProcessGraphDeserializer.py @@ -546,10 +546,11 @@ def _collection_crs(collection_id, env) -> str: metadata = env.backend_implementation.catalog.get_collection_metadata(collection_id) except CollectionNotFoundException: return None - crs = metadata.get('cube:dimensions', {}).get('x', {}).get('reference_system', None) + crs = metadata.get("cube:dimensions", {}).get("x", {}).get("reference_system", None) return crs -def _collection_resolution(collection_id, env) -> str: + +def _collection_resolution(collection_id, env) -> Optional[List[int]]: try: metadata = env.backend_implementation.catalog.get_collection_metadata(collection_id) except CollectionNotFoundException: @@ -583,14 +584,16 @@ def _align_extent(extent,collection_id,env,target_resolution=None): if (target_resolution == None and collection_resolution == None): return extent - - if ( crs == 4326 - and extent.get('crs','') == "EPSG:4326" - and "extent" in x and "extent" in y - and (target_resolution == None or target_resolution == collection_resolution) + if ( + crs == 4326 + and extent.get("crs", "") == "EPSG:4326" + and "extent" in x + and "extent" in y + and (target_resolution is None or target_resolution == collection_resolution) ): - #only align to collection resolution + # only align to collection resolution target_resolution = collection_resolution + def align(v, dimension, rounding, resolution): range = dimension.get('extent', []) if v < range[0]: @@ -612,15 +615,20 @@ def align(v, dimension, rounding, resolution): _log.info(f"Realigned input extent {extent} into {new_extent}") return new_extent - elif(isUTM): - bbox = BoundingBox.from_dict(extent,default_crs=4326) - bbox_utm = bbox.reproject_to_best_utm() + elif isUTM: + if collection_resolution[0] <= 20: + bbox = BoundingBox.from_dict(extent, default_crs=4326) + bbox_utm = bbox.reproject_to_best_utm() - new_extent = bbox_utm.round_to_resolution(target_resolution[0],target_resolution[1]) + new_extent = bbox_utm.round_to_resolution(target_resolution[0], target_resolution[1]) - _log.info(f"Realigned input extent {extent} into {new_extent}") - return new_extent.as_dict() + _log.info(f"Realigned input extent {extent} into {new_extent}") + return new_extent.as_dict() + else: + _log.info(f"Not realigning input extent {extent} because crs is UTM and resolution > 20m") + return extent else: + _log.info(f"Not realigning input extent {extent} (collection crs: {crs}, resolution: {collection_resolution})") return extent def _extract_load_parameters(env: EvalEnv, source_id: tuple) -> LoadParameters: