제목

ST_Aspect — 표고 래스터 밴드의 향(기본 단위는 도)을 반환합니다. 지형을 분석하는 데 유용합니다.

요약

raster ST_Aspect(raster rast, integer band=1, text pixeltype=32BF, text units=DEGREES, boolean interpolate_nodata=FALSE);

raster ST_Aspect(raster rast, integer band, raster customextent, text pixeltype=32BF, text units=DEGREES, boolean interpolate_nodata=FALSE);

Description

표고 래스터 밴드의 향(기본 단위는 도)을 반환합니다. 맵 대수를 활용해서 이웃 픽셀들에 향 방정식을 적용합니다.

units 는 향의 단위를 의미합니다. RADIANS, DEGREES(기본값)를 쓸 수 있습니다.

units = RADIANS일 경우, 북쪽에서 시계방향으로 측정한 0과 2π 라디안 사이의 값입니다.

units = DEGREES일 경우, 북쪽에서 시계방향으로 측정한 0도와 360도 사이의 값입니다.

픽셀의 경사가 0일 경우, 픽셀의 향은 -1입니다.

[참고]

경사(slope), 향(aspect), 음영기복(hillshade)에 대한 자세한 내용을 알고 싶다면, ESRI - How hillshade worksERDAS Field Guide - Aspect Images 를 참조하십시오.

2.0.0 버전부터 사용할 수 있습니다.

개선 사항: 2.1.0 버전부터 ST_MapAlgebra()를 이용하며, 선택적인 interpolate_nodata 함수 파라미터가 추가됐습니다.

변경 사항: 2.1.0 미만 버전에서는 반환되는 값이 라디안 단위였습니다. 2.1.0 버전부터 반환되는 값의 기본 단위가 도로 바뀌었습니다.

예시

Variant 1.

This symmetric peak highlights the expected compass directions at the corners and the -1 aspect at the summit. The generated PNG shows the full aspect surface without relying on a manual illustration. The generated source raster is large enough for the PNG to show the directional field around the summit.

Code
WITH pixels AS (
    SELECT
        x,
        y,
        (20 - greatest(abs(x - 9), abs(y - 9)))::double precision AS value
    FROM generate_series(1, 17) AS y
    CROSS JOIN generate_series(1, 17) AS x
), rows AS (
    SELECT
        y,
        array_agg(value ORDER BY x) AS row_values
    FROM pixels
    GROUP BY y
), source AS (
    SELECT ST_SetValues(
        ST_AddBand(
            ST_MakeEmptyRaster(17, 17, 0, 0, 1, -1, 0, 0, 0),
            1, '32BF', 0, -9999
        ),
        1, 1, 1,
        array_agg(row_values ORDER BY y)::double precision[][]
    ) AS rast
    FROM rows
), aspect AS (
    SELECT ST_Aspect(rast, 1, '32BF') AS rast
    FROM source
)
SELECT
    round(ST_Value(rast, 1, 1, 1)::numeric, 3) AS northwest_degrees,
    round(ST_Value(rast, 1, 9, 9)::numeric, 3) AS summit_degrees,
    round(ST_Value(rast, 1, 17, 17)::numeric, 3) AS southeast_degrees,
    ST_AsPNG(ST_ColorMap(rast, 1, 'bluered')) AS image
FROM aspect;
래스터 출력
northwest_degrees | summit_degrees | southeast_degrees | image
-------------------+----------------+-------------------+------------------------
           315.000 |         -1.000 |           135.000 | PNG image, 17 x 17 pixels
Figure
Geometry figure for visual-rt-st-aspect-01

Variant 2.

Complete example of tiles of a coverage.

Code
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_Aspect(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;