RSGISLib Elevation

Slope and Aspect

rsgislib.elevation.slope(input_img, output_img, gdalformat, unit)

Calculates a slope layer given an input elevation model.

Parameters
  • input_img – is a string containing the name and path of the input DEM file.

  • output_img – is a string containing the name and path of the output file.

  • gdalformat – is a string with the output image format for the GDAL driver.

  • unit – is a string specifying the output unit (‘degrees’ or ‘radians’).

rsgislib.elevation.slope_pxl_res_img(in_dem_img, in_pxl_res_img, output_img, unit, gdalformat)

Calculates a slope layer given an input elevation model and external pixel resolution image, which allows the slope to be calculated for images in projections (e.g., EPSG:4326) which do not use the same units as the elevation values (e.g., metres).

Parameters
  • in_dem_img – is a string containing the name and path of the input DEM file.

  • in_pxl_res_img – is a string containing the name and path of the input image. specifying the image pixel resolutions. Band 1: East-West resolution and Band 2 is the North-South resolution.

  • output_img – is a string containing the name and path of the output file.

  • unit – is a string specifying the output unit (‘degrees’ or ‘radians’).

  • gdalformat – is a string with the output image format for the GDAL driver.

rsgislib.elevation.aspect(input_img, output_img, gdalformat)

Calculates a aspect layer given an input elevation model

Parameters
  • input_img – is a string containing the name and path of the input DEM file.

  • output_img – is a string containing the name and path of the output file.

  • gdalformat – is a string with the output image format for the GDAL driver.

rsgislib.elevation.aspect_pxl_res_img(in_dem_img, in_pxl_res_img, output_img, gdalformat)

Calculates a aspect layer given an input elevation model and external pixel resolution image, which allows the slope to be calculated for images in projections (e.g., EPSG:4326) which do not use the same units as the elevation values (e.g., metres).

Parameters
  • in_dem_img – is a string containing the name and path of the input DEM file.

  • in_pxl_res_img – is a string containing the name and path of the input image. specifying the image pixel resolutions. Band 1: East-West resolution and Band 2 is the North-South resolution.

  • output_img – is a string containing the name and path of the output file.

  • gdalformat – is a string with the output image format for the GDAL driver.

rsgislib.elevation.catagorise_aspect(input_img, output_img, gdalformat)

Creates an aspect layer which is categorised into 8 catergories from 0-45, 45-90, 90-135, 135-180, 180-225, 225-270, 270-315 and 315-360.

Parameters
  • input_img – is a string containing the name and path of the input aspect (in degrees) file.

  • output_img – is a string containing the name and path of the output file.

  • gdalformat – is a string with the output image format for the GDAL driver.

Flitering

rsgislib.elevation.dtm_aspect_median_filter(in_dem_img, in_aspect_img, output_img, aspect_range, win_h_size, gdalformat)

Filter the DTM for noise using a median filter with an aspect restriction (i.e., only pixels within the aspect range of the centre pixel will be used within the median filter).

Parameters
  • in_dem_img – is a string containing the name and path of the input DTM file.

  • in_aspect_img – is a string containing the name and path of the input Aspect file (in degrees).

  • output_img – is a string containing the name and path of the output file.

  • aspect_range – is a float with the range of from the centre pixel in degrees.

  • win_h_size – is an integer for half the window size.

  • gdalformat – is a string with the output image format for the GDAL driver.

rsgislib.elevation.fill_dem_soille_gratin_1994(in_dem_img, in_vld_img, output_img, gdalformat)

Filter the local minima in a DEM using the Soille and Gratin 1994 algorithm.

Soille, P., and Gratin, C. (1994). An efficient algorithm for drainage network extraction on DEMs. J. Visual Communication and Image Representation. 5(2). 181-189.

Parameters
  • in_dem_img – is a string containing the name and path of the input DEM file.

  • in_vld_img – is a string containing the name and path to a binary image specifying the valid data region (1 == valid)

  • output_img – is a string containing the name and path of the output file.

  • gdalformat – is a string with the output image format for the GDAL driver.

import rsgislib.elevation
inputDEMImage = 'DEM.kea'
validMaskImage = 'ValidRegionMask.kea'
outFilledImage = 'DEM_filled.kea'
rsgislib.elevation.fill_dem_soille_gratin_1994(inputDEMImage, validMaskImage, outFilledImage, 'KEA')
rsgislib.elevation.plane_fit_detreat_dem(input_img, output_img, gdalformat, win_size)

An algorithm to detread a DEM using local plane fitting. The winSize will define the scale at which the DEM will be detreaded.

Parameters
  • input_img – is a string containing the name and path of the input DEM file.

  • output_img – is a string containing the name and path of the output file.

  • gdalformat – is a string with the output image format for the GDAL driver.

  • win_size – is an integer with the window size within which the plane is fitted.

import rsgislib.elevation
inputDEMImage = 'DEM.kea'
outDEMImage = 'DEM_Detread.kea'
rsgislib.elevation.plane_fit_detreat_dem(inputDEMImage, outDEMImage, 'KEA', 11)

Masking

rsgislib.elevation.shadow_mask(input_img, output_img, azimuth, zenith, max_height, gdalformat)

Calculates a shadow mask given an input elevation model

Parameters
  • input_img – is a string containing the name and path of the input DEM file.

  • output_img – is a string containing the name and path of the output file.

  • azimuth – is a float with the solar azimuth in degrees.

  • zenith – is a float with the solar zenith in degrees.

  • max_height – is a float with the maximum height for the ray tracing (should be above the maximum elevation within the scene).:param gdalformat: is a string with the output image format for the GDAL driver.

Incidence / Existance Angle

rsgislib.elevation.local_incidence_angle(input_img, output_img, azimuth, zenith, gdalformat)

Calculates a local solar incidence angle layer given an input elevation model

Parameters
  • input_img – is a string containing the name and path of the input DEM file.

  • output_img – is a string containing the name and path of the output file.

  • azimuth – is a float with the solar azimuth in degrees.

  • zenith – is a float with the solar zenith in degrees.

  • gdalformat – is a string with the output image format for the GDAL driver.

rsgislib.elevation.local_existance_angle(input_img, output_img, azimuth, zenith, gdalformat)

Calculates a local solar existance angle layer given an input elevation model

Parameters
  • input_img – is a string containing the name and path of the input DEM file.

  • output_img – is a string containing the name and path of the output file.

  • azimuth – is a float with the solar azimuth in degrees.

  • zenith – is a float with the solar zenith in degrees.

  • gdalformat – is a string with the output image format for the GDAL driver.

Visualisation

rsgislib.elevation.hillshade(input_img, output_img, azimuth, zenith, gdalformat)

Calculates a hillshade layer given an input elevation model

Parameters
  • input_img – is a string containing the name and path of the input DEM file.

  • output_img – is a string containing the name and path of the output file.

  • azimuth – is a float with the solar azimuth in degrees (Good value is 315).

  • zenith – is a float with the solar zenith in degrees (Good value is 45).

  • gdalformat – is a string with the output image format for the GDAL driver.

rsgislib.elevation.hillshade_pxl_res_img(in_dem_img, in_pxl_res_img, output_img, azimuth, zenith, gdalformat)

Calculates a hillshade layer given an input elevation model and external pixel resolution image, which allows the slope to be calculated for images in projections (e.g., EPSG:4326) which do not use the same units as the elevation values (e.g., metres).

Parameters
  • in_dem_img – is a string containing the name and path of the input DEM file.

  • in_pxl_res_img – is a string containing the name and path of the input image. specifying the image pixel resolutions. Band 1: East-West resolution and Band 2 is the North-South resolution.

  • output_img – is a string containing the name and path of the output file.

  • azimuth – is a float with the solar azimuth in degrees (Good value is 315).

  • zenith – is a float with the solar zenith in degrees (Good value is 45).

  • gdalformat – is a string with the output image format for the GDAL driver.

Fusion

rsgislib.elevation.fft_dem_fusion(highResDEMImg, lowResDEMImg, fusedDEMImg, cSize=20)

This function merges DEMs (any single band file) using a fourier transformation where the low frequency component is taken from the lower resolution DEM and the high frequency component is taken from the higher resolution DEM.

This is an implementation ideas from:

Karkee, M., Steward, B. L., & Aziz, S. A. (2008). Improving quality of public domain digital elevation models through data fusion. Biosystems Engineering, 101(3), 293–305.

Parameters
  • high_res_DEM_img – is an input image file for the high resolution DEM file.

  • low_res_DEM_img – is an input image file for the low resolution DEM file.

  • fused_DEM_img – is an output image file for the resulting fused DEM.

  • c_size – is the threshold (int) defining the high and low frequencies.

import rsgislib
from rsgislib import elevation

high_res_DEM_img = "N09E009_TDX_12m_EGM08.tif"
low_res_DEM_img = "N09E009_SRTM_30m_EGM08.tif"
fused_DEM_img = "NO9E009_SRTM_TDX_EGM08_fusion.tif"
c_size = 10

elevation.fft_dem_fusion(highResDEMImg, lowResDEMImg, fusedDEMImg, cSize=20)