Raster data utilities
combine_raster_bands(input_rasters)
Combine multiple rasters into one multiband raster.
The input rasters can be either singleband or multiband. All bands are stacked in the order they are extracted from the input raster list.
All input rasters must have matching spatial metadata (extent, pixel size, CRS).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_rasters |
Sequence[DatasetReader]
|
List of rasters to combine. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The combined raster data. |
Profile
|
The updated raster profile. |
Raises:
Type | Description |
---|---|
InvalidParameterValueException
|
Input rasters contains only one raster. |
NonMatchingRasterMetadataException
|
Input rasters have mismatching spatial metadata. |
Source code in eis_toolkit/utilities/raster.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
profile_from_extent_and_pixel_size(extent, pixel_size, round_strategy='up')
Create a raster profile from given extent and pixel size.
If extent and pixel size do not match exactly, i.e. raster width and height calcalated from bounds and pixel size are not integers, rounding for the width and height is performed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
extent |
Tuple[Number, Number, Number, Number]
|
Raster extent in the form (coord_west, coord_east, coord_south, coord_north). |
required |
pixel_size |
Union[Number, Tuple[Number, Number]]
|
Desired pixel size. If two values are provided, first is used for x and second for y. If one value is provided, the value is used for both directions. |
required |
round_strategy |
Literal[nearest, up, down]
|
The rounding strategy if extent and pixel size do not match exactly. Defaults to "up". |
'up'
|
Returns:
Type | Description |
---|---|
Profile
|
Rasterio profile. |
Source code in eis_toolkit/utilities/raster.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
split_raster_bands(raster)
Split multiband raster into singleband rasters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raster |
DatasetReader
|
Input multiband raster. |
required |
Returns:
Type | Description |
---|---|
Sequence[Tuple[ndarray, Profile]]
|
Output singleband raster list. List elements are tuples where first element is raster data (2D) and second element is raster profile. |
Raises:
Type | Description |
---|---|
InvalidParameterValueException
|
Input raster contains only one band. |
Source code in eis_toolkit/utilities/raster.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
stack_raster_arrays(arrays)
Stack 2D and 3D NumPy arrays (each representing a raster with one or multiple bands) along the bands axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arrays |
Sequence[ndarray]
|
List of 2D and 3D NumPy arrays. Each 2D array should have shape (height, width). and 3D array shape (bands, height, width). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
A single 3D NumPy array where the first dimension size equals the total number of bands. |
Raises:
Type | Description |
---|---|
InvalidDataShapeException
|
Input raster arrays have mismatching shapes or all input rasters are not 2D or 3D. |
Source code in eis_toolkit/utilities/raster.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|