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

update geodense - to return geojson featurecollection in check-densit… #90

Merged
merged 1 commit into from
Jan 5, 2024
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies = [
"pyproj == 3.6.1",
"pydantic-settings == 2.1.0",
"email-validator == 2.1.0.post1",
"geodense ~= 0.0.1a9",
"geodense ~= 0.0.1a11",
]
requires-python = ">=3.11.4"
dynamic = ["version"]
Expand Down
14 changes: 3 additions & 11 deletions src/coordinate_transformation_api/assets/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -743,20 +743,12 @@ components:
densityCheckReport:
type: object
properties:
checkPassed:
checkResult:
type: boolean
report:
type: array
items:
type: array
items:
anyOf:
- type: array
items:
type: integer
- type: number
$ref: https://geojson.org/schema/FeatureCollection.json
example:
passesCheck: false
checkResult: false
featuresReport:
- - - 0
- 0
Expand Down
19 changes: 6 additions & 13 deletions src/coordinate_transformation_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from fastapi.routing import APIRoute
from fastapi.staticfiles import StaticFiles
from geodense.geojson import CrsFeatureCollection
from geodense.lib import GeodenseError, flatten # type: ignore # type: ignore
from geodense.lib import GeodenseError # type: ignore # type: ignore
from geojson_pydantic import Feature
from geojson_pydantic.geometries import Geometry, GeometryCollection

Expand Down Expand Up @@ -329,17 +329,13 @@ async def density_check( # noqa: ANN201

s_crs = get_src_crs_densify(body, source_crs_str, content_crs_str)
try: # raises GeodenseError when all geometries in body are (multi)point
report = density_check_request_body(
fc_report = density_check_request_body(
body, s_crs, max_segment_deviation, max_segment_length
)
except GeodenseError as e:
raise DensityCheckError(str(e)) from e

# TODO: filter out NONE values in Geodense (or allow non values to indicate point geoms)
result = DensityCheckReport.from_report(
[x for x in list(flatten(report)) if x is not None]
)
return result
return DensityCheckReport.from_fc_report(fc_report)


@app.get("/transform")
Expand Down Expand Up @@ -446,14 +442,11 @@ async def post_transform( # noqa: ANN201, PLR0913
else:
if density_check:
try: # raises GeodenseError when all geometries in body are (multi)point
report = density_check_request_body(
fc_report = density_check_request_body(
body, s_crs, max_segment_deviation, max_segment_length
)
# TODO: filter out NONE values in Geodense (or allow non values to indicate point geoms)
result = DensityCheckReport.from_report(
[x for x in list(flatten(report)) if x is not None]
)
if result.passes_check:
result = DensityCheckReport.from_fc_report(fc_report)
if result.check_result:
response_headers = set_response_headers(
(DENSITY_CHECK_RESULT_HEADER, DensityCheckResult.success.value)
)
Expand Down
18 changes: 10 additions & 8 deletions src/coordinate_transformation_api/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from typing import Optional

from pydantic import BaseModel, computed_field
from geodense.geojson import CrsFeatureCollection
from pydantic import BaseModel, Field, computed_field
from pyproj import CRS as ProjCrs # noqa: N811


Expand Down Expand Up @@ -80,15 +80,17 @@ class Conformance(BaseModel):


class DensityCheckReport(BaseModel):
passes_check: bool
report: Optional[list[tuple[list[int], float]]]
check_result: bool = Field(..., alias="checkResult")
report: CrsFeatureCollection | None

@classmethod
def from_report(
cls, report: list[tuple[list[int], float]] # noqa: ANN102
def from_fc_report(
cls, fc_report: CrsFeatureCollection # noqa: ANN102
) -> "DensityCheckReport":
passes_check = not len(report) > 0
return DensityCheckReport(passes_check=passes_check, report=report)
check_result = len(fc_report.features) == 0
return DensityCheckReport(
checkResult=check_result, report=None if check_result else fc_report
)


class TransformGetAcceptHeaders(Enum):
Expand Down
17 changes: 8 additions & 9 deletions src/coordinate_transformation_api/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
_geom_type_check,
apply_function_on_geojson_geometries,
densify_geojson_object,
density_check_geojson_object,
flatten,
get_density_check_fun,
)
from geodense.models import DenseConfig, GeodenseError
from geodense.types import Nested
Expand Down Expand Up @@ -156,21 +156,20 @@ def density_check_request_body(
source_crs: str,
max_segment_deviation: float | None,
max_segment_length: float | None,
) -> list[tuple[list[int], float]]:
report: list[tuple[list[int], float]] = []

) -> CrsFeatureCollection:
_geom_type_check(body)

if max_segment_deviation is not None:
bbox_check_deviation_set(body, source_crs, max_segment_deviation)
max_segment_length = convert_deviation_to_distance(max_segment_deviation)

# TODO: @jochem add comments on langelijnen advies implementatie
crs_transform(body, source_crs, DENSIFY_CRS)
crs_transform(
body, source_crs, DENSIFY_CRS
) # !NOTE: crs_transform is required for langelijnen advies implementatie
c = DenseConfig(CRS.from_authority(*DENSIFY_CRS.split(":")), max_segment_length)
my_fun = get_density_check_fun(c)
report = apply_function_on_geojson_geometries(body, my_fun)
return report
report_fc = density_check_geojson_object(body, c)
crs_transform(report_fc, DENSIFY_CRS, source_crs)
return report_fc


def bbox_check_deviation_set(
Expand Down