Geom
This module applies various geometric transformations to raster data.
It uses other raster modules under the hood to balance performance and safety (memory-awareness).
align_rasters(rasters, method='first', resampling=Resampling.nearest)
Align multiple rasters to a common grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rasters
|
List[Union[str, Path, Raster]]
|
List of input rasters (Paths or Objects). |
required |
method
|
str
|
Alignment strategy. Default is 'first' (align to first raster). |
'first'
|
resampling
|
Resampling
|
Interpolation method. |
nearest
|
Returns:
| Type | Description |
|---|---|
List[Raster]
|
List[Raster]: List of aligned Raster objects. |
Source code in src/phytospatial/raster/geom.py
crop(raster, bounds)
Crop raster to specified geographic bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
Raster
|
Input raster. |
required |
bounds
|
Tuple[float, float, float, float]
|
(minx, miny, maxx, maxy) in the same CRS as the raster. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Raster |
Raster
|
A new cropped Raster object. |
Source code in src/phytospatial/raster/geom.py
reproject(raster, target_crs, res=None, resampling=Resampling.bilinear)
Reproject a Raster to a new Coordinate Reference System (CRS).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
Raster
|
Input raster (Path or Raster object). |
required |
target_crs
|
Union[str, CRS]
|
Destination CRS (EPSG code or proj string). |
required |
res
|
Optional[float]
|
Force a specific resolution in destination units. |
None
|
resampling
|
Resampling
|
Interpolation method (default: Bilinear). Accepts other rasterio.warp.Resampling methods. |
bilinear
|
Returns:
| Name | Type | Description |
|---|---|---|
Raster |
Raster
|
A new Raster object in the target CRS. |
Source code in src/phytospatial/raster/geom.py
resample(raster, scale_factor, resampling=Resampling.bilinear)
Resample a raster by a scaling factor (Up/Down sampling).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
Raster
|
Input raster. |
required |
scale_factor
|
float
|
Multiplier for dimensions (0.5 = half size). |
required |
resampling
|
Resampling
|
Interpolation method. Accepts other rasterio.warp.Resampling methods. |
bilinear
|
Returns:
| Name | Type | Description |
|---|---|---|
Raster |
Raster
|
A new rescaled Raster object. |
Source code in src/phytospatial/raster/geom.py
split_bands(raster)
Splits a multi-band Raster into a list of single-band Rasters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
Raster
|
Multi-band input raster. |
required |
Returns:
| Type | Description |
|---|---|
List[Raster]
|
List[Raster]: One Raster object per band. |
Source code in src/phytospatial/raster/geom.py
stack_bands(rasters)
Combines a list of Rasters into a single multi-band Raster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rasters
|
List[Union[str, Path, Raster]]
|
List of paths or Raster objects. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Raster |
Raster
|
A single multi-band Raster object. |