Add bounded Flanders thematic analysis
GeoIntel CI / docs-smoke (push) Canceled after 0s
GeoIntel CI / contract-smoke (push) Canceled after 0s

This commit is contained in:
Codex
2026-07-17 18:28:48 +02:00
parent 21103441cf
commit ce597ee0b4
17 changed files with 389 additions and 55 deletions
+9
View File
@@ -1508,6 +1508,15 @@ Kempen work area fits. External WCS transfers remain split into fixed 10 km
tiles, product identifiers remain server-allowlisted and other raster
pipelines retain their smaller independent limits.
The Flanders browser workflow uses these same endpoints on demand. It never
performs a startup import or direct browser WCS request: an explicit
municipality or drawn rectangle starts five bounded acquisitions, followed by
the existing persisted-raster analyses. Exact request hashes reuse ready
Datasets. A full-Flanders raster request remains blocked by the same 60 km and
30 million cell limits. Dataset metadata labels only Areas named
`Gemeente ...` as `coverage_scope=municipality`; regional Area clipping is
stored as `bounded_selection`.
Provision the official DOV soil polygons for Mol through the existing vector
upload path:
@@ -304,6 +304,15 @@ class ThematicRasterAcquisitionService:
raise AppError(code="THEMATIC_RASTER_SELECTION_OUTSIDE_AREA", message="Selection does not overlap the selected work area", status_code=422)
return intersection
@staticmethod
def _coverage_scope(db, area_id: UUID | None) -> str:
if area_id is None:
return "bounded_selection"
area = db.get(Area, area_id)
if area and str(area.name).casefold().startswith("gemeente "):
return "municipality"
return "bounded_selection"
@staticmethod
def _fetch(request_url: str, settings: Settings, opener: Callable[..., Any] | None = None) -> tuple[bytes, str]:
request = Request(request_url, headers={"Accept": "image/tiff,*/*", "User-Agent": "GeoIntel/0.1 bounded-thematic-raster"})
@@ -568,7 +577,7 @@ class ThematicRasterAcquisitionService:
"license_note": ThematicRasterAcquisitionService.LICENSE_NOTE,
"legend_min_label": product.legend_min_label,
"legend_max_label": product.legend_max_label,
"coverage_scope": "municipality" if payload.area_id else "bounded_selection",
"coverage_scope": ThematicRasterAcquisitionService._coverage_scope(db, payload.area_id),
},
provenance_metadata={
"acquisition": "explicit_bounded_tiled_wcs_coverage",
@@ -21,7 +21,9 @@ def test_evolution_mode_falls_back_to_an_available_series() -> None:
def test_evolution_theme_catalog_distinguishes_history_from_current_only_data() -> None:
workspace = read("frontend/src/components/map/MapWorkspace.tsx")
assert "analysisMode === 'current' || evolutionAvailable" in workspace
assert "analysisMode === 'current'" in workspace
assert "Boolean(dataset || onDemandProduct)" in workspace
assert "Boolean(dataset) && evolutionAvailable" in workspace
assert "meetmomenten" in workspace
assert "Tijdreeks" in workspace
assert "Alleen huidige toestand" in workspace
@@ -17,7 +17,7 @@ from app.core.config import Settings
from app.core.errors import AppError
from app.db.session import get_db
from app.main import app
from app.models import Dataset, Job, Project
from app.models import Area, Dataset, Job, Project
from app.schemas.thematic_raster import ThematicRasterAcquireRequest, ThematicRasterSelectionRequest
from app.schemas.assistant import AssistantQueryRequest
from app.services.geo_assistant_service import GeoAssistantService
@@ -177,6 +177,20 @@ def test_complete_kempen_scope_fits_the_tiled_thematic_guardrails() -> None:
assert exc_info.value.code == "THEMATIC_RASTER_SELECTION_TOO_LARGE"
def test_coverage_scope_only_labels_named_municipality_areas_as_municipality() -> None:
project_id = uuid4()
municipality_id = uuid4()
region_id = uuid4()
db = FakeSession({
(Area, municipality_id): Area(id=municipality_id, project_id=project_id, name="Gemeente Mol"),
(Area, region_id): Area(id=region_id, project_id=project_id, name="Vlaanderen"),
})
assert ThematicRasterAcquisitionService._coverage_scope(db, municipality_id) == "municipality"
assert ThematicRasterAcquisitionService._coverage_scope(db, region_id) == "bounded_selection"
assert ThematicRasterAcquisitionService._coverage_scope(db, None) == "bounded_selection"
def test_wcs_fetch_retries_an_incomplete_tile_without_accepting_partial_bytes(monkeypatch) -> None:
content = b"II*\x00complete-geotiff"
responses = [IncompleteResponse(content), FakeResponse(content)]
@@ -339,7 +339,8 @@ def test_theme_failures_name_the_source_and_reason() -> None:
root = Path(__file__).resolve().parents[2]
hook = (root / "frontend/src/hooks/useMapThemeSelectionInsights.ts").read_text(encoding="utf-8")
assert "dataset: queries[index]?.dataset.name" in hook
assert "queries[index]?.dataset?.name" in hook
assert "queries[index]?.thematicProductKey" in hook
assert "reason: formatError(item.reason" in hook
assert "failure.dataset}: ${failure.reason}" in hook
@@ -0,0 +1,59 @@
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
def read(path: str) -> str:
return (ROOT / path).read_text(encoding="utf-8")
def test_flanders_workspace_exposes_governed_thematic_products_on_demand() -> None:
workspace = read("frontend/src/components/map/MapWorkspace.tsx")
product_hook = read("frontend/src/hooks/useThematicRasterProducts.ts")
selection_hook = read("frontend/src/hooks/useMapThemeSelectionInsights.ts")
api = read("frontend/src/services/api/datasets.ts")
assert "activeScopeProject?.name === FLANDERS_WORKSPACE_PROJECT_NAME" in workspace
assert "new Map<DataThemeId, ThematicRasterProductRead>" in workspace
assert "'Op aanvraag'" in workspace
assert "thematicProductKey: thematicProduct.key" in workspace
assert "datasetsApi.listThematicRasterProducts" in product_hook
assert "datasetsApi.acquireThematicRaster" in selection_hook
assert "datasetsApi.selectThematicRaster" in selection_hook
assert "datasetsApi.get(selectedProjectId, acquisition.output_dataset_id)" in selection_hook
assert "/datasets/thematic-raster/acquire" in api
def test_selection_runs_all_available_themes_and_refreshes_persisted_datasets() -> None:
workspace = read("frontend/src/components/map/MapWorkspace.tsx")
app = read("frontend/src/App.tsx")
selection_hook = read("frontend/src/hooks/useMapThemeSelectionInsights.ts")
assert "for (const theme of DATA_THEMES)" in workspace
assert "await loadThemeInsights(bbox, availableThemes, areaId)" in workspace
assert "!regionalPartitionedThemeActive && !onDemandThematicThemeActive" in workspace
assert "onRefreshProjectData" in workspace
assert "selectedProjectId ? loadProjectData(selectedProjectId)" in app
assert "successful.some((item) => item.thematicProductKey)" in selection_hook
assert "await onDatasetsChanged()" in selection_hook
def test_regional_on_demand_rasters_require_a_bounded_drawn_selection() -> None:
workspace = read("frontend/src/components/map/MapWorkspace.tsx")
assert "regionalOnDemandThematicThemeActive" in workspace
assert "regionalRasterThemeActive || regionalOnDemandThematicThemeActive" in workspace
assert "Teken een begrensde rechthoek voor een regionale rasteranalyse." in workspace
assert "officiële Vlaamse rasters worden begrensd opgehaald, bewaard en hergebruikt" in workspace
def test_frontend_does_not_contact_the_external_wcs_directly() -> None:
frontend_sources = "\n".join(
path.read_text(encoding="utf-8")
for path in (ROOT / "frontend/src").rglob("*")
if path.suffix in {".ts", ".tsx"}
)
assert "mercatornet.be" not in frontend_sources.casefold()
assert "GetCoverage" not in frontend_sources