Skip to content

Analysis: A5 equal-area grids, and points counted by cell (#551) - #573

Merged
giswqs merged 10 commits into
opengeos:mainfrom
elpidioassinaturas:feat/551-a5
Oct 19, 2026
Merged

giswqs merged 10 commits into
opengeos:mainfrom
elpidioassinaturas:feat/551-a5

Conversation

@elpidioassinaturas

@elpidioassinaturas elpidioassinaturas commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #551, as agreed there. Two tools in a new Analysis › DGGS toolbox, on the a5 crate. It is 1.0.0, Apache-2.0 and pure Rust, and its only dependency, lazy_static, is already in the lockfile, so Cargo.lock gains just a5.

  • A5 Grid (a5Grid): the cells at a resolution (0–30) over:

    • Map Extent: the view, cut to the globe when panned past ±180° or ±90°, its edges followed every degree, so a parallel isn't taken for a great circle;
    • Input Layer: its polygons (holes kept), or the extent of its points and lines; a selection is honoured;
    • World.

    Cells: Overlapping covers the area without gaps (Containment::Overlapping); Center keeps the cells whose centre is inside.

  • Cap: a run makes at most 200,000 cells, and the error says how many it would make.

    • Before A5 covers an area, its cells are estimated from its spherical area and outline. Over twice the cap is refused there, so a large area at a fine resolution fails at once instead of after the covering.
    • The shapes are then covered one at a time. Each covering is counted exactly before its cells are made, and the cells go into one set, so cells that overlapping polygons share count once. The run stops at the covering that takes the set over the cap (cells_of, the same for the three areas).
  • Aggregate Points to A5 (a5Aggregate): a point layer's points (its selection, when there is one) counted by the cell holding them. Only cells that hold any are written, and the cap is checked per point. It adds count and density_per_km2, and a numeric field's _sum and _mean, where a feature's value counts once in each cell (a multipoint's, however many of its points fall there). Points without a usable position are left out, and the message says how many.

  • Fields: both write a5, the cell's 64-bit id in hex (u64_to_hex, as DuckDB, PostgreSQL, pya5 and R read it), resolution, and area_km2, which is the same for every cell of a resolution.

  • Outlines: a cell across the antimeridian is written as two parts of one polygon, each within −180° to 180°. A cell round a pole is closed along the pole, and split the same way when its ring turns past ±180°.

  • Inputs checked: an unknown area is refused; a polygon part whose outline isn't a ring (under three corners, or corners past ±90° latitude or ±360° longitude) is left out and counted in the message; Aggregate leaves out a point past ±90° latitude or ±360° longitude.

  • Docs: analysis.md, with the tool table and a section, including the cell sizes: resolution 5 is about 33,000 km², 9 about 130 km², 12 about 2 km².

On the questions in #551, this PR goes with:

  • the a5 dependency in rustgis-analysis;
  • the names A5 Grid and Aggregate Points to A5;
  • a 200,000-cell cap.

It should build for wasm32 as it's pure Rust, but I couldn't check that here (this machine lacks clang for zstd-sys), so it's left to CI.

Testing

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings and cargo xtask layers are clean.
  • rustgis-analysis (dggs tests):
    • a_grid_of_equal_cells:
      • a Map Extent grid over Mato Grosso has equal areas, which multiplied by the Earth's cell count give the authalic sphere's area (to 1e-6);
      • rings close;
      • the World grid at resolution 1 has get_num_cells(1) cells;
      • the cap is enforced, and the World at resolution 30 (15·4³⁰ cells, which fits in a u64) is counted and refused;
      • a view far over the cap at resolution 30 is refused by the estimate, and one just over by the exact count;
      • a view panned past the antimeridian is cut to the globe, and one wholly off it is refused;
      • a one-point layer and a row of points along a parallel get the cells holding them;
      • polygon parts without a usable outline are left out and said to be; three copies of one polygon, over the cap together, give that polygon's cells; a ring from 170° to 190° gets cells on both sides of ±180°;
      • an unknown area is refused;
      • bad resolutions (31, 2.5, −1) are refused, as is a run with no view.
    • the_estimate_follows_the_count: for three extents and resolutions, the estimate is within a factor of 2 of the cells A5 makes.
    • rings_across_the_antimeridian_and_round_the_poles: cells at 179.99°, −179.99° and both poles have no jump over 180° and close; split for the map, their parts lie within ±180° and have the ring's area, and a cell elsewhere stays whole.
    • points_counted_by_cell:
      • three points in Sorriso's resolution 12 cell and one in Oslo's give two cells;
      • the count and density are right, and the field's sum and mean skip a NaN;
      • a point at longitude 1e12 is left out, and the message says so;
      • a multipoint of two points (value 5) and a point (value 1) in one cell give count 3, sum 6 and mean 3;
      • the hex id matches lonlat_to_cell;
      • bad requests are refused.
  • rustgis-engine, a5_grids_and_points_by_cell: through gp.run, the world grid's fields, and the sample's cities counted by cell, every city in exactly one.
  • Results: rustgis-analysis: 30 passed; rustgis-engine: 220 (with RUSTGIS_GDAL_BIN); rustgis-ui-egui --lib: 146.
  • Checked by rendering with rustgis-cli: a resolution 4 grid over South America, 811 pentagons of 132,830 km² each.

🤖 Generated with Claude Code

Two tools in Analysis › DGGS, on the a5 crate (1.0.0, Apache-2.0,
pure Rust):

- A5 Grid: the cells at a resolution (0-30) over the map's extent, an
  input layer's polygons (or its points' and lines' extent) or the
  world, overlapping (no gaps) or by centre, at most 200,000 cells;
- Aggregate Points to A5: a point layer's points (its selection) counted
  by the cell holding them, with density_per_km2 and a numeric field's
  sum and mean.

Both write a5 (the cell's id in hex), resolution and area_km2; every
cell of a resolution has the same area, so a count is a density. Rings
across the antimeridian run on past 180 degrees, and those round a pole
close along it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread crates/analysis/src/dggs.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the PR statically and did not build or run it. The change adds two analysis tools, a5Grid and a5Aggregate, built on the a5 crate. I checked the hostile-input rules, wasm compatibility, and layering, and found no violations. Findings:

Bugs / robustness

  • Cell cap runs after the expensive work (dggs.rs, grid), confidence medium. polygon_to_cells runs before MAX_CELLS is checked, in both the Map Extent and Input Layer branches. A large extent or polygon at resolution 20–30 can burn CPU and memory before the error is returned. A cheap estimate (area ÷ a5::cell_area(res)) before covering would bound it. This matters because of the "never crash / hostile input" rule. I posted this inline.
  • Map Extent branch handles the covering differently from Input Layer (dggs.rs, grid), confidence low–medium. It doesn't filter compaction markers or sort and dedup, while the Input Layer branch does. The branches should agree unless a5::count and a5::uncompact handle markers. I posted this inline.
  • View extent not clamped (dggs.rs, grid), confidence low. A panned view past ±180° longitude or ±90° latitude may make A5 return an error. The tool then fails instead of clamping.
  • Antimeridian cells (dggs.rs, ring), confidence low. Cells across the antimeridian are emitted once, with longitudes past ±180°. Depending on the renderer and exporters, the part on the far side may not appear or may be clipped. The test only checks continuity, not how it draws.

Security

  • No issues found. Parameters are validated: resolution is a whole number from 0 to 30, names are length-capped, and a non-finite point is rejected.

Performance

  • Aggregation checks the by.len() cap only once per feature, so one huge MultiPoint can overshoot it before the check runs. Confidence low.

Quality

  • The "too many cells" message is duplicated between grid's World branch and expand.
  • Tests use panic! and unwrap, which is fine in test code. The engine test a5_grids_and_points_by_cell runs the tools through gp.run. I did not see a hostile-parameters addition for the new tools, but the existing hostile_params_never_panic loop covers every registered tool.

AGENTS.md

  • Interface strings in tools.rs follow the existing convention, and the docs are updated. The new dependency a5 must build for wasm32-unknown-unknown, because analysis sits below the apps. Please confirm that in CI (cargo build --target wasm32-unknown-unknown -p rustgis-web). Confidence: medium. ATTRIBUTION.md may also need an entry for the third-party crate if the project lists dependencies there. Confidence: low.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head b360309).

Metric Value
Files changed 8 (1 added, 7 modified, 0 removed, 0 renamed)
Size before 856.7 KB
Size after 877.8 KB
Total size change +21.2 KB
File Before After Change
crates/analysis/src/dggs.rs 0 B 16.1 KB +16.1 KB
crates/analysis/src/tools.rs 69.1 KB 71.5 KB +2.4 KB
docs/user-guide/analysis.md 18.5 KB 19.7 KB +1.2 KB
crates/engine/src/tests.rs 581.7 KB 582.8 KB +1.2 KB
Cargo.lock 169.0 KB 169.2 KB +228 B
Cargo.toml 4.9 KB 5.0 KB +69 B
crates/analysis/Cargo.toml 440 B 466 B +26 B
crates/analysis/src/lib.rs 13.1 KB 13.1 KB +14 B

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: f43f628b-3957-4886-9c1e-f1817fc0f489
📥 Commits

Reviewing files that changed from the base of the PR and between 98921c3 and cbce40a.

⛔ Files ignored due to path filters: 1
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing: 7
  • Cargo.toml
  • crates/analysis/Cargo.toml
  • crates/analysis/src/dggs.rs
  • crates/analysis/src/lib.rs
  • crates/analysis/src/tools.rs
  • crates/engine/src/tests.rs
  • docs/user-guide/analysis.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

📝 Walkthrough

The analysis toolbox adds A5 grid generation and point aggregation. The tools return A5 cell polygons with cell identifiers, resolution, and area. Grid generation supports several coverage areas and selection modes. Aggregation reports point counts, density, and optional numeric-field statistics.

Changes: A5 DGGS analysis

Layer / File(s) Summary
A5 cell geometry and coverage
Cargo.toml, crates/analysis/Cargo.toml, crates/analysis/src/lib.rs, crates/analysis/src/dggs.rs
Adds the a5 dependency and public DGGS module. Adds cell boundary construction, polygon splitting, shared cell attributes, and coverage helpers. Tests cover estimates, cell geometry, antimeridian splitting, and polar cells.
A5 grid generation
crates/analysis/src/dggs.rs
Adds grid generation for the world, map extent, and input-layer geometry. Resolution validation and cell-count limits apply. Tests cover grid output and invalid inputs.
Point aggregation
crates/analysis/src/dggs.rs
Adds aggregation of point and multipoint positions by A5 cell. Outputs include counts and density, with optional numeric-field sums and means. Tests cover aggregation results and invalid inputs.
Tool registration and validation
crates/analysis/src/tools.rs, crates/engine/src/tests.rs, docs/user-guide/analysis.md
Registers a5Grid and a5Aggregate. Engine tests exercise both tools. The user guide describes their options and outputs.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant gp_run
  participant TOOLS
  participant dggs_grid as dggs::grid
  participant dggs_aggregate as dggs::aggregate
  gp_run->>TOOLS: Invoke a5Grid
  TOOLS->>dggs_grid: Dispatch grid parameters
  dggs_grid-->>TOOLS: Return ToolResult
  TOOLS-->>gp_run: Return result
  gp_run->>TOOLS: Invoke a5Aggregate
  TOOLS->>dggs_aggregate: Dispatch aggregation parameters
  dggs_aggregate-->>TOOLS: Return ToolResult
  TOOLS-->>gp_run: Return result
Loading

Suggested reviewers: giswqs

Merge Risk: ⚪ Minimal · up to cbce4

No actionable issue remains from this review; the change is ready to merge after normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 3 files. (4 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main changes: adding A5 equal-area grids and counting points by cell.
Linked Issues check Passed The pull request implements the coding requirements in #551. It adds the a5 dependency, registers A5 Grid and Aggregate Points to A5, supports the requested grid areas and containment modes, writes …
Out of Scope Changes check Passed The changed files support #551. They add the dependency, DGGS implementation and tests, tool registration, engine coverage, and user documentation. The changes do not add the explicitly deferred field…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Linked Issues check

Explanation

The pull request implements the coding requirements in #551. It adds the a5 dependency, registers A5 Grid and Aggregate Points to A5, supports the requested grid areas and containment modes, writes the requested identifiers and metrics, enforces the 200,000-cell limit, handles selections, antimeridian and polar geometries, and validates invalid inputs. The aggregation supports occupied-cell output and optional numeric sums and means. The changes add focused analysis and engine tests and update analysis.md.

Full details: Out of Scope Changes check

Explanation

The changed files support #551. They add the dependency, DGGS implementation and tests, tool registration, engine coverage, and user documentation. The changes do not add the explicitly deferred field-calculator, H3, or unrelated polygon-to-cell follow-up work.

Full details: Docstring Coverage

Explanation

Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 3 files. (4 skipped: 3 unsupported, 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit maps the fields in rows,
Where equal-area A5 grows.
Each cell keeps its numbered name,
Points gather there by count and sum.
The burrow hums: the grid is done!

Comment @coderabbitai help to get the list of available commands.

…s cut to the globe (opengeos#573 review)

- An area's cells are estimated from its spherical area and outline before A5 covers it, and
  well over the cap is refused there; the exact count still applies after.
- Map Extent, Input Layer and World go through one expansion (cells_of): counted before any is
  made, compaction markers skipped, sorted and deduped. The duplicated message is one helper.
- A view or layer extent past ±180° or ±90° is cut to the globe; wholly off it is an error.
- Aggregate checks the cell cap per point, so one large MultiPoint can't overshoot it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread crates/analysis/src/dggs.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I reviewed dggs.rs (the two new tools), the registration in tools.rs, the new tests, and the docs. I didn't build or run anything, so this is from reading the code only. I found one issue worth raising and it needs a fix. Otherwise the change looks sound and follows the repo rules.

Bugs

  • Degenerate extents are rejected with a misleading error (crates/analysis/src/dggs.rs:110, medium confidence). on_the_globe requires min_x < max_x && min_y < max_y. In A5 Grid with Input Layer, a one-point layer, a single selected point, or a purely horizontal or vertical line gives a zero-width or zero-height extent. The user then sees "The extent of X is outside the globe's longitudes and latitudes", which is wrong. Pad such extents slightly, or use a separate message. Inline comment posted.

Security

  • Nothing found. Resolution is validated as a whole number from 0 to 30. The 200,000-cell cap is checked before cells are generated (cells_of) and while counting points. Hostile geometry such as NaN coordinates or latitudes beyond ±90° is handled, and the engine's hostile-params test covers the new tools.

Performance

  • Nothing blocking. The pre-cover estimate refuses huge areas before A5 works on them, and ring edges are capped at 720 steps.

Quality

  • Nothing worth raising. In estimate, ring.len() can't be zero inside the loop, so the % ring.len() is safe.

AGENTS.md

  • No unwrap, expect or panic! in non-test code, and no unsafe.
  • The new a5 dependency is pure Rust. That should keep wasm32 working, but the author couldn't build it locally, so CI has to confirm.
  • A regression test is added in crates/engine/src/tests.rs.
  • Docs are updated. Per-tool UI strings come from the tool registry, so no tl! issue arises in these files.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head b79ed0d)

Metric Value
Files changed 8 (1 added, 7 modified, 0 removed, 0 renamed)
Size before 856.7 KB
Size after 882.3 KB
Total size change +25.7 KB
File Before After Change
crates/analysis/src/dggs.rs 0 B 20.7 KB +20.7 KB
crates/analysis/src/tools.rs 69.1 KB 71.5 KB +2.4 KB
docs/user-guide/analysis.md 18.5 KB 19.7 KB +1.2 KB
crates/engine/src/tests.rs 581.7 KB 582.8 KB +1.2 KB
Cargo.lock 169.0 KB 169.2 KB +228 B
Cargo.toml 4.9 KB 5.0 KB +69 B
crates/analysis/Cargo.toml 440 B 466 B +26 B
crates/analysis/src/lib.rs 13.1 KB 13.3 KB +14 B

…pengeos#573 review)

An extent with no width or height is widened by a hair instead of being taken as off the globe,
so a layer of one point, or of points along a parallel or meridian, is covered by the cells
holding it. With Cells: Center and no cell centre inside, the error says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread crates/analysis/src/dggs.rs Resolved
Comment thread crates/analysis/src/dggs.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff and the surrounding code. The PR adds the A5 Grid and Aggregate Points to A5 tools, backed by the a5 crate. I did not build the code or run the tests. I posted two inline comments.

Bugs

  • Unbounded longitude in Aggregate (low-medium). aggregate checks that latitude is within ±90° but passes longitude to lonlat_to_cell unchecked. Junk or projected x values could be rejected or silently wrapped into the wrong cell. See the inline comment.
  • Unknown area value (low). An unrecognised area string falls back to Map Extent without any message. This can't crash; it is only a usability gap.
  • Degenerate polygon rings (low, unverified). A polygon with a degenerate ring (fewer than 3 points) goes to polygon_to_cells. If that returns an error, the whole run fails instead of skipping that feature.

Security

  • Nothing found. Parameters are validated, the cell count is capped before cells are generated, and there is no unwrap or panic in non-test code.

Performance

  • The estimate-then-cap design is sound. Areas far over the cap are refused before covering, and the exact count is checked afterwards. No problems found.

Quality

  • Timing assertion (medium). The elapsed < 1.0 assertion in a_grid_of_equal_cells is likely to be flaky on loaded CI runners. The "About " prefix check already proves the estimate path ran. See the inline comment.

AGENTS.md

  • The PR follows the repository guidelines: it adds an engine test for gp.run and docs for the new tools, and it uses no unwrap or panic outside tests.
  • The tool labels and help text are plain strings in ToolSpec, so they are covered by the repo's existing tool-text handling.
  • I couldn't confirm that a5 builds for wasm32-unknown-unknown. It pulls in lazy_static, so CI should confirm it.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head 639147f)

Metric Value
Files changed 8 (1 added, 7 modified, 0 removed, 0 renamed)
Size before 856.7 KB
Size after 884.0 KB
Total size change +27.3 KB
File Before After Change
crates/analysis/src/dggs.rs 0 B 22.2 KB +22.2 KB
crates/analysis/src/tools.rs 69.1 KB 71.5 KB +2.4 KB
docs/user-guide/analysis.md 18.5 KB 19.7 KB +1.2 KB
crates/engine/src/tests.rs 581.7 KB 582.8 KB +1.2 KB
Cargo.lock 169.0 KB 169.2 KB +228 B
Cargo.toml 4.9 KB 5.0 KB +69 B
crates/analysis/Cargo.toml 440 B 466 B +26 B
crates/analysis/src/lib.rs 13.1 KB 13.1 KB +14 B

…utlines checked (opengeos#573 review)

- A cell across the antimeridian (or round a pole, when its ring turns past ±180°) is written as
  two parts of one polygon, each within −180° to 180°, so renderers and exporters draw both sides.
- Aggregate leaves out a point whose longitude is past ±360°, with the other unusable positions.
- An unknown area is refused instead of read as Map Extent.
- A polygon whose outline isn't a ring (under three corners, or not finite) is left out and
  counted in the message; a hole that isn't one is dropped.
- The wall-clock check in the cap test is gone: the estimate's "About" already shows the path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread crates/analysis/src/dggs.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

The PR adds two A5 DGGS tools, a5Grid and a5Aggregate, in a new crates/analysis/src/dggs.rs. The a5 dependency, docs and an engine test come with it. I read the whole diff but did not build the code or run the tests. The code follows the "never crash" rules: it uses get() and clamped sizes, has no unwrap or panic outside tests, and caps the cell count and the extent-ring steps.

Bugs

  • Low (medium-low confidence): grid with area: "Input Layer" on a polygon layer whose outlines are all unusable fails with "has no features to cover". The skipped count is lost, so the message doesn't say why. Posted inline.
  • Low (low confidence): Polygon coordinates outside ±180°/±90° go to a5::polygon_to_cells unclamped. The extent path is clamped by on_the_globe. The result is an A5 error or odd cells, not a panic, and I didn't find a test for it.
  • Nit (low confidence): The skip message always says "polygons". It counts polygons, but the wording could confuse for multipolygon features.

Security

  • Nothing found. Input is validated, the cell count is capped at 200,000, and the pre-cover estimate refuses oversized requests before A5 does the work.

Performance

  • Nothing significant. estimate runs before covering. cells_of counts before it expands. The by map is capped during aggregation.

Quality

  • ring unwraps longitudes with while loops. They terminate for the finite values A5 returns, but a rem_euclid-style step would be safer if a5's output ever changes. This is a nit (low confidence).
  • The tests are thorough: equal areas, the cap and estimate, the antimeridian and poles, and the hostile cases.

AGENTS.md

  • Layering and wasm: no UI dependencies are added. a5 is pure Rust (its only dependency is lazy_static), so it should build for wasm, though I didn't confirm that.
  • The new tools fall under the existing hostile_params_never_panic coverage, assuming it enumerates TOOLS.
  • Tool names and labels are plain literals in ToolSpec, like the other tools there. The i18n catalog entries can wait for the maintainer.
  • No assets were added.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head e2a62c1).

Metric Value
Files changed 8 (1 added, 7 modified, 0 removed, 0 renamed)
Size before 856.7 KB
Size after 889.4 KB
Total size change +32.7 KB
File Before After Change
crates/analysis/src/dggs.rs 0 B 27.6 KB +27.6 KB
crates/analysis/src/tools.rs 69.1 KB 71.5 KB +2.4 KB
docs/user-guide/analysis.md 18.5 KB 19.8 KB +1.3 KB
crates/engine/src/tests.rs 581.7 KB 582.8 KB +1.2 KB
Cargo.lock 169.0 KB 169.2 KB +228 B
Cargo.toml 4.9 KB 5.0 KB +69 B
crates/analysis/Cargo.toml 440 B 466 B +26 B
crates/analysis/src/lib.rs 13.1 KB 13.1 KB +14 B

…pengeos#573 review)

- A polygon ring is usable only when its corners are longitudes and latitudes (within ±90°, and
  ±360° so a ring that runs on past the antimeridian is kept, and is covered across it).
- When every polygon part was left out, the error says so instead of "no features to cover".
- The messages count polygon parts, as a multipolygon's parts are counted one by one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread crates/analysis/src/dggs.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the diff and the changed files. I did not build the crate or run the tests. The PR adds two analysis tools, a5Grid and a5Aggregate, in a new crates/analysis/src/dggs.rs, plus the a5 dependency, docs and an engine test. It is generally careful. Non-test code has no unwrap, expect or panic. Sizes are clamped, inputs are validated, and the cell cap is checked before cells are materialised.

Bugs

  • Low confidence: the pre-count in cells_of (dggs.rs:269) adds up cells across all covering polygons before de-duplicating them. A layer of overlapping polygons can be refused as "too many" even when the final de-duplicated grid would fit under MAX_CELLS. The estimate guard behaves the same way, but it has a 2× margin. This is posted as an inline comment.

Security

  • Nothing found. Layer data and parameters are treated as untrusted: resolution, area and containment are validated, coordinates are range-checked, the output name is truncated, and cell counts are capped before any large allocation.

Performance

  • Nothing significant. The cheap estimate rejects huge areas before polygon_to_cells runs. Up to about 400k cells can still be covered in the margin before the exact check applies, which looks acceptable.

Quality

  • Nit: "its 1 polygon parts" and similar messages are not pluralised correctly (dggs.rs:336 and :364).
  • Test coverage is good: antimeridian and pole rings, estimate against exact count, hostile polygons, and an engine-level gp.run test.
  • I did not confirm that hostile_params_never_panic in crates/engine/src/tests.rs picks up the new tools. It iterates the tool registry, so it probably does.

AGENTS.md

  • The a5 crate adds lazy_static. I could not verify that it builds for wasm32-unknown-unknown, which the repo requires. CI covers it.
  • Interface text and translations: the tool labels and help are plain literals in tools.rs, like the neighbouring tools, so this looks consistent.
  • Docs were updated in docs/user-guide/analysis.md, and no assets were added.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head edb84e6).

Metric Value
Files changed 8 (1 added, 7 modified, 0 removed, 0 renamed)
Size before 856.7 KB
Size after 891.1 KB
Total size change +34.4 KB
File Before After Change
crates/analysis/src/dggs.rs 0 B 29.3 KB +29.3 KB
crates/analysis/src/tools.rs 69.1 KB 71.5 KB +2.4 KB
docs/user-guide/analysis.md 18.5 KB 19.8 KB +1.3 KB
crates/engine/src/tests.rs 581.7 KB 582.8 KB +1.2 KB
Cargo.lock 169.0 KB 169.2 KB +228 B
Cargo.toml 4.9 KB 5.0 KB +69 B
crates/analysis/Cargo.toml 440 B 466 B +26 B
crates/analysis/src/lib.rs 13.1 KB 13.1 KB +14 B

 review)

Each covering is counted exactly before its cells are made, and coverings are merged as they
come, so the cells that overlapping polygons share count once against the cap. The left-out
messages read right in the singular.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread crates/analysis/src/dggs.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

The PR adds two A5 DGGS tools, a5Grid and a5Aggregate, in a new crates/analysis/src/dggs.rs, with registry entries, docs, and an engine test. I read the diff and the changed files but did not run the code, tests or CI. The code follows the repository's "never crash" rules in non-test code: it uses get(), clamps sizes, checks finite values, and refuses oversized runs before covering them. I found one issue worth raising, posted as an inline comment.

Bugs

  • None found. I checked the antimeridian and pole splitting in ring and parts, the ring validation in usable, the resolution parsing, and the hole handling. They look correct.

Security

  • None. Input is validated and bounded (MAX_CELLS, ESTIMATE_MARGIN, name and area strings truncated). a5 = "1" is a new third-party dependency (pure Rust, depends only on lazy_static). I did not check that it builds for wasm32-unknown-unknown.

Performance

  • cells_of can go quadratic (medium confidence). Once the vector is over MAX_CELLS, every following covering re-sorts and dedups all of it. Many small polygons that share cells would repeat that full sort per polygon. A HashSet, or deduping only after the vector has doubled, would avoid it. See the inline comment.

Quality

  • Nothing significant. The module is well documented and has thorough tests, including antimeridian, pole, overlap-dedup and hostile-input cases.
  • Minor: estimate is documented as rough and is tested to within 2×, which is acceptable because the exact count is checked afterwards.

AGENTS.md

  • Layering and the analysis crate's deny lints are respected, and no unwrap appears outside tests.
  • a5Grid and a5Aggregate are not covered by an analysis-level hostile-params test that I could see in the diff. The tools are registered in TOOLS, so the existing hostile_params_never_panic in the analysis crate may pick them up automatically. I did not verify that, so check it.
  • New tool labels are plain strings in the tool registry, like the existing tools, so no tl! is needed.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head 2e3cb39).

Metric Value
Files changed 8 (1 added, 7 modified, 0 removed, 0 renamed)
Size before 856.6 KB
Size after 892.9 KB
Total size change +36.3 KB
File Before After Change
crates/analysis/src/dggs.rs 0 B 31.2 KB +31.2 KB
crates/analysis/src/tools.rs 69.1 KB 71.5 KB +2.4 KB
docs/user-guide/analysis.md 18.5 KB 19.8 KB +1.3 KB
crates/engine/src/tests.rs 581.7 KB 582.8 KB +1.2 KB
Cargo.lock 169.0 KB 169.2 KB +228 B
Cargo.toml 4.9 KB 5.0 KB +69 B
crates/analysis/Cargo.toml 440 B 466 B +26 B
crates/analysis/src/lib.rs 13.1 KB 13.1 KB +14 B

…tay linear (opengeos#573 review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread crates/analysis/src/dggs.rs Resolved
Comment thread crates/analysis/src/tools.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

The PR adds the A5 Grid and Aggregate Points to A5 tools. It follows the repo's rules: no unwrap/panic outside tests, bounded cell counts, and a rough estimate that refuses oversized areas before covering them. It also handles the antimeridian, the poles, and polygons with unusable rings. I read the diff only; I did not build or run any tests.

Bugs

  • Wrong example cell areas (medium confidence). The help text and docs say resolution 5 cells are about 33,000 km², resolution 9 about 130 km² and resolution 12 about 2 km². With 12·4^res cells covering the Earth, the figures should be about 41,500, 162 and 2.5 km². The PR's own test asserts that relationship. The wrong figures are in crates/analysis/src/tools.rs:168 and docs/user-guide/analysis.md. I commented on tools.rs only; the same figures are in the docs paragraph.
  • MultiPoint value counted per point (low–medium confidence). In aggregate, a MultiPoint feature adds its field value once per point, so _sum and _mean count one attribute several times. Count it once per cell or document the behaviour (dggs.rs:409).

Security

  • Nothing found. Cell counts are capped at 200,000, input coordinates are validated, and resolution is bounded to 0–30.

Performance

  • Nothing significant. The estimate-then-exact-count approach avoids covering huge areas. cells_of keeps a HashSet of up to 200,000 cells, which is fine.

Quality

  • Nothing worth raising beyond the two findings above. The tests are thorough.

AGENTS.md

  • No violations found. The tool strings are data in the tool registry, and the new a5 dependency is pure Rust. I did not run a wasm build.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head e8e93c3)

Metric Value
Files changed 8 (1 added, 7 modified, 0 removed, 0 renamed)
Size before 856.7 KB
Size after 892.9 KB
Total size change +36.2 KB
File Before After Change
crates/analysis/src/dggs.rs 0 B 31.1 KB +31.1 KB
crates/analysis/src/tools.rs 69.1 KB 71.5 KB +2.4 KB
docs/user-guide/analysis.md 18.5 KB 19.8 KB +1.3 KB
crates/engine/src/tests.rs 581.7 KB 582.8 KB +1.2 KB
Cargo.lock 169.0 KB 169.2 KB +228 B
Cargo.toml 4.9 KB 5.0 KB +69 B
crates/analysis/Cargo.toml 440 B 466 B +26 B
crates/analysis/src/lib.rs 13.1 KB 13.1 KB +14 B

 review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff and the surrounding code. I didn't build the code or run the tests. The PR adds the A5 Grid and Aggregate Points to A5 tools on the a5 crate, with docs and tests. The code is careful and follows the repo rules. It has no unwrap/expect/panic in non-test code, it caps cell counts, and it checks the resolution. Only minor concerns remain, so I posted no inline comments.

Bugs

  • Duplicate vertices when a vertex sits exactly on ±180° (dggs.rs, clip, low confidence ~35%). The inside test is inclusive on both sides (<= and >=). A vertex with x == edge lands in both the near and far parts. This should only add a repeated point, not a wrong shape. Real A5 boundaries rarely land exactly on ±180°.
  • Area estimate for rings spanning more than a hemisphere (dggs.rs, estimate, low confidence ~30%). The ring area uses abs() of the signed area. A user polygon enclosing more than half the globe, or with edges longer than 180° of longitude, is ambiguous. The estimate could then be too low, and the guard that skips covering would not fire. The exact cells_of count still enforces the cap afterwards, but only after a5::polygon_to_cells has already done the expensive work. The risk is slow runs, not wrong output.
  • No bound on the number of features or polygons in the input (dggs.rs, grid, low confidence ~30%). The per-polygon estimates are summed, but each shape is only covered after that sum passes. A layer with very many tiny polygons can still spend a long time in polygon_to_cells calls before cells_of ends the run. Consider stopping the covering loop once the running cells.len() passes MAX_CELLS.

Security

  • No issues. Parameters are validated: the resolution is a finite whole number from 0 to 30, the area is one of three choices, strings are truncated, and cell counts are capped.

Performance

  • credited: Vec<u64> with contains in aggregate is O(k²) for a multipoint with k points in the same cell. A multipoint with hundreds of thousands of points would be slow. A HashSet, or reusing a "last credited cell" check, would fix it. Confidence ~40%.
  • cells_of collects everything into a HashSet and then sorts. That is fine at the 200k cap.

Quality

  • parts() can return one part when the other has fewer than 4 points. It silently drops that part, so the cell loses area. Probably harmless, but a comment would help.
  • The grid function is long, with the area selection, shape collection and covering all in one body. Pulling out a shapes_for(area, …) helper would make it easier to read.
  • usable accepts |x| <= 360, but A5 is then given longitudes up to ±360. The tests cover rings past the antimeridian, so this appears intentional.
  • In the engine test, total as usize on an f64 is fine in test code.

AGENTS.md

  • Layering and wasm: the new a5 dependency lives in rustgis-analysis (L2), not in an egui crate. I couldn't confirm that a5 builds for wasm32-unknown-unknown. It depends only on lazy_static, so it probably does, but CI should confirm it.
  • Hostile params: the engine test hostile_params_never_panic should cover the new tools automatically, since they sit in the TOOLS registry. The PR has no explicit regression test for junk parameters on a5Grid or a5Aggregate, though the resolution and area checks are tested.
  • Translations: the tool names and labels are plain &str in ToolSpec, like the other tools, so no tl! change is needed.
  • Attribution: the new third-party crate a5 is not an asset, so ATTRIBUTION.md doesn't apply. Check whether the repo's license policy for dependencies needs a licence check, for example cargo deny.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head e79e330).

Metric Value
Files changed 8 (1 added, 7 modified, 0 removed, 0 renamed)
Size before 856.7 KB
Size after 894.0 KB
Total size change +37.3 KB
File Before After Change
crates/analysis/src/dggs.rs 0 B 31.9 KB +31.9 KB
crates/analysis/src/tools.rs 69.1 KB 71.7 KB +2.6 KB
docs/user-guide/analysis.md 18.5 KB 19.9 KB +1.4 KB
crates/engine/src/tests.rs 581.7 KB 582.8 KB +1.2 KB
Cargo.lock 169.0 KB 169.2 KB +228 B
Cargo.toml 4.9 KB 5.0 KB +69 B
crates/analysis/Cargo.toml 440 B 466 B +26 B
crates/analysis/src/lib.rs 13.1 KB 13.1 KB +14 B

…or credited cells (opengeos#573 review)

- cells_of takes the coverings as they're made, so a layer of many polygons stops at the one
  that takes the run over the cap instead of covering them all first.
- Aggregate tracks the cells a multipoint's value went to in a set, not a list.
- parts says why a side with fewer than four points is left out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread crates/analysis/src/dggs.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff and the surrounding code, and I flagged one possible bug. I had no Bash tool and no network, so I couldn't build the code, run the tests or read the a5 crate source.

Bugs

  • Possible u64 overflow in cells_of, crates/analysis/src/dggs.rs:271 (medium-low confidence). A5 has 60·4^res cells. At resolution 30 that is about 6.9e19, which is above u64::MAX (about 1.8e19). a5::get_num_cells(res) may therefore overflow. The area: "World" path reaches cells_of at resolution 30 without going through the estimate guard. A release build would wrap quietly and a debug build would panic. I posted an inline comment suggesting an f64 pre-check or checked_* arithmetic, plus a regression case in hostile_params_never_panic.

Security

  • Nothing found. Input is bounded: resolution is validated, cell counts are capped at 200,000, and the estimate refuses oversized areas before any covering runs. Out-of-range coordinates are filtered, and get() is used instead of indexing.

Performance

  • Nothing blocking. The pre-estimate with ESTIMATE_MARGIN and the per-covering cap check keep work bounded. A layer with very many polygons that each stay under the cap is only limited by the merged-set check after each covering (low confidence that this matters).

Quality

  • The code is clear and well commented. The tests are thorough: antimeridian and pole splits, overlap deduplication, and estimate against exact count.
  • Minor: ring() decides a pole cell by summing latitudes (sum > 0). That works, but comparing the first latitude's sign, or the pole nearest the centre, would say more directly what it means (low confidence, nit).

AGENTS.md

  • There is no unwrap, expect, panic! or unsafe in non-test code. These calls appear only in #[cfg(test)], which matches existing practice.
  • Docs were updated, and the new tools are registered in tools.rs, which means the hostile-parameter sweep covers them.
  • a5 is a pure-Rust crate. I couldn't confirm it builds for wasm32-unknown-unknown, so CI needs to check that.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head d745d77)

Metric Value
Files changed 8 (1 added, 7 modified, 0 removed, 0 renamed)
Size before 856.7 KB
Size after 894.2 KB
Total size change +37.5 KB
File Before After Change
crates/analysis/src/dggs.rs 0 B 32.1 KB +32.1 KB
crates/analysis/src/tools.rs 69.1 KB 71.7 KB +2.6 KB
docs/user-guide/analysis.md 18.5 KB 19.9 KB +1.4 KB
crates/engine/src/tests.rs 581.7 KB 582.8 KB +1.2 KB
Cargo.lock 169.0 KB 169.2 KB +228 B
Cargo.toml 4.9 KB 5.0 KB +69 B
crates/analysis/Cargo.toml 440 B 466 B +26 B
crates/analysis/src/lib.rs 13.1 KB 13.1 KB +14 B

…ed (opengeos#573 review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread crates/analysis/src/dggs.rs Resolved
Comment thread crates/analysis/src/dggs.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I found no blocking issues. The PR adds the A5 Grid and Aggregate Points to A5 tools, the a5 dependency, tests and docs. Hostile-input handling is thorough and follows the repo's never-crash rules.

I read the diff and dggs.rs but did not build the code or run any tests.

Bugs

  • None found.

Security

  • None found. Input is bounded: resolution is validated to 0–30, coordinates are checked for finiteness and range, output names are truncated, and cell counts are capped at 200k (counted before cells are made, with an area-based estimate beforehand).

Performance

  • Low confidence: crates/analysis/src/dggs.rs:275. polygon_to_cells runs in full for each shape before the cap check. The pre-estimate only bounds the total roughly, and it treats edges as great circles. A layer with many mid-sized polygons could still cost a lot of time before the cap trips.

Quality

  • Low confidence: crates/analysis/src/dggs.rs:393. aggregate rejects any layer whose geometry type isn't Point, yet it handles MultiPoint features. Either accept both types or drop that arm.
  • Nit: the tests use unwrap, expect and panic!. That is allowed in test code, so there is no action needed.

AGENTS.md

  • No unwrap, expect or panic in non-test code. The crate-root deny block still applies.
  • There are no user-visible strings in new UI code. The tool specs follow the existing ToolSpec pattern, and the engine-level gp.run test is added.
  • a5 is pure Rust and added in the analysis crate, so I expect it to build for wasm. I didn't verify this.
  • No assets were added. The docs are updated.

Change size

Compared: the whole PR against main (merge base 98921c3 to PR head cbce40a)

Metric Value
Files changed 8 (1 added, 7 modified, 0 removed, 0 renamed)
Size before 856.7 KB
Size after 894.5 KB
Total size change +37.9 KB
File Before After Change
crates/analysis/src/dggs.rs 0 B 32.4 KB +32.4 KB
crates/analysis/src/tools.rs 69.1 KB 71.7 KB +2.6 KB
docs/user-guide/analysis.md 18.5 KB 19.9 KB +1.4 KB
crates/engine/src/tests.rs 581.7 KB 582.8 KB +1.2 KB
Cargo.lock 169.0 KB 169.2 KB +228 B
Cargo.toml 4.9 KB 5.0 KB +69 B
crates/analysis/Cargo.toml 440 B 466 B +26 B
crates/analysis/src/lib.rs 13.1 KB 13.1 KB +14 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-573/
Web app https://preview.rustgis.app/pr-573/app/
Commit cbce40a

GitHub Pages takes a minute or two to publish a new commit.

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.

[Feature]: A5 equal-area grids: build a grid and aggregate points by cell (#77, "H3 and DGGS grids")

3 participants