TerrainModel
TerrainModel
DTM helper built on rasterio.
Wraps GeoTIFF-backed elevation model and provides convenience methods for querying pixel values, retrieving the spatial extent, and cropping/resampling.
Source code in occpy/terrainmodel.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
__init__
__init__(path2geotiff)
Open a DTM GeoTIFF for reading.
Parameters:
-
path2geotiff(str) –Path to a GeoTIFF file (typically single-band) in the dataset CRS.
Source code in occpy/terrainmodel.py
191 192 193 194 195 196 197 198 199 200 201 | |
crop2extent
crop2extent(extent, out_file, res=None)
Crop the DTM to an extent and optionally resample to a target pixel size.
Writes the cropped data to out_file.
If res is provided, the raster is resampled using bilinear interpolation
to the given pixel size. The instance is updated to reference the new file.
Parameters:
-
extent(tuple of float) –Bounding box in the dataset CRS as (min_x, max_y, max_x, min_y).
-
out_file(str) –Output GeoTIFF path for the cropped (and optionally resampled) raster.
-
res(float, default:None) –Target pixel size (units per pixel). If None, the original resolution is kept.
Returns:
-
ndarray–Cropped (and optionally resampled) data with shape (count, height, width).
Source code in occpy/terrainmodel.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
get_extent
get_extent()
Return the dataset bounding box.
Returns:
-
BoundingBox–Bounding box (left, bottom, right, top) in the dataset CRS.
Source code in occpy/terrainmodel.py
236 237 238 239 240 241 242 243 244 245 | |
get_pixel_value
get_pixel_value(x, y)
Sample the DTM at map coordinates.
Parameters:
-
x(float) –X coordinate in the dataset CRS.
-
y(float) –Y coordinate in the dataset CRS.
Returns:
-
float–Elevation value at (x, y).
Source code in occpy/terrainmodel.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
get_terrainmodel_path
get_terrainmodel_path()
Return the path to the currently opened DTM file.
Returns:
-
str–Absolute path of DTM file.
Source code in occpy/terrainmodel.py
204 205 206 207 208 209 210 211 212 213 | |
nhit_to_dsm
nhit_to_dsm(nhit_grid, config, out_file, smoothing_sigma=None)
Generate a canopy-surface GeoTIFF from an Nhit grid by taking, for each (x, y) column, the height of the highest voxel with at least one hit.
The resulting file has the same extent and pixel size as the voxel grid, so it
can be used directly as the dsm_file argument of
occpy.util.normalize_occlusion_output (which derives a canopy height model
internally as dsm - dtm).
Parameters:
-
nhit_grid(ndarray) –3D array (nx, ny, nz) with the number of hits per voxel, as produced by the occpy raytracer.
-
config(dict) –Configuration dictionary containing 'plot_dim' ([minX, minY, minZ, maxX, maxY, maxZ]) and 'vox_dim' (voxel size), matching the values used to derive
nhit_grid. An optional 'crs' key (anything accepted by rasterio, e.g. an EPSG string) sets the output CRS. -
out_file(str) –Path to the output GeoTIFF file for the generated DSM.
-
smoothing_sigma(float, default:None) –Standard deviation of the Gaussian kernel (in voxels/pixels) for a nodata-aware smoothing pass to remove per-column max-height spike noise before writing. If None, no smoothing is applied.
Returns:
-
ndarray–2D DSM array as written to
out_file, with shape (ny, nx).
Source code in occpy/terrainmodel.py
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 173 174 175 176 177 178 179 180 | |
nhit_to_dtm
nhit_to_dtm(nhit_grid, config, out_file, smoothing_sigma=None)
Generate a DTM GeoTIFF from an Nhit grid by taking, for each (x, y) column, the height of the lowest voxel with at least one hit (i.e. the ground return).
The resulting file has the same extent and pixel size as the voxel grid, so it
can be used directly as the dtm_file argument of
occpy.util.normalize_occlusion_output.
Parameters:
-
nhit_grid(ndarray) –3D array (nx, ny, nz) with the number of hits per voxel, as produced by the occpy raytracer.
-
config(dict) –Configuration dictionary containing 'plot_dim' ([minX, minY, minZ, maxX, maxY, maxZ]) and 'vox_dim' (voxel size), matching the values used to derive
nhit_grid. An optional 'crs' key (anything accepted by rasterio, e.g. an EPSG string) sets the output CRS. -
out_file(str) –Path to the output GeoTIFF file for the generated DTM.
-
smoothing_sigma(float, default:None) –Standard deviation of the Gaussian kernel (in voxels/pixels) for a nodata-aware smoothing pass to remove per-column max-height spike noise before writing. If None, no smoothing is applied.
Returns:
-
ndarray–2D DTM array as written to
out_file, with shape (ny, nx).
Source code in occpy/terrainmodel.py
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 | |