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
5 6 7 8 9 10 11 12 13 14 15 16 17 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 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 | |
__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
13 14 15 16 17 18 19 20 21 22 23 | |
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
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 | |
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
58 59 60 61 62 63 64 65 66 67 | |
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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
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
26 27 28 29 30 31 32 33 34 35 | |