xdem.DEM

Contents

xdem.DEM#

class xdem.DEM(filename_or_dataset, vcrs=None, load_data=False, parse_sensor_metadata=False, silent=True, downsample=1, nodata=None)[source]#

The digital elevation model.

The DEM has a single main attribute in addition to that inherited from geoutils.Raster:
vcrs: pyproj.VerticalCRS

Vertical coordinate reference system of the DEM.

Other derivative attributes are:
vcrs_name: str

Name of vertical CRS of the DEM.

vcrs_grid: str

Grid path to the vertical CRS of the DEM.

ccrs: pyproj.CompoundCRS

Compound vertical and horizontal CRS of the DEM.

The attributes inherited from geoutils.Raster are:
data: np.ndarray

Data array of the DEM, with dimensions corresponding to (count, height, width).

transform: affine.Affine

Geotransform of the DEM.

crs: pyproj.crs.CRS

Coordinate reference system of the DEM.

nodata: int or float

Nodata value of the DEM.

All other attributes are derivatives of those attributes, or read from the file on disk. See the API for more details.

__init__(filename_or_dataset, vcrs=None, load_data=False, parse_sensor_metadata=False, silent=True, downsample=1, nodata=None)[source]#

Instantiate a digital elevation model.

The vertical reference of the DEM can be defined by passing the vcrs argument. Otherwise, a vertical reference is tentatively parsed from the DEM product name.

Inherits all attributes from the geoutils.Raster class.

Parameters:
  • filename_or_dataset (str | TypeVar(RasterType, bound= Raster) | DatasetReader | MemoryFile) – The filename of the dataset.

  • vcrs (Literal['Ellipsoid', 'EGM08', 'EGM96'] | VerticalCRS | str | Path | int | None) – Vertical coordinate reference system either as a name (“WGS84”, “EGM08”, “EGM96”), an EPSG code or pyproj.crs.VerticalCRS, or a path to a PROJ grid file (OSGeo/PROJ-data).

  • load_data (bool) – Whether to load the array during instantiation. Default is False.

  • parse_sensor_metadata (bool) – Whether to parse sensor metadata from filename and similarly-named metadata files.

  • silent (bool) – Whether to display vertical reference parsing.

  • downsample (int) – Downsample the array once loaded by a round factor. Default is no downsampling.

  • nodata (int | float | None) – Nodata value to be used (overwrites the metadata). Default reads from metadata.

Methods

__init__(filename_or_dataset[, vcrs, ...])

Instantiate a digital elevation model.

aspect([method, surface_fit, degrees, mp_config])

Calculate the aspect of each cell in a DEM, returned in degrees by default.

astype(dtype[, convert_nodata, inplace])

coords([grid, shift_area_or_point, force_offset])

Get coordinates (x,y) of all pixels in the raster.

copy([new_array])

Copy the DEM, possibly updating the data array.

coregister_3d(reference_elev, coreg_method)

Coregister DEM to a reference DEM in three dimensions.

crop(bbox[, mode, inplace])

curvature([surface_fit, mp_config])

THIS FUNCTION IS DEPRECATED - REFER TO DOCS FOR SPECIFIC CURVATURE RECOMMENDATIONS

estimate_uncertainty(other_elev[, ...])

Estimate the uncertainty of DEM.

filter(method[, inplace, size])

flowline_curvature([surface_fit, ...])

Calculates flow line curvature in units of m-1 multiplied by 100.

fractal_roughness([window_size, mp_config])

Calculates the fractal roughness, the local 3D fractal dimension.

from_array(data, transform, crs[, nodata, ...])

Create a DEM from a numpy array and the georeferencing information.

from_pointcloud_regular(pointcloud[, ...])

Create a raster from a point cloud with coordinates on a regular grid.

from_xarray(ds[, dtype])

Create raster from a xarray.DataArray.

georeferenced_grid_equal(raster)

Check that raster shape, geotransform and CRS are equal.

get_bounds_projected(out_crs[, densify_points])

Get raster bounds projected in a specified CRS.

get_footprint_projected(out_crs[, ...])

Get raster footprint projected in a specified CRS.

get_mask()

Get mask of invalid values from the raster.

get_metric_crs([local_crs_type, method])

Get local metric coordinate reference system for the raster (UTM, UPS, or custom Mercator or Polar).

get_nanarray([floating_dtype, return_mask])

get_stats([stats_name, inlier_mask, band, ...])

get_terrain_attribute(attribute, **kwargs)

Derive one or multiple terrain attributes from a DEM.

hillshade([method, surface_fit, azimuth, ...])

Generate a hillshade from the given DEM.

icrop(bbox, *[, inplace])

ij2xy(i, j[, shift_area_or_point, force_offset])

Get coordinates (x,y) of indexes (row,column).

info([stats, verbose])

interp_points(points[, method, ...])

intersection(raster[, match_ref])

Returns the bounding box of intersection between this image and another.

load([bands])

Load the raster array from disk.

max_curvature([surface_fit, curv_method, ...])

Calculate the maximal (geometric) or maximum (directional derivative) curvature in units of m-1 multiplied by 100.

min_curvature([surface_fit, curv_method, ...])

Calculate the minimal (geometric) or minimum (directional derivative) curvature in units of m-1 multiplied by 100.

outside_image(xi, yj[, index])

Check whether a given point falls outside the raster.

planform_curvature([surface_fit, ...])

Calculates planform (or plan) curvature in units of m-1 multiplied by 100., defined as the curvature of a projection of the contour line onto a horizontal plane.

plot([bands, cmap, vmin, vmax, alpha, ...])

polygonize([target_values, data_column_name])

Polygonize the raster into a vector.

profile_curvature([surface_fit, ...])

Calculates profile curvature in units of m-1 multiplied by 100.

proximity([vector, target_values, ...])

Compute proximity distances to the raster target pixels, or to a vector geometry on the raster grid.

raster_equal(other[, strict_masked, ...])

Check if two rasters are equal.

reduce_points(points[, reducer_function, ...])

Reduce raster values around point coordinates.

reproject([ref, crs, res, grid_size, ...])

roughness([window_size, mp_config])

Calculates the roughness, the maximum difference between neighbouring pixels, for any window size.

rugosity([mp_config])

Calculates the rugosity, the ratio between real area and planimetric area.

save(filename[, driver, dtype, nodata, ...])

set_area_or_point(new_area_or_point[, ...])

Set new pixel interpretation of the raster.

set_mask(mask)

Set a mask on the raster array.

set_nodata(new_nodata[, update_array, ...])

Set a new nodata value for all bands.

set_vcrs(new_vcrs)

Set the vertical coordinate reference system of the DEM.

slope([method, surface_fit, degrees, mp_config])

Generate a slope map for a DEM, returned in degrees by default.

split_bands([copy, bands])

Split the bands into separate rasters.

subsample(subsample[, return_indices, ...])

tangential_curvature([surface_fit, ...])

Calculates tangential curvature in units of m-1 multiplied by 100.

terrain_ruggedness_index([method, ...])

Calculates the Terrain Ruggedness Index, the cumulated differences to neighbouring pixels.

texture_shading([alpha, mp_config])

Generate a texture shaded relief map using fractional Laplacian operator.

to_file(filename[, driver, dtype, nodata, ...])

Write the raster to file.

to_pointcloud([data_column_name, data_band, ...])

Convert raster to point cloud.

to_points(**kwargs)

to_rio_dataset()

Export to a Rasterio in-memory dataset.

to_vcrs(vcrs[, force_source_vcrs, inplace])

to_xarray([name])

Convert raster to a xarray.DataArray.

topographic_position_index([window_size, ...])

Calculates the Topographic Position Index, the difference to the average of neighbouring pixels.

translate(xoff, yoff[, distance_unit, inplace])

xy2ij(x, y[, op, precision, shift_area_or_point])

Get indexes (row,column) of coordinates (x,y).

Attributes

area_or_point

Pixel interpretation of the raster.

bands

Band indexes loaded in memory if they are, otherwise on disk.

bands_on_disk

Band indexes on disk if a file exists.

bounds

Bounding coordinates of the raster.

ccrs

Compound horizontal and vertical coordinate reference system of the DEM.

count

Count of bands loaded in memory if they are, otherwise the one on disk.

count_on_disk

Count of bands on disk if it exists.

crs

Coordinate reference system of the raster.

data

Array of the raster.

driver

Driver used to read a file on disk.

dtype

Data type of the raster (string representation).

footprint

Footprint of the raster.

height

Height of the raster in pixels.

indexes

Band indexes (duplicate of .bands attribute, mirroring Rasterio naming "indexes").

is_loaded

Whether the raster array is loaded.

is_mask

Whether the raster array is a boolean data type (a mask).

is_modified

Whether the array has been modified since it was loaded from disk.

name

Name of the raster file on disk, if it exists.

nodata

Nodata value of the raster.

profile

Basic metadata and creation options of this dataset.

res

Resolution (X, Y) of the raster in georeferenced units.

shape

Shape (i.e., height, width) of the raster in pixels.

tags

Metadata tags of the raster.

transform

Geotransform of the raster.

vcrs

Vertical coordinate reference system of the DEM.

vcrs_grid

Grid path of vertical coordinate reference system of the DEM.

vcrs_name

Name of vertical coordinate reference system of the DEM.

width

Width of the raster in pixels.