ST_Slope
Prev | 12.14. Raster Processing: DEM (Elevation) | Next

## Name

ST_Slope — Returns the slope (in degrees by default) of an elevation raster band. Useful for analyzing terrain.

## Synopsis

`raster ST_Slope(`raster rast, integer nband=1, text pixeltype=32BF, text units=DEGREES, double precision scale=1.0, boolean interpolate_nodata=FALSE`)`;

`raster ST_Slope(`raster rast, integer nband, raster customextent, text pixeltype=32BF, text units=DEGREES, double precision scale=1.0, boolean interpolate_nodata=FALSE`)`;

## Description

Returns the slope (in degrees by default) of an elevation raster band. Utilizes map algebra and applies the slope equation to neighboring pixels.

`units` indicates the units of the slope. Possible values are: RADIANS, DEGREES (default), PERCENT.

`scale` is the ratio of vertical units to horizontal. For Feet:LatLon use scale=370400, for Meters:LatLon use scale=111120.

If `interpolate_nodata` is TRUE, values for NODATA pixels from the input raster will be interpolated using ST_InvDistWeight4ma before computing the surface slope.

For more information about Slope, Aspect and Hillshade, please refer to ESRI - How hillshade works and ERDAS Field Guide - Slope Images.

Availability: 2.0.0

Enhanced: 2.1.0 Uses ST_MapAlgebra() and added optional `units`, `scale`, `interpolate_nodata` function parameters

Changed: 2.1.0 In prior versions, return values were in radians. Now, return values default to degrees

## Examples: Variant 1

    WITH foo AS (
        SELECT ST_SetValues(
            ST_AddBand(ST_MakeEmptyRaster(5, 5, 0, 0, 1, -1, 0, 0, 0), 1, '32BF', 0, -9999),
            1, 1, 1, ARRAY[
                [1, 1, 1, 1, 1],
                [1, 2, 2, 2, 1],
                [1, 2, 3, 2, 1],
                [1, 2, 2, 2, 1],
                [1, 1, 1, 1, 1]
            ]::double precision[][]
        ) AS rast
    )
    SELECT
        ST_DumpValues(ST_Slope(rast, 1, '32BF'))
    FROM foo

                                st_dumpvalues

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------
     (1,"{{10.0249881744385,21.5681285858154,26.5650520324707,21.5681285858154,10.0249881744385},{21.5681285858154,35.2643890380859,36.8698959350586,35.2643890380859,21.5681285858154},
    {26.5650520324707,36.8698959350586,0,36.8698959350586,26.5650520324707},{21.5681285858154,35.2643890380859,36.8698959350586,35.2643890380859,21.5681285858154},{10.0249881744385,21.
    5681285858154,26.5650520324707,21.5681285858154,10.0249881744385}}")
    (1 row)

## Examples: Variant 2

Complete example of tiles of a coverage. This query only works with PostgreSQL 9.1 or higher.

    WITH foo AS (
        SELECT ST_Tile(
            ST_SetValues(
                ST_AddBand(
                    ST_MakeEmptyRaster(6, 6, 0, 0, 1, -1, 0, 0, 0),
                    1, '32BF', 0, -9999
                ),
                1, 1, 1, ARRAY[
                    [1, 1, 1, 1, 1, 1],
                    [1, 1, 1, 1, 2, 1],
                    [1, 2, 2, 3, 3, 1],
                    [1, 1, 3, 2, 1, 1],
                    [1, 2, 2, 1, 2, 1],
                    [1, 1, 1, 1, 1, 1]
                ]::double precision[]
            ),
            2, 2
        ) AS rast
    )
    SELECT
        t1.rast,
        ST_Slope(ST_Union(t2.rast), 1, t1.rast)
    FROM foo t1
    CROSS JOIN foo t2
    WHERE ST_Intersects(t1.rast, t2.rast)
    GROUP BY t1.rast;

## See Also

ST_MapAlgebra (callback function version), ST_TRI, ST_TPI, ST_Roughness, ST_HillShade, ST_Aspect

Prev | Up | Next
ST_Roughness | Home | ST_TPI