Skip to content

fix(analysis): reject geocentric CRS in Kernel Density - #2035

Merged
Mavrick-F merged 1 commit into
opengeos:mainfrom
choupeanut:codex/2008-kernel-density-geocentric
Nov 14, 2026
Merged

Mavrick-F merged 1 commit into
opengeos:mainfrom
choupeanut:codex/2008-kernel-density-geocentric

Conversation

@choupeanut

@choupeanut choupeanut commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Kernel Density now refuses geocentric coordinate systems before transforming points or making its raster. Its calculation uses a two-dimensional projected plane, while systems such as EPSG:4978 describe three-dimensional X/Y/Z coordinates. The existing geographic-CRS check did not exclude them, and equatorial points can pass a two-coordinate round trip even after Z has been dropped.

The check covers both an explicit crs and the layer's default coordinate system. The error explains the distinction and points to a projected system such as UTM. The guide documents the same rule. An explicit projected target can still override the layer's default CRS.

No dependencies, tool parameters or data-model changes. No other project's code was followed or copied. This addresses only the Kernel Density geocentric-CRS finding in #2008; the remaining audit items are outside this PR.

Testing

  • cargo test -p rustgis-analysis --lib kernel_density_: 8 passed, including the new regression.
  • Regression covers EPSG:4978 and a custom geocentric PROJ definition, each supplied explicitly and inherited from the layer. It also checks successful projected runs before and after a layer's default is set to geocentric.
  • cargo xtask ci: passed (fmt, Clippy with -D warnings, workspace tests: 6,452 passed / 23 ignored, layers).
  • pre-commit run --all-files: all hooks passed.
  • cargo check --locked --target wasm32-unknown-unknown -p rustgis-analysis: passed.

UI evidence

No visible UI change.

Related issue

Part of #2008 (section 2: Reject geocentric CRS in kernelDensity). Does not close the tracking issue.

Summary by CodeRabbit

  • Bug Fixes
    • Kernel Density now reports an error when the selected or inherited coordinate system is geocentric, requiring a projected system with linear units. An explicitly selected projected system remains supported when the input layer uses a geocentric system.
  • Documentation
    • Updated the Kernel Density guide to clarify which coordinate systems are accepted.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Kernel Density now rejects geocentric coordinate systems supplied explicitly or inherited from the input layer. Regression tests cover accepted projected CRSs and rejected geocentric CRSs. The user guide documents this behavior.

Changes: Kernel Density CRS validation

Layer / File(s) Summary
Geocentric CRS validation and coverage
crates/analysis/src/tools.rs, docs/user-guide/analysis.md
kernel_density_tool rejects geocentric CRSs and directs users to provide a projected CRS. Tests cover explicit and inherited CRS values, including an explicit projected CRS with a geocentric input layer. The user guide documents the restriction.

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

Change: Bug fix

Suggested reviewers: pick2510, mavrick-f

Merge Risk: Minimal · up to 453e3

Kernel Density now rejects geocentric coordinate systems with a clear error that points users to a projected system. No concrete merge-blocking risk was found, and the change is narrow and easy to revert.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the primary change, rejecting geocentric CRS in Kernel Density. It is short, specific, and follows the conventional type(scope) prefix. It matches the code change in crates/analysis/sr…
Description check Passed The description follows the template. The Summary section explains the change and its reasons. The Testing section lists the commands run and their results. The UI evidence section states 'No visible …
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 primary change, rejecting geocentric CRS in Kernel Density. It is short, specific, and follows the conventional type(scope) prefix. It matches the code change in crates/analysis/src/tools.rs and the matching docs update.

Full details: Description check

Explanation

The description follows the template. The Summary section explains the change and its reasons. The Testing section lists the commands run and their results. The UI evidence section states 'No visible UI change.', as the template allows. The Related issue section references #2008 and says it does not close the tracking issue. All required sections are present and substantively filled.

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 checks the map at dawn,
And finds the geocentric path withdrawn.
A projected route is clear and bright,
Tests keep each CRS case right.
The guide records what tools now do,
Then hops along beneath the blue.

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: 12b99bb4-af4c-42d9-9793-b544aebd9200
Commits

Reviewing files that changed from the base of the PR and between d00276e and 453e308.

Files selected for processing: 2

  • crates/analysis/src/tools.rs
  • docs/user-guide/analysis.md

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

));
};

if crs.is_geocentric() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium confidence (~70%), defense in depth. This guard lives only in kernel_density_tool. density::kernel_density (crates/analysis/src/density.rs, around line 305) is re-exported as pub from lib.rs, and its own CRS check still only tests is_geographic(). A geocentric Crs given to that function is gridded as a 2-D plane, which is the failure this PR describes. Adding if crs.is_geocentric() { return Err(...) } next to the geographic check there would keep every caller on one rule, and a test beside the existing geo_crs case would pin it.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • None found. The new geocentric guard at crates/analysis/src/tools.rs:4788 runs after the CRS is resolved, so it covers both an explicit crs and the layer default. It sits before the geographic check, and an explicit projected crs still overrides a geocentric layer, as the test asserts. Confidence: high.

Security

  • None found. No new input paths, parsing, or dependencies. Confidence: high.

Performance

  • None found. Confidence: high.

Quality

  • Public entry point missing the same guard (medium, ~70%). density::kernel_density (crates/analysis/src/density.rs, around line 305) is re-exported as pub from crates/analysis/src/lib.rs. Its own CRS check still only tests is_geographic(), so a geocentric Crs passed directly is gridded as a 2-D plane. Adding if crs.is_geocentric() { return Err(...) } next to that check, plus a test beside the existing geo_crs case, would keep every caller on one rule. Posted inline at crates/analysis/src/tools.rs:4788, because density.rs is not part of the PR diff.
  • Nit: the inherited-layer message doesn't name the layer. When the geocentric system comes from the layer default, the message says "Provide a projected system under 'crs'" but doesn't say which layer or where the system came from. The geographic branch names the layer (ds.name). Left for the release quality pass.

AGENTS.md

  • No unwrap/panic in non-test code; the test's unwrap calls follow the file's existing test style.
  • No new command, so long_commands_stop_when_cancelled_while_they_run needs no change; Kernel Density is already in its list.
  • Error strings are plain literals. The analysis crate has no tl! calls anywhere, so this matches local convention.
  • Docs in docs/user-guide/analysis.md match the code's behaviour.
  • The kernelDensity path also falls under the hostile-params test. The new branch returns an error and cannot panic.
  • Confidence: high.

I did not run the tests. I checked the test's key assumption by reading: EPSG:4978 is treated as geocentric elsewhere in the repo (crates/engine/src/tests.rs:11292).

Prior review threads: none. Nothing was re-raised, so zero earlier concerns were left alone.

Change size

Compared with the base branch: the whole PR against main (merge base 7c377ff to PR head 453e308).

Measure Value
Files changed 2 (0 added, 2 modified, 0 removed, 0 renamed)
Size before 975.4 KB
Size after 977.6 KB
Total size change +2.1 KB
Path Before After Change
crates/analysis/src/tools.rs 828.2 KB 830.1 KB +1.9 KB
docs/user-guide/analysis.md 147.2 KB 147.4 KB +234 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2035/
Web app https://preview.rustgis.app/pr-2035/app/
Commit 453e308

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

@Mavrick-F
Mavrick-F merged commit 37d3f56 into opengeos:main Nov 14, 2026
18 checks passed
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.

2 participants