report what an area selection actually measured

Four ways a selection produced a confident number about a different area than
the operator drew:

Flood hazard divided the inundated cells by every cell in the drawn rectangle,
including cells the VMM raster does not model at all. A selection reaching
past the modelled extent therefore reported a diluted risk share, turning
missing data into an implied absence of risk. Terrain, bathymetry and thematic
raster already divided by valid cells; flood hazard was the outlier. It now
reports the three populations separately, states model coverage next to the
drawn area, and returns a null fraction rather than a zero when nothing was
modelled.

geometry_mask selects a cell when its centre falls inside the geometry, so a
rectangle smaller than one cell — or one landing between four centres —
selected nothing and the analysis returned zeros indistinguishable on screen
from "we looked and there is nothing here". On a 100 m population raster a
40 m rectangle over a city block reported no inhabitants. Selection now falls
back to the touched cells and says that it did, since the answer then covers
more ground than was requested. rasterio.mask applies the same centre rule
when cropping, so that call is widened too; the cells that count are still
decided by the centre rule wherever it selects anything.

The object count treated any feature touching the selection as whole, while
intersection_area clipped it — two headline numbers on one panel describing
different populations. The count stays whole-feature, which is what "objecten"
means to an operator, but now reports how many the edge cuts and is marked an
estimate when it does. The area_weighted_sum branch reuses that same count
instead of issuing its own near-identical query.

Partitioned selection de-duplicated the count on source_feature_id but
returned the raw rows, so a building on a municipal boundary was counted once
and drawn twice.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Jens
2026-08-22 14:33:19 +02:00
co-authored by Claude Opus 5
parent 08188005bd
commit dd87a62e8f
20 changed files with 1037 additions and 82 deletions
@@ -24,8 +24,15 @@ class ScalarQuery:
class SequenceScalarSession:
def __init__(self, values: list[float]):
self.values = iter(values)
"""Answers scalar queries in the order the summary issues them.
The first query is the fully-covered feature count that produces the
selection-edge disclosure; ``covered_count`` defaults to the full
population, i.e. a selection that cuts nothing.
"""
def __init__(self, values: list[float], covered_count: float | None = None):
self.values = iter(([covered_count] if covered_count is not None else []) + values)
def query(self, *args): # noqa: ANN002, ARG002
return ScalarQuery(next(self.values))
@@ -53,7 +60,7 @@ def themed_dataset(theme: str, *, method: str = "feature_count") -> Dataset:
def test_building_selection_promotes_footprint_area_and_retains_object_count() -> None:
result = VectorFeatureService.summarize_features_by_bbox(
SequenceScalarSession([125_000.0]),
SequenceScalarSession([125_000.0], covered_count=40),
dataset=themed_dataset("buildings"),
bbox=BBOX,
total_feature_count=40,
@@ -73,7 +80,7 @@ def test_building_selection_promotes_footprint_area_and_retains_object_count() -
def test_water_selection_reports_surface_length_and_honest_volume_limitation() -> None:
result = VectorFeatureService.summarize_features_by_bbox(
SequenceScalarSession([52_500.0, 12_750.0]),
SequenceScalarSession([52_500.0, 12_750.0], covered_count=23),
dataset=themed_dataset("water"),
bbox=BBOX,
total_feature_count=23,
@@ -95,7 +102,7 @@ def test_population_keeps_configured_metric_and_adds_sector_count() -> None:
{"metric_key": "population", "property": "population_total", "label": "Inwoners", "unit": "inwoners"}
)
result = VectorFeatureService.summarize_features_by_bbox(
SequenceScalarSession([86_458.0]),
SequenceScalarSession([86_458.0], covered_count=733),
dataset=dataset,
bbox=BBOX,
total_feature_count=733,
@@ -132,7 +139,7 @@ def test_station_measurement_uses_numeric_mean_without_area_extrapolation() -> N
)
result = VectorFeatureService.summarize_features_by_bbox(
SequenceScalarSession([30.455]),
SequenceScalarSession([30.455], covered_count=1),
dataset=dataset,
bbox=BBOX,
total_feature_count=1,
@@ -152,7 +159,7 @@ def test_regional_historical_polygons_do_not_emit_irrelevant_line_metrics() -> N
dataset.provenance_metadata = {"operator_tool": "provision_regional_historical_landuse.py"}
result = VectorFeatureService.summarize_features_by_bbox(
SequenceScalarSession([52_500.0]),
SequenceScalarSession([52_500.0], covered_count=23),
dataset=dataset,
bbox=BBOX,
total_feature_count=23,