Skip to content

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

Done

Description

@elpidioassinaturas

What happens

Line numbers are on main at 5269b96.

Raster::cell_size_m (crates/data/src/raster/mod.rs:1379, cell_size_m_on at 1386) converts a geographic raster's degrees to metres, but returns a projected raster's cell in the system's own unit ((x, y) at line 1392). For a system in feet, such as EPSG:2263 (NAD83 / New York Long Island, US survey feet), a 10 ft cell comes back as 10.

For slope, aspect and hillshade that is deliberate and documented: "elevations must be in the same unit as the coordinates (feet aren't converted)" (docs/user-guide/analysis.md:1710). A DEM in feet with heights in feet then needs no Z factor. Shaded Relief, the cast shadows and the sky-view factor follow the same rule, and they should stay as they are.

Three callers mix that cell with values documented in metres:

  1. Viewshed. radius is "metres" (crates/engine/src/cmd/workflows.rs:68), but the radius in cells is radius_m / cx (crates/analysis/src/rasterops.rs:851–852), with cx, cy from cell_size_m at line 843. The ray distances built from them meet the Earth's curvature, dist * dist / (2.0 * SIGHT_RADIUS_M) (lines 905 and 928), with SIGHT_RADIUS_M in metres (line 655). The workflow's default radius, the raster's diagonal, comes from the same cells (workflows.rs:2071–2075). On a DEM in feet the radius is taken in feet, 3.28 times shorter than asked for, and the curvature is under-corrected.
  2. Measure volume. The answer's keys are cubicMetresAbove and cubicMetresBelow (crates/engine/src/cmd/imagery.rs:3062), but the cell area comes from cell_size_m (line 3027). It is converted only for a geographic raster (line 3029), so a DEM in feet gives square feet times the height.
  3. Mosaic in longitude/latitude. The finest image's pixel is turned into degrees as cx / (111_320.0 * cos(latitude)) (imagery.rs:3191–3192), which assumes cx is in metres. An image in feet gives a pixel 3.28 times finer than its own, so the default grid has about 10.8 times as many cells. This one I found by reading the code; I didn't run it.

Steps to reproduce (Viewshed)

A flat DEM of 200 × 200 cells at 10 m, observer at the centre, 1.7 m high, radius 300 m, nearest heights (rasterops::viewshed):

DEM Cell Visible cells
EPSG:32618 (UTM, metres) 3.048 m 30,453 (π × 98.4² cells: 300 m)
EPSG:2263 (US survey feet) 10 ft (the same 3.048 m) 2,821 (π × 30² cells: 300 ft, 91 m)

The same ground with the same radius sees a tenth of the cells.

Through the app: open a DEM in a state plane system in feet, run Viewshed with a radius of 1,000 m, and measure the visible area's extent: it reaches about 305 m.

Expected

radius, the curvature and cubicMetres… are in metres whatever unit the DEM's system uses. The mosaic's finest pixel is the image's own.

Proposed fix

Convert the horizontal cell size to metres at these three callers only, with the system's unit, as #3343 does for texture shading (crates/analysis/src/texture.rs):

let unit = if r.crs.is_geographic() { 1.0 } else { r.crs.metres_per_unit() };
let (cx, cy) = r.cell_size_m();
let (cx, cy) = (cx * unit, cy * unit);

A helper on Raster beside cell_size_m, such as cell_size_ground_m(), would keep it in one place. #3343's own conversion and these three callers would then all use it. cell_size_m itself should not change: slope, aspect, hillshade, Shaded Relief and the shadows rely on cells in the coordinates' unit.

  • Viewshed: the cells in metres at rasterops.rs:843 and for the workflow's diagonal at workflows.rs:2071.
  • Measure volume: the cells in metres at imagery.rs:3027, before the geographic branch.
  • Mosaic: cx in metres before dividing by 111,320 at imagery.rs:3191.

Tests: the viewshed table above as a regression (EPSG:2263 against EPSG:32618 on the same ground, the same counts), a volume of a box in both systems, and a mosaic grid from an image in feet.

Left as it is

Heights stay in the band's own unit. On a DEM with heights in feet, the Viewshed's observer height (documented in metres) and the volume's heights are taken in feet. RustGIS has no elevation unit for a raster, so this issue doesn't change it, but the Viewshed and volume help could say so, as the terrain functions' help does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions