Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crs list filtering #75

Merged
merged 6 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 214 additions & 0 deletions src/coordinate_transformation_api/assets/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
transformations:
exclude:
EPSG:28992:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:4258:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:4936: [EPSG:7789]
EPSG:3035:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:3034:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:3043:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:3044:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:9067:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:9000:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:7789: [EPSG:4936]
EPSG:4326:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
OGC:CRS84:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:9755:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:3857:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:32631:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
EPSG:32632:
[
EPSG:7415,
EPSG:4937,
EPSG:4936,
EPSG:7931,
EPSG:7930,
EPSG:9286,
EPSG:7912,
EPSG:7789,
OGC:CRS84h,
EPSG:4979,
EPSG:9754,
EPSG:9753,
]
21 changes: 18 additions & 3 deletions src/coordinate_transformation_api/assets/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -688,17 +688,32 @@ components:
crs-enum:
type: string
enum:
- EPSG:7415
- EPSG:28992
- EPSG:4258
- EPSG:4937
- EPSG:7415
- EPSG:4936
- EPSG:3035
- EPSG:3034
- EPSG:3043
- EPSG:3044
- EPSG:7931
- EPSG:9067
- EPSG:7930
- EPSG:9286
- EPSG:9000
- EPSG:7912
- EPSG:7789
- EPSG:4326
- OGC:CRS84
- OGC:CRS84h
- EPSG:4979
- EPSG:9755
- EPSG:9754
- EPSG:9753
- EPSG:3857
- OGC:CRS84
- EPSG:9928
- EPSG:32631
- EPSG:32632
example: EPSG:28992

coords:
Expand Down
29 changes: 29 additions & 0 deletions src/coordinate_transformation_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Annotated, Callable, Union

import uvicorn
import yaml
from fastapi import FastAPI, Header, Query, Request, Response
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.docs import get_swagger_ui_html
Expand Down Expand Up @@ -43,6 +44,7 @@
init_oas,
post_transform_get_crss,
raise_response_validation_error,
raise_validation_error,
set_response_headers,
transform_coordinates,
validate_coords_source_crs,
Expand All @@ -52,6 +54,11 @@

assets_resources = impresources.files(assets)
logging_conf = assets_resources.joinpath("logging.conf")
api_conf = assets_resources.joinpath("config.yaml")


with open(str(api_conf)) as f:
TRANSFORMATIONS_EXCLUDE = yaml.safe_load(f)["transformations"]["exclude"]


logging.config.fileConfig(str(logging_conf), disable_existing_loggers=False)
Expand Down Expand Up @@ -101,6 +108,15 @@
)


def exclude_transformation(source_crs_str: str, target_crs_str: str) -> bool:
if source_crs_str in TRANSFORMATIONS_EXCLUDE and (
target_crs_str in TRANSFORMATIONS_EXCLUDE[source_crs_str]
):
return True

return False


@app.middleware("http")
async def add_api_version(request: Request, call_next: Callable) -> Response:
response_body = {
Expand Down Expand Up @@ -318,6 +334,12 @@ async def transform( # noqa: PLR0913, ANN201
for x in [source_crs, target_crs, content_crs, accept_crs]
)

if exclude_transformation(source_crs_str, target_crs_str):
raise_validation_error(
f"Transformation not possible between {source_crs_str} and {target_crs_str}",
[("query", "source-crs"), ("query", "target-crs")],
)

s_crs, t_crs = get_transform_get_crss(
source_crs_str, target_crs_str, content_crs_str, accept_crs_str, CRS_LIST
)
Expand Down Expand Up @@ -372,6 +394,13 @@ async def post_transform( # noqa: ANN201, PLR0913
x.value if x is not None else None
for x in [source_crs, target_crs, content_crs, accept_crs]
)

if exclude_transformation(source_crs_str, target_crs_str):
raise_validation_error(
f"Transformation not possible between {source_crs_str} and {target_crs_str}",
[("query", "source-crs"), ("query", "target-crs")],
)

s_crs, t_crs = post_transform_get_crss(
body, source_crs_str, target_crs_str, content_crs_str, accept_crs_str, CRS_LIST
)
Expand Down