Skip to content

perf(analysis): Largest overlap measures a line's steps without a solve each - #2754

Merged
Mavrick-F merged 1 commit into
opengeos:mainfrom
Mavrick-F:perf/overlap-line-steps
Nov 23, 2026
Merged

Mavrick-F merged 1 commit into
opengeos:mainfrom
Mavrick-F:perf/overlap-line-steps

Conversation

@Mavrick-F

@Mavrick-F Mavrick-F commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Spatial Join's Largest overlap ranks a line target's overlaps by their length on the WGS 84 ellipsoid (#2730). join::length_m summed a GeographicLib inverse solve for every segment. #2730 said that cost was small next to the overlay, but that was measured for areas only. For a line, the clip is a single pass over the vertices, and the solves cost more than the clip they measure. length_m now measures each step with rustgis_geom::wgs84_step_m, as a route's steps are measured since #2730. That uses the ellipsoid's radii of curvature at the step's mean latitude, within a millionth of the solve for steps up to 0.05° below 89°, and is the solve itself for longer steps and steps by a pole.

On a line of 300,000 vertices (steps of 1e-5° in longitude, about a metre) clipped by six zones, three runs each on this box:

before after
join::length_m over the line, dev 185–220 ms 14–19 ms
join::length_m over the line, release 112–128 ms 15–22 ms
the whole Spatial Join run, dev 602–684 ms 305–390 ms
the whole Spatial Join run, release 353–432 ms 356–406 ms

The release runs of the whole join shared the box with another build, so their spread is wider than the 100 ms the length step saves there. The zone chosen and the length agree: 6,354,720.6485 m from the solve, 6,354,720.6485 m from the steps, a difference of 1e-5 m. The probe was a throwaway test, not part of this pull request.

Nothing else changes: areas keep the polygon pass, and projected runs keep their plane's length.

Surfaces: Spatial Join runs the same from the desktop, the browser, the command line, Python, the Assistant and MCP. No parameters, output fields or saved data change.

Testing

  • join::tests::largest_overlap_ranks_overlaps_on_the_ellipsoid gains a dense road, 0.01° steps along a meridian. Each overlap's length agrees with wgs84_length_m to within a millionth, the tolerance the routing test uses, and the same zone wins as for the two-vertex road. With each step's length made 2e-6 too long, it fails with 110574.60970375789 m, 110574.38855779874 m on the ellipsoid.
  • cargo test -p rustgis-analysis --lib join:: (41 passed), cargo clippy -p rustgis-analysis --all-targets -- -D warnings, and the full CI on the fork.

Related issue

Follows up a review point on #2730 (#2730 (comment)).

Summary by CodeRabbit

  • Bug Fixes
    • Improved distance calculations for detailed routes, bringing reported lengths closer to their geodesic lengths.
    • Improved length comparisons for overlap results involving dense road geometry.

…ve each

join::length_m summed a geodesic solve per segment. On a dense line
target that cost more than the clip it measured: a 300,000-vertex line
over six zones spent about 200 ms in it (dev). It now measures each step
with wgs84_step_m, within a millionth of the solve, and the solve itself
for long steps and steps by a pole.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

length_m now sums WGS84 step distances between consecutive coordinates. The documentation describes its accuracy for dense lines, and the Largest overlap test adds dense-road coverage and compares step-based lengths with geodesic lengths.

Changes: Largest overlap length

Layer / File(s) Summary
Step-based length and validation
crates/analysis/src/join.rs
length_m sums wgs84_step_m for consecutive coordinates. Tests compare dense-section lengths with geodesic lengths and check that the dense road selects the northern zone.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related issues

  • [Enhancement]: geodesic stand-point #2568: The issue identifies the Largest overlap measurement in join.rs as using a spherical or haversine measurement. This change updates that measurement to use WGS84 step distances and compares them with geodesic lengths. Other measurement paths named in the issue are not changed.

Suggested reviewers: elpidioassinaturas, pick2510

Merge Risk: Minimal · up to 19aac

This change speeds up the largest-overlap length measurement on dense lines while keeping results within a millionth of the geodesic solve. No outputs or saved data change, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Largest overlap now measures line steps with wgs84_step_m instead of a geodesic solve per segment, and it is tagged as perf(analysis). It is specific and matches the s…
Description check Passed The description follows the template. It has a Summary that explains the change and why, with benchmark figures. It has a Testing section that names the new dense-road test, the cargo commands, and th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: Largest overlap now measures line steps with wgs84_step_m instead of a geodesic solve per segment, and it is tagged as perf(analysis). It is specific and matches the summary, objectives, and description. It is a single sentence of 11 words.

Full details: Description check

Explanation

The description follows the template. It has a Summary that explains the change and why, with benchmark figures. It has a Testing section that names the new dense-road test, the cargo commands, and the clippy run. It has a Related issue section that references the follow-up review point on #2730. The UI evidence section is absent, but the change has no visible UI effect. The author does not say 'No visible UI change.' in that section, so the template's required line is missing. The author instead notes that no parameters, output fields, or saved data change, and the surfaces are unchanged. That is a minor gap. The Related issue entry is a link to a review comment, not an issue reference like 'Closes #' or 'Part of #', which is a minor gap as well.

Resolution

Optionally add the template line 'No visible UI change.' under the UI evidence heading, and optionally state the related issue or PR in the 'Part of' or 'Follows up' form the template expects.

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 hops along the line,
Each step measured, neat and fine.
Dense roads pass the length test true,
The northern zone comes into view.
Then carrots mark the join complete.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: b443832e-8707-4fe5-938c-92670f1b90a0
Commits

Reviewing files that changed from the base of the PR and between 7985435 and 19aacd2.

Files selected for processing: 1

  • crates/analysis/src/join.rs

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

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff, the base-branch AGENTS.md, and the surrounding code in crates/geom/src/lib.rs (wgs84_step_m, wgs84_distance_m, wgs84_length_m), crates/analysis/src/tools.rs (the overlap caller), and the existing geom test wgs84_steps_agree_with_the_geodesic. I checked the step formula by hand: the radii of curvature are right, the mean-latitude error is second order in the step size, and the 89° and 0.05° fallbacks cover poles and long steps. I could not compile or run the tests here (no shell), so this is a read-only review.

Bugs: None found (confidence high, about 90%). Non-finite input still gives NaN, and out-of-range latitudes still clamp, through the same fallback path as before. The projected path is untouched.

Security: None found.

Performance: None new. The change replaces a geodesic solve per segment with a few multiplications for short steps, which matches the PR's measurements. Only one caller (tools.rs:7197), and the geographic branch only.

Quality:

  • The new join test uses only meridian steps (dlon = 0), so it does not exercise the across-track (cos φ) term of wgs84_step_m. The geom test does cover that term, so this is a minor gap, not a missing check. Left for the release quality pass.
  • The _ => 0.0 arm in length_m can't be reached, since windows(2) always yields two elements. It mirrors wgs84_length_m, so it's harmless. No change needed.

AGENTS.md: No violations found.

  • No unwrap, expect, or direct indexing in non-test code.
  • No new stored copy of layer data, so the memory rule does not apply.
  • No silent data loss, because NaN propagates as before.
  • No new command, tool or background path, so the cancellation lists don't apply.
  • The new test uses a computed ratio, not identical assert sides.
  • wgs84_step_m is pure math in geom, so the wasm build is unaffected.
  • The import line is 137 characters, under the 140 max_width.

Prior review threads: none on this PR, so no concerns were left alone.

Change size

Compared: the whole PR against main (merge base 2b9fc33 to PR head 19aacd2).

Measure Value
Files changed 1 (added 0, modified 1, removed 0, renamed 0)
Size before 35.6 KB
Size after 36.7 KB
Total size change +1.1 KB
Path Before After Change
crates/analysis/src/join.rs 35.6 KB 36.7 KB +1.1 KB

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2754/
Web app https://preview.rustgis.app/pr-2754/app/
Commit 19aacd2

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

@Mavrick-F
Mavrick-F added this pull request to the merge queue Nov 23, 2026
Merged via the queue into opengeos:main with commit 25f3b18 Nov 23, 2026
27 checks passed
@Mavrick-F
Mavrick-F deleted the perf/overlap-line-steps branch November 23, 2026 03:53
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