Handle DHMV WCS edge grid rounding
GeoIntel CI / docs-smoke (push) Canceled after 0s
GeoIntel CI / contract-smoke (push) Canceled after 0s

This commit is contained in:
Codex
2026-07-16 12:47:53 +02:00
parent e620689d8c
commit 512e15f24b
2 changed files with 84 additions and 6 deletions
@@ -115,6 +115,24 @@ def elevation_tiff(*, left: float, top: float, width: int, height: int, resoluti
return memory.read()
def edge_elevation_tiff(*, left: float, top: float, x_resolution: float, y_resolution: float = 5.0) -> bytes:
rows, columns = np.indices((20, 20))
values = (20.0 + columns * 0.5 + rows).astype("float32")
with MemoryFile() as memory:
with memory.open(
driver="GTiff",
width=20,
height=20,
count=1,
dtype="float32",
crs="EPSG:31370",
transform=from_origin(left, top, x_resolution, y_resolution),
nodata=-9999.0,
) as output:
output.write(values, 1)
return memory.read()
def multipart_tiff(content: bytes) -> tuple[bytes, str]:
boundary = "wcs-test"
payload = (
@@ -190,6 +208,28 @@ def test_dhmv_large_scope_is_bounded_into_mosaicable_wcs_tiles() -> None:
assert dataset.nodata == -9999.0
def test_dhmv_mosaic_harmonizes_only_bounded_wcs_edge_grid_rounding() -> None:
regular = elevation_tiff(left=200_000, top=210_100, width=20, height=20)
rounded_edge = edge_elevation_tiff(left=200_100, top=210_100, x_resolution=4.76555, y_resolution=5.0008)
diagnostics: dict[str, object] = {}
mosaic = DhmvAcquisitionService._mosaic_geotiffs(
[regular, rounded_edge],
expected_resolution_m=5.0,
diagnostics=diagnostics,
)
with MemoryFile(mosaic) as memory, memory.open() as dataset:
assert dataset.res == pytest.approx((5.0, 5.0))
assert diagnostics["harmonized_tile_indexes"] == [1]
assert diagnostics["harmonization_method"] == "rasterio_merge_target_resolution"
unsafe_edge = edge_elevation_tiff(left=200_100, top=210_100, x_resolution=4.5)
with pytest.raises(AppError) as exc_info:
DhmvAcquisitionService._mosaic_geotiffs([regular, unsafe_edge], expected_resolution_m=5.0)
assert exc_info.value.code == "DHMV_TILE_MISMATCH"
def test_dhmv_multipart_geotiff_is_extracted_and_invalid_response_fails_closed() -> None:
tiff = elevation_tiff(left=200_000, top=210_100, width=20, height=20)
multipart, content_type = multipart_tiff(tiff)