Skip to content

fix(analysis): take a projected DEM's cells in feet as metres in Viewshed, Measure volume and the mosaic (#3346) - #3369

Merged
elpidioassinaturas merged 1 commit into
opengeos:mainfrom
elpidioassinaturas:fix/3346-feet-cells
Nov 29, 2026
Merged

elpidioassinaturas merged 1 commit into
opengeos:mainfrom
elpidioassinaturas:fix/3346-feet-cells

Conversation

@elpidioassinaturas

@elpidioassinaturas elpidioassinaturas commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

What

Raster::cell_size_m returns a projected raster's cell in its system's own unit, which slope, aspect, hillshade and the shadows rely on. Three callers mixed that cell with values in metres. This adds Raster::cell_size_ground_m() beside it (the cell with a projected system's unit turned into metres) and uses it there only:

  • Viewshed: the radius in cells and the Earth's curvature (rasterops::viewshed), and the workflow's default radius, the raster's diagonal (workflows.rs).
  • Measure volume: the cell area behind cubicMetresAbove / cubicMetresBelow (imagery.rs).
  • Mosaic in longitude/latitude: the finest image's pixel in degrees (imagery.rs). On main an image in feet got a pixel 3.28 times coarser than its own (10 ft taken as 10 m), so about 10.8 times fewer cells, not more as the issue guessed.

cell_size_m itself doesn't change.

Tests (written first, failing on main)

  • a_viewshed_on_a_dem_in_feet_takes_its_radius_in_metres: the issue's table. On main EPSG:2263 sees 2,821 cells against 30,453 in EPSG:32618 on the same ground; now both see 30,453.
  • a_volume_on_a_dem_in_feet_is_in_cubic_metres: a box 10 high on 10 × 10 cells of 10 ft. On main 100,000 (ft² × height); now 9,290.34 m³, as in UTM.
  • a_mosaic_in_degrees_of_an_image_in_feet_keeps_its_pixel: on main 0.0001185° against the image's own 0.0000361°.

Closes #3346

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved distance and area-related calculations for projected raster data measured in feet, including viewsheds and volume measurements.
    • Corrected imagery mosaic resolution handling so source pixel sizes are better preserved when working with geographic coordinates.
    • Equivalent raster data in feet and metres now produces more consistent viewshed and volume results.

…shed, Measure volume and the mosaic (opengeos#3346)

Raster::cell_size_ground_m() gives the cell with a projected system's
unit turned into metres. Viewshed (radius, curvature, default diagonal),
Measure volume (cubic metres) and the longitude/latitude mosaic's finest
pixel use it; cell_size_m keeps the coordinates' unit for the terrain
functions.

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

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds Raster::cell_size_ground_m() and uses it in viewshed distance calculations, volume measurements, and mosaic resolution selection. Regression tests cover equivalent rasters in metres and US survey feet.

Changes: Ground-unit cell dimensions

Layer / File(s) Summary
Raster cell-size conversion
crates/data/src/raster/mod.rs
Raster::cell_size_ground_m() converts projected cell dimensions to metres and leaves geographic cell dimensions unchanged.
Viewshed distance calculations
crates/analysis/src/rasterops.rs, crates/engine/src/cmd/workflows.rs
Viewshed calculations use ground cell dimensions. A regression test compares visible-cell counts for equivalent flat DEMs in metres and US survey feet.
Volume and mosaic calculations
crates/engine/src/cmd/imagery.rs, crates/engine/src/tests.rs
Volume measurements and mosaic resolution selection use ground cell dimensions. Tests check volume consistency across units and mosaic resolution for a foot-based source.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • opengeos/RustGIS#1789: Changes Viewshed radius validation and height sampling, which overlap with the radius handling updated here.

Suggested reviewers: giswqs, deniial00, mavrick-f

Merge Risk: Minimal · up to a19b6

This change makes viewshed, volume and mosaic results correct for rasters in feet. Terrain functions are not touched. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and its three affected areas: Viewshed, Measure volume, and the mosaic. The PR adds Raster::cell_size_ground_m() and uses it in those callers so that projected DEM cell sizes i…
Description check Passed The description follows the template well. Summary covers what changed and why, including the rule that cell_size_m is unchanged. Testing lists three named regression tests with before and after value…
Linked Issues check Passed [#3346] Requirements: (1) keep cell_size_m() unchanged; (2) convert projected cell sizes to metres at Viewshed, Measure volume and the longitude/latitude mosaic's finest pixel; (3) Viewshed visible-ce…
Out of Scope Changes check Passed The summary shows changes only in crates/data/src/raster/mod.rs (new helper), crates/analysis/src/rasterops.rs (viewshed_on), crates/engine/src/cmd/workflows.rs (default radius), crates/engine/src/cmd…
Full details: Title check

Explanation

The title names the fix and its three affected areas: Viewshed, Measure volume, and the mosaic. The PR adds Raster::cell_size_ground_m() and uses it in those callers so that projected DEM cell sizes in feet are taken as metres. The title is specific and matches the main change. Its length (112 characters) is long, but the content is accurate.

Full details: Description check

Explanation

The description follows the template well. Summary covers what changed and why, including the rule that cell_size_m is unchanged. Testing lists three named regression tests with before and after values. The UI evidence section states no visible UI change, as the template allows. Related issue is filled in with Closes #3346. Minor gap: the template asks for how verification was run (for example cargo xtask ci), and the description does not state that command or a full CI run.

Full details: Linked Issues check

Explanation

[#3346] Requirements: (1) keep cell_size_m() unchanged; (2) convert projected cell sizes to metres at Viewshed, Measure volume and the longitude/latitude mosaic's finest pixel; (3) Viewshed visible-cell counts match for EPSG:2263 and EPSG:32618 on the same ground; (4) volume matches across systems; (5) mosaic keeps the source pixel size. Evidence from the PR summary and description: Raster::cell_size_ground_m() is added in crates/data/src/raster/mod.rs and multiplies cell_size_m() by metres-per-unit for projected systems and by 1 for geographic systems. The summary lists no change to cell_size_m(). rasterops::viewshed_on (crates/analysis/src/rasterops.rs) uses the helper for its radius and curvature. workflows.rs viewshed_work uses it for the default diagonal radius. imagery.rs uses it for the volume cell area and the mosaic finest pixel. Regression tests cover the viewshed table, a box volume in feet, and a mosaic pixel from a foot-based image. Caveat: the diff blobs were unavailable in the checkout, so the code-level check relies on the PR summary and description, not on reading the changed hunks. Heights remain in the band's unit, which the issue leaves unchanged.

Full details: Out of Scope Changes check

Explanation

The summary shows changes only in crates/data/src/raster/mod.rs (new helper), crates/analysis/src/rasterops.rs (viewshed_on), crates/engine/src/cmd/workflows.rs (default radius), crates/engine/src/cmd/imagery.rs (volume and mosaic cell size) and crates/engine/src/tests.rs (regression tests). Each change serves a #3346 objective. No unrelated behaviour change appears in the summary. The unchanged cell_size_m() keeps the slope, aspect, hillshade and shadow paths as the issue requires. Caveat: the diff blobs were unavailable, so this rests on the summary and description.

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 raster’s feet,
And turns each cell to metres neat.
Viewsheds reach the distance asked,
Volume counts are checked and tasked.
Mosaics keep their pixels right,
Then hops away beneath moonlight.

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: 6bbb9fd0-0569-421a-bc82-a9570899ea8d
Commits

Reviewing files that changed from the base of the PR and between 446e0eb and a19b687.

Files selected for processing: 5

  • crates/analysis/src/rasterops.rs
  • crates/data/src/raster/mod.rs
  • crates/engine/src/cmd/imagery.rs
  • crates/engine/src/cmd/workflows.rs
  • crates/engine/src/tests.rs

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

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Scope: 5 files, one behavioural change. Raster::cell_size_ground_m() converts a projected raster's cell into metres and is used in Viewshed (rasterops.rs, workflows.rs), Measure volume (imagery.rs), and the mosaic's degree pixel (imagery.rs). Slope, aspect, hillshade and sky-view still use cell_size_m(). I found no prior review threads, so no earlier concerns were skipped.

Bugs

  • Viewshed mixes metres and DEM heights (rasterops.rs:906). Distances and the curvature term are now metres, but the DEM values and observer height are not converted. On a feet DEM whose elevations are in feet, the sight-line slope is about 3.3× too steep. This disagrees with slope, hillshade and sky-view, which keep heights in coordinate units. The flat test DEM has no relief, so it cannot catch this. Confidence: about 65%.
  • Measure volume assumes metres elevations (imagery.rs:3053). The cell area is metres, but dz is the DEM's own unit. The command's base parameter is documented as metres, so this may be intended. If the elevations are in feet, the volume is about 3.3× too small, and the test pins the metres assumption without saying so. Confidence: about 55%.

Security

  • None found.

Performance

  • None found. The change adds one unit lookup per call, outside the per-cell loops.

Quality

  • cell_size_ground_m and the existing cell_size_m_on(ground: &Extent) both use "ground" for different things. Consider a clearer name, such as cell_size_metres. Left for the release quality pass.
  • metres_per_unit returns 1.0 when a projected CRS has no conversion. A feet raster in that state is then treated as metres without a notice, which is a possible "Never silent" gap. Confidence: about 30%. Left for the release quality pass.

AGENTS.md

  • No rule is broken as far as I can see. There is no new command, so the surface snapshot, schema and fixtures are unaffected. Nothing new is stored, so the memory rules do not apply.

Checked, no change needed

  • The mosaic's degree path: for geographic rasters cell_size_m already returns metres and the unit factor is 1, so the degree pixel is unchanged.
  • Twins: viewshed is called only by analysis.viewshed and one analysis test. Volume is only reached through raster.measure. The degree mosaic is the only mosaic path that uses this value. write_surface (OBJ export) and the map render paths keep cell_size_m, which is correct for coordinate-unit output.
  • Not checked: whether the Assistant or MCP tool descriptions for raster.measure or the viewshed should mention feet-to-metres handling.

Change size

Compared with main (merge base f943424 to PR head a19b687).

Measure Value
Files changed 5 (0 added, 5 modified, 0 removed, 0 renamed)
Size before 4.45 MB
Size after 4.46 MB
Total size change +5.2 KB
File Before After Change
crates/engine/src/tests.rs 3.77 MB 3.78 MB +3.1 KB
crates/analysis/src/rasterops.rs 193.1 KB 194.6 KB +1.6 KB
crates/data/src/raster/mod.rs 158.9 KB 159.5 KB +562 B
crates/engine/src/cmd/imagery.rs 194.4 KB 194.4 KB +14 B
crates/engine/src/cmd/workflows.rs 146.8 KB 146.8 KB +7 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3369/
Web app https://preview.rustgis.app/pr-3369/app/
Commit a19b687

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).

@elpidioassinaturas
elpidioassinaturas added this pull request to the merge queue Nov 29, 2026
Merged via the queue into opengeos:main with commit 713d33a Nov 29, 2026
28 checks passed
@elpidioassinaturas
elpidioassinaturas deleted the fix/3346-feet-cells branch November 29, 2026 19:28
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.

[Bug]: Viewshed, Measure volume and the mosaic's finest pixel take a projected DEM's cells in feet as metres

2 participants