meta
RasterMeta
Bases: BaseModel
Raster metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
crs |
InstanceOf[CRS]
|
Coordinate reference system. |
transform |
InstanceOf[Affine]
|
The affine transformation associated with the raster. This is based on the CRS, the cell size, as well as the offset/origin. |
Source code in src/rastr/meta.py
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 44 45 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 88 89 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 124 125 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 | |
cell_height
property
Cell height derived from the transform's y-pixel height.
cell_size
property
Cell size as (width, height) in CRS units, derived from the transform.
cell_width
property
Cell width derived from the transform's x-pixel width.
has_square_cells
property
Whether the cells are square (i.e. cell width == cell height).
square_cell_size
property
Cell size if the cells are square, otherwise raises an error.
check_non_rotated_non_skewed(v)
classmethod
Validator to ensure the transform is non-rotated and non-skewed.
Source code in src/rastr/meta.py
31 32 33 34 35 36 37 38 39 40 41 | |
example()
classmethod
Create an example RasterMeta object.
Source code in src/rastr/meta.py
72 73 74 75 76 77 78 | |
get_cell_centre_coords(shape)
Return an array of (x, y) coordinates for the center of each cell.
The coordinates will be in the coordinate system defined by the raster's transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, int]
|
(rows, cols) of the raster array. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
(x, y) coordinates for each cell center, with shape (rows, cols, 2) |
Source code in src/rastr/meta.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
get_cell_x_coords(n_columns)
Return an array of x coordinates for the center of each cell.
The coordinates will be in the coordinate system defined by the raster's transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_columns
|
int
|
Number of columns in the raster array. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
x_coordinates at cell centers, with shape (n_columns,) |
Source code in src/rastr/meta.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
get_cell_y_coords(n_rows)
Return an array of y coordinates for the center of each cell.
The coordinates will be in the coordinate system defined by the raster's transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_rows
|
int
|
Number of rows in the raster array. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
y_coordinates at cell centers, with shape (n_rows,) |
Source code in src/rastr/meta.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
infer(x, y, *, cell_size=None, crs)
classmethod
Automatically get recommended raster metadata (and shape) using data points.
The cell size can be provided, or a heuristic will be used based on the spacing
of the (x, y) points. Square cells are assumed unless a (cell_width,
cell_height) pair is explicitly provided.
Source code in src/rastr/meta.py
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 | |
infer_cell_size(x, y)
Infer a suitable cell size based on the spacing of (x, y) data points.
When points are distributed regularly, this corresponds to the distance between neighboring points.
When distributed irregularly, the size is more influenced by the densest clusters of points, i.e. the cell size will be small enough to capture the detail in these clusters.
This is based on a heuristic which has been found to work well in practice.
The inferred result uses square cells, i.e. (cell_size, cell_size).
Source code in src/rastr/meta.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
infer_origin(x, y, *, cell_size)
Infer a suitable raster origin based on the bounds of (x, y) data points.
Use equal values in cell_size for square cells, or distinct values for
rectangular cells.
Source code in src/rastr/meta.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
infer_shape(x, y, *, cell_size=None)
Infer a suitable raster shape based on the bounds of (x, y) data points.
Square cells are assumed unless a (cell_width, cell_height) pair is explicitly
provided.
Source code in src/rastr/meta.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
infer_transform(x, y, *, cell_size=None, crs)
Infer a suitable raster transform based on the bounds of (x, y) data points.
Square cells are assumed unless a (cell_width, cell_height) pair is explicitly
provided.
Source code in src/rastr/meta.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |