Skip to content

slope() planar path does not warn on degree coordinates with meter elevation #2764

@brendancol

Description

@brendancol

Describe the bug

slope() with the default method='planar' uses the coordinate spacing directly as the cellsize (xrspatial/slope.py:378). When the coordinates are in degrees (lat/lon) but the elevation values are in meters, the rise-over-run computation mixes incompatible units and the returned slope is wrong by orders of magnitude. Nothing tells the caller this happened, so downstream code trusts the numbers.

A warning helper already exists for this case, warn_if_unit_mismatch in xrspatial/utils.py:781. It is tested in isolation but no module calls it. The docs mention the degree/meter pitfall, but a doc note does not help someone who never reads it and feeds the output into a model.

Expected behavior

When the planar path detects degree-like horizontal coordinates alongside meter-like elevation values, slope() should emit a UserWarning at runtime pointing the caller to reproject to a projected CRS. Projected/meter coordinates should produce no warning.

Additional context

Fix is to wire the planar branch of slope() to call the existing warn_if_unit_mismatch helper. Add a test asserting the warning fires for degree coordinates and stays silent for projected coordinates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions