From 39ee3b377cc6ff311a81dd58e3a0c42eac8ae614 Mon Sep 17 00:00:00 2001 From: Anton Bakker Date: Tue, 2 Jan 2024 17:08:07 +0100 Subject: [PATCH] update flowchart for transformation endpoint + add data-outside-bbox error --- README.md | 15 +++++++++------ src/coordinate_transformation_api/main.py | 13 ++++++++----- src/coordinate_transformation_api/models.py | 7 +++++++ src/coordinate_transformation_api/util.py | 6 +++--- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3a5b634..315c3d1 100644 --- a/README.md +++ b/README.md @@ -152,19 +152,22 @@ cjio test_1.city.json crs_reproject 4937 save test_1_4937.city.json flowchart input([/transform endpoint]) ==> filetype{content-type
request body} filetype==> | GeoJSON | dc_param{density-check parameter} - filetype==> | CityJSON | tf + filetype==> | CityJSON | a4[add response header:
density-check-result: not-implemented] + a4 --> tf dc_param ==> |"`default: *true*`"|ms_param{max_segment param} ms_param -.-> |max_segment_deviation param| bc[check if data within bbox] bc --> |success| dc bc --> |failure| output_error_bbox([HTTP 400 with bbox error]) ms_param ==> |"`max_segment_length param (default: *200*)`"| dc[density check] - dc_param -.-> |"`*false*`"| tf[transform] + dc_param -.-> |"`*false*`"| a5[add response header:
density-check-result: not-run] - dc --> |"not applicable: geometrytype is point" | a2[add response header:
Density-Check-Result: NotApplicableGeometryType] - dc --> |"partially not applicable:
one or more geometries have geometrytype (multi)Point" | a4[??] - dc --> |"success"| a3[add response header:
Density-Check-Result: success] - dc --> |"failure"| output_error([HTTP 400 with density check report]) + a5 --> tf[transform] + + dc --> |"not applicable: geometrytype is point" | a2[add response header:
density-check-result: not-applicable-geom-type] + dc --> |"success"| a3[add response header:
density-check-result: success] + dc --> |"failure"| a6[add response header:
density-check-result: failed] + a6 --> output_error([HTTP 400 with density check report]) a2 --> tf a3 --> tf tf --> output([http 200 response]) diff --git a/src/coordinate_transformation_api/main.py b/src/coordinate_transformation_api/main.py index 6de8b92..e76df06 100644 --- a/src/coordinate_transformation_api/main.py +++ b/src/coordinate_transformation_api/main.py @@ -399,11 +399,6 @@ async def post_transform( # noqa: ANN201, PLR0913 for x in [source_crs, target_crs, content_crs, accept_crs] ) - # if exclude_transformation(source_crs_str, target_crs_str): - # raise middleware.TransformationNotPossibleError( - # source_crs_str, target_crs_str - # ) - s_crs, t_crs = post_transform_get_crss( body, source_crs_str, target_crs_str, content_crs_str, accept_crs_str ) @@ -411,8 +406,16 @@ async def post_transform( # noqa: ANN201, PLR0913 if isinstance(body, CityjsonV113): body.crs_transform(s_crs, t_crs, epoch) + response_headers = set_response_headers( + ( + DENSITY_CHECK_RESULT_HEADER, + DensityCheckResult.not_implemented.value, + ), + headers=response_headers, + ) return Response( content=body.model_dump_json(exclude_none=True), + headers=response_headers, media_type="application/city+json", ) else: diff --git a/src/coordinate_transformation_api/models.py b/src/coordinate_transformation_api/models.py index 679e607..9980649 100644 --- a/src/coordinate_transformation_api/models.py +++ b/src/coordinate_transformation_api/models.py @@ -44,6 +44,12 @@ def __init__( self.report = report +class DeviationOutOfBboxError(DataValidationError): + type_str = "nsgi.nl/deviation-data-outside-bbox" + title = "Data Outside Bounding Box when Using Deviation" + pass + + class DensityCheckError(DataValidationError): type_str = "nsgi.nl/density-check-error" title = "Error Occured In Density Check" @@ -95,6 +101,7 @@ class DensityCheckResult(Enum): success = "success" failed = "failed" not_applicable_geom_type = "not-applicable-geom-type" + not_implemented = "not-implemented" class Axis(BaseModel): diff --git a/src/coordinate_transformation_api/util.py b/src/coordinate_transformation_api/util.py index 34b2cfb..2092bb2 100644 --- a/src/coordinate_transformation_api/util.py +++ b/src/coordinate_transformation_api/util.py @@ -45,8 +45,8 @@ Crs as MyCrs, ) from coordinate_transformation_api.models import ( - DataValidationError, DensifyError, + DeviationOutOfBboxError, ) from coordinate_transformation_api.settings import app_settings from coordinate_transformation_api.types import CoordinatesType @@ -179,8 +179,8 @@ def bbox_check_deviation_set( if max_segment_deviation is not None and not request_body_within_valid_bbox( body, source_crs ): - raise DataValidationError( - f"GeoJSON geometries not within bounding box: {','.join([str(x) for x in DEVIATION_VALID_BBOX])}, use max_segment_length parameter instead of max_segment_deviation parameter. Use of max_segment_deviation parameter requires data to be within mentioned bounding box." + raise DeviationOutOfBboxError( + f"Geometries not within bounding box: {DEVIATION_VALID_BBOX!s}. Use of max_segment_deviation parameter requires data to be within mentioned bounding box." )