Skip to content

feat: detect geozone from spatial.geom - #3857

Draft
abulte wants to merge 1 commit into
mainfrom
feat/bbox-to-geozone
Draft

feat: detect geozone from spatial.geom#3857
abulte wants to merge 1 commit into
mainfrom
feat/bbox-to-geozone

Conversation

@abulte

@abulte abulte commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This feed dataset.extras['analysis:spatial:zones'] with one or more detected geozones from dataset.spatial.geom.

We're not using dataset.spatial.zones because:

  • we don't want to override a producer's available attribute
  • there currently can't be both a geom and zones in dataset.spatial

I believe this belongs in udata since it's working on dataset's metadata. The analysis: namespace might be wrong though.

The matching is done by comparing the geozone bbox to the spatial geometry bbox. This makes it fast and doesn't require any geo lib. See https://github.com/abulte/dataset-geom-to-zone for more info on matching method. It's triggered through Celery on dataset creation and dataset geometry update.

This requires associating a bbox to geozones, which this PR introduces a CLI command for. See attached file for a working draft of the expected input file. This should probably be industrialised through a DAG and published on data.gouv.fr. See https://github.com/abulte/dataset-geom-to-zone for more info on building the required input file.

Performance insights:

# no cache
In [3]: %timeit zones = get_zone_bboxes()
557 ms ± 3.69 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

# with cache
In [3]: %timeit zones = get_zone_bboxes()
19.6 ms ± 153 μs per loop (mean ± std. dev. of 7 runs, 10 loops each)

In [8]: %timeit bbox = geom_to_bbox(poissy)
27.3 μs ± 66.3 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

In [10]: %timeit detect_zone(bbox, zones)
19.3 ms ± 790 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

I'm leaving this in draft for now since I want to take more time to review the code and do more tests on the matching threshold, but don't hesitate to comment on the principle and implementation choices.

zones_bboxes.json

@abulte

abulte commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Related ecolabdata/ecospheres#1191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant