← Back to Pull requests

feat(analysis): A5 Grid takes a System (H3, S2, A5, anchored hexagons) as Generate Tessellation #2727

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 22, 2026 19:34 UTC
Author

Summary

A5 Grid and Aggregate Points to A5 (#551, #573) take a System parameter, so they build a grid, or count points by cell, in one of four systems, and the same place can be compared across grids. They keep their ids and default to A5, and are renamed for what they now do:

  • Generate Tessellation (a5Grid, was A5 Grid): the cells at a resolution over the map's extent, an input layer's polygons (or the extent of its points and lines), or the world, as polygons with their ids.

  • Aggregate Points to Grid (a5Aggregate, was Aggregate Points to A5): a point layer counted by the cell holding each point, with count, density_per_km2 (by each cell's own area) and a numeric field's _sum and _mean.
  • | System | Cells | Resolutions | Id (text) |
    |---|---|---|---|
    | H3 (h3o 0.11, BSD-3-Clause) | hexagons + 12 pentagons | 0–15 | h3: H3's hex text |
    | S2 (s2 0.2, Apache-2.0) | quadrilaterals | 0–30 | s2: S2 token |
    | A5 (existing) | equal-area pentagons | 0–30 | a5: as A5 Grid's |
    | Hexagon (no crate) | flat hexagons on the map's projection | 0–24 | hex: axial q,r, plus plane |

    The anchored hexagon grid. It's laid on the active map's flat projection (Web Mercator when the map is a globe). It's anchored at that projection's origin, not at a layer's corner, so a place gets the same cell whatever layer or extent it's gridded with. The ids only mean something in that projection, so every layer names it in plane. A cell at resolution r has an A5 cell's area at r on the plane, so the two compare at one resolution. area_km2 is each cell's own area on the ground. To take the corners back to longitude/latitude, Inputs gets unproject, the inverse of the existing project (the engine's implementation is Flat::inverse). A polygon's corners are placed on the plane only where the projection takes them back to the same place, so a projection that folds (a transverse Mercator far from its meridian) refuses the area rather than covering the wrong cells. A cell whose corners the projection can't take back is left out and counted in the message.

    Shared with A5. crates/analysis/src/dggs.rs now has a System and a Grid with the per-system operations: the cell of a point, a cell's outline and area, the covering of a polygon, and the world. On top of them sit the existing pieces:

  • the area check and estimate before covering;

  • the 200,000-cell cap;

  • the split at the antimeridian;

  • the polygons left out for want of an outline.
  • One tool per task rather than a second pair beside A5's: a run that names no system (every model and script saved before) gets A5, with the same layer and message as before, and a test checks that against an explicit System: A5.

    How each system covers a polygon:

  • H3: h3o's tiler, in Covers mode for Overlapping and ContainsCentroid for Center. Shapes are cut at ±180° first, so its transmeridian heuristic is off: that heuristic would take a world-wide view for a polygon across the antimeridian.

  • S2: s2 0.2 has no polygons. The covering descends from the six faces to the level, pruned by the polygon's bounding Rect, and keeps the cells that overlap the polygon (or hold its centre), tested with geo's PreparedGeometry.

  • Hexagon: for each row of hexagons, the polygon's leftmost and rightmost point within the row, then the same test on the plane. The candidates are counted, and refused past the cap, before any is tested.
  • Corners on a pole are drawn as a line along the pole. S2's face cells have them, and so do A5's cells round a pole, which fixes a gap in A5 as it is on main: a point at 89.99° S fell outside the outline of the cell that a5Aggregate put it in (a_point_falls_in_the_cell_holding_it fails for A5 without the change). In S2 and the hexagon grid, Overlapping keeps the cells that share area with the polygon, not those that only touch its outline; H3's is h3o's own Covers mode, which keeps a cell that meets the outline. A hole without a usable outline is left out and counted, as a polygon part already was. In Web Mercator the hexagon grid stops at 85.05°: a point beyond it is left out and counted (never put in the edge cell its latitude would be clamped to), and an area past it is cut there and said to be. A system that isn't text is refused.

    Limits, Cancel and memory.

  • Cell cap: a run makes at most 200,000 cells, as A5 Grid does.

  • Refused before covering: an area that would need far more cells (the estimate, summed over every polygon of the run, as A5's).

  • Refused while covering: a run whose coverings would look at more than 800,000 cells, again counted over every polygon. That's the S2 descent's bounding-box cells and the hexagon grid's rows and candidates. Many polygons that each stay under the cap can't add up to hours.

  • Cancel and progress: both tools look at Cancel when they start, while reading the layer, during the coverings and the point loop (Pace), and while they make the layer. The point loop and the layer count progress. Both tools are in the cancellation test's list of long tools, a5Grid in H3, S2 and Hexagon, a5Aggregate in H3.

  • H3: its tiler runs as one step, bounded by the estimate before it.

  • Memory: the output is at most 200,000 polygons of about 5–25 vertices, so roughly 80 MB of coordinates at worst. The selected polygons' rings are copied once (about 1× the layer's coordinates), as A5 Grid already did, and that copy is moved into its antimeridian-split sides, not copied again.

  • Threads: the work runs on one thread. Each covering is bounded by the caps above, and the relate tests run on prepared geometry, so a split per polygon isn't worth its merge.
  • Where it reaches. Both tools are in the built-in list (TOOLS), so they reach every surface that lists or runs built-in tools:

  • gp.tools lists them, and gp.run and gp.batch run them;

  • so do models, scripts, the CLI, Python and the assistant;

  • the Analysis pane and the model builder list them with every built-in tool (analysis::TOOLS), and the pane's forms show their parameters.
  • They get no ribbon button, shortcut or phone entry, as A5 Grid and the other analysis tools have none: on the desktop they are reached through the Analysis pane.

    Their output is a new layer, undone like any tool's. Their new names, summaries and labels are English strings that wait for the next translation pass; the .tsv catalogues are left alone, so the rows for the old names (A5 Grid, Aggregate Points to A5) are left for that pass to drop.

    A project capability, dggs-system. An older release would leave out a system it doesn't know and make A5 cells, warning only that it ignored the key. So a project, model file or web tool that saves a run of either tool with a system other than A5 (a step, a task, the history, gp.run, gp.batch or a script) requires dggs-system, as slope-percent and tabulate-intersection-unit do for their options, and an older reader refuses it by name. A blank system, A5 or none needs nothing. It's in CAPABILITIES, the schema and docs/maintaining.md; schema/fixtures/dggs_system.rgis is a project that requires it, and a_grid_system_other_than_a5_is_required covers every saved path, and fails with the capability taken out of the table.

    New dependencies: h3o 0.11 (with its geo feature, on our geo 0.33) and s2 0.2 (default features off), both pure Rust. cargo check -p rustgis-web --target wasm32-unknown-unknown passes, and cargo xtask notices refreshed the three THIRD-PARTY-LICENSES.txt files.

    ISEA3H (dggal) is left out until its licence is checked.

    Testing

  • cargo nextest run -p rustgis-analysis: 671 passed. The new tests in dggs::tests cover:

  • - every system covering an area and counting points: each point falls in the cell whose outline holds it, and that cell is in the grid;
    - points across the antimeridian, at high latitudes and round the poles, and a point at the pole on Web Mercator left out;
    - the hexagon grid's polygon corners on a plane that folds, refused rather than misplaced (the test breaks without the check);
    - a polygon across the antimeridian, covered on both sides;
    - the world against each system's own count, and the areas summing to the sphere's (H3, S2);
    - the cap, before and after the estimate;
    - each system's resolution range, and an unknown system;
    - ids against h3o, s2 and a5;
    - the hexagon grid anchored (two overlapping areas give the same cells) and regular on a projected plane;
    - a run naming no system, the same as System: A5 (a model or script saved before).
  • the_world_and_the_cap also covers the run-wide limit on what the coverings look at: many copies of one block, each under the cap, are refused together. I broke it on purpose by removing the limit: the run went through, and the test failed.

  • cargo nextest run --workspace: 8,905 of 8,906 passed; the one failure, portable_projects::reload::reload_reconverts_duckdb_table…, fails on main on this machine too (local DuckDB). In it:

  • - tessellations_and_points_by_cell_in_every_system: gp.run in every system, every city counted, and the hexagon grid on Mollweide (its world reaching both poles) and on the globe;
    - the cancellation tests, with a5Grid (H3, S2, Hexagon) and a5Aggregate (H3) in the list of long tools: Cancel at every look leaves the project unchanged;
    - a5_grids_and_points_by_cell and hostile_params_never_panic.
  • cargo xtask schema --check: the schema matches, 55 fixture projects open.

  • cargo deny check licenses: ok. cargo xtask notices --check: up to date.

  • cargo clippy -p rustgis-analysis -p rustgis-engine --all-targets: clean.

  • cargo check -p rustgis-web --target wasm32-unknown-unknown: passes.
  • UI evidence

    Before and after, the form the Analysis pane builds for the tool: A5 Grid on main, and Generate Tessellation with its System. Then the form of Aggregate Points to Grid, and captures of the same view of Bogotá with Generate Tessellation in each system, from the headless ui_shot runner: H3 r8, S2 r13, A5 r13, and Hexagon r13 on a map in Web Mercator and on one in EPSG:9377 (MAGNA-SIRGAS / Origen-Nacional).

    | Before: A5 Grid on main | After: Generate Tessellation |
    |---|---|
    | !form-before-a5Grid.png | !form-dggsGrid.png |

    Aggregate Points to Grid

    !form-dggsAggregate.png

    | H3 r8 | S2 r13 |
    |---|---|
    | !H3-mercator.png | !S2-mercator.png |
    | A5 r13 | Hexagon r13, Web Mercator |
    | !A5-mercator.png | !Hexagon-mercator.png |

    Hexagon r13, EPSG:9377

    !Hexagon-EPSG9377.png

    Related issue

    Closes #2726

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: github-actions[bot] Review duration: 7m
    All Vouch review confidence checks passed
    Residual risk 0.37 = Change Risk (0.52) × (1 − Review Confidence (0.29)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 47% · Reviewer familiarity: 35%
    29%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #2727"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 29.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 29.1% · Lower = rushed or shallow review
    29.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 36.9% · Moderate risk
    36.9%