Respect VMM flood coverage size limit
GeoIntel CI / docs-smoke (push) Canceled after 0s
GeoIntel CI / contract-smoke (push) Canceled after 0s

This commit is contained in:
Codex
2026-07-15 22:23:22 +02:00
parent 501f824257
commit 943ecfbc90
2 changed files with 51 additions and 2 deletions
@@ -14,6 +14,7 @@ from urllib.error import HTTPError, URLError
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from uuid import UUID
from xml.etree import ElementTree
from geoalchemy2.shape import to_shape
from pyproj import Transformer
@@ -50,7 +51,9 @@ class FloodHazardAcquisitionService:
SOURCE_VERSION = "VMM OGRK flood hazard maps"
ATTRIBUTION = "Bron: VMM"
LICENSE_NOTE = "Publieke toegang; gebruik en bronvermelding volgens de metadata van VMM/GDI-Vlaanderen."
WCS_TILE_SIDE_M = 10_000.0
# The VMM WCS rejects generated coverages above 4.88 MB. At the default
# 5 metre resolution a 5 km square stays below that provider-side limit.
WCS_TILE_SIDE_M = 5_000.0
WCS_REQUEST_INTERVAL_SECONDS = 1.0
WCS_RETRY_DELAY_SECONDS = 3.0
WCS_TRANSIENT_STATUS_CODES = frozenset({400, 429, 502, 503, 504})
@@ -281,10 +284,27 @@ class FloodHazardAcquisitionService:
if content.startswith((b"II*\x00", b"MM\x00*")):
return content
if "multipart" not in content_type.lower():
provider_exception = None
if "xml" in content_type.lower() or content.lstrip().startswith(b"<"):
try:
root = ElementTree.fromstring(content)
exception_texts = [
(element.text or "").strip()
for element in root.iter()
if element.tag.rsplit("}", 1)[-1] in {"ExceptionText", "ServiceException"}
and (element.text or "").strip()
]
provider_exception = " ".join(exception_texts) or None
except ElementTree.ParseError:
pass
raise AppError(
code="FLOOD_HAZARD_PROVIDER_INVALID_RESPONSE",
message="The official VMM service did not return a GeoTIFF coverage",
details={"content_type": content_type, "response_preview": content[:300].decode("utf-8", errors="replace")},
details={
"content_type": content_type,
"provider_exception": provider_exception,
"response_preview": content[:300].decode("utf-8", errors="replace"),
},
status_code=502,
)
message = BytesParser(policy=default).parsebytes(f"Content-Type: {content_type}\r\nMIME-Version: 1.0\r\n\r\n".encode() + content)