terraflow.geo¶
The geo module owns ROI clipping and CRS alignment. The pipeline invariant is all output coordinates are EPSG:4326 — geo.py reprojects any input that differs.
Overview¶
- ROI bounds in any CRS are reprojected to the raster CRS (all four corners, then axis-aligned bounding box) before windowing.
- ROI clipping snaps requested bounds to an intersecting pixel window so very small ROIs avoid oversized raster reads.
- Degenerate windows (NaN dimensions after reprojection) raise
ValueErrorwith diagnostic context.
API Reference¶
geo
¶
clip_raster_to_roi(raster, roi, roi_crs='EPSG:4326', band=1)
¶
Clip a raster to the region of interest and return data & transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
DatasetReader
|
Open rasterio dataset. |
required |
roi
|
Dict[str, Any]
|
Dictionary with keys: xmin, ymin, xmax, ymax. Coordinates must be in the CRS specified by roi_crs (default EPSG:4326 / WGS 84). |
required |
roi_crs
|
str
|
EPSG code or WKT string for the CRS of the ROI coordinates.
Defaults to |
'EPSG:4326'
|
Returns:
| Name | Type | Description |
|---|---|---|
data |
MaskedArray
|
A masked array (band 1) containing the clipped raster values. |
transform |
Affine
|
Affine transform corresponding to the clipped window. |
Raises:
| Type | Description |
|---|---|
ValueError:
|
If raster does not have band 1, ROI bounds are invalid, or the (reprojected) ROI does not intersect the raster extent. |
Source code in terraflow/geo.py
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 142 143 | |