I/O Utilities¶
The io module provides functions for reading and writing GeoTIFF raster files, vector formats (GeoJSON, GeoPackage, GeoParquet), and CRS handling.
io ¶
I/O utilities for raster and vector data.
Provides functions for reading/writing GeoTIFF files, vector formats (GeoJSON, GeoPackage, GeoParquet), and CRS handling.
get_equal_area_crs ¶
Return the NSIDC EASE-Grid 2.0 equal-area CRS (EPSG:6933).
This CRS is used for accurate area calculations of field polygons.
Returns:
| Type | Description |
|---|---|
CRS
|
EPSG:6933 equal-area cylindrical projection. |
Source code in agribound/io/crs.py
get_utm_crs ¶
Determine the UTM CRS for a given longitude/latitude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon
|
float
|
Longitude in degrees. |
required |
lat
|
float
|
Latitude in degrees. |
required |
Returns:
| Type | Description |
|---|---|
CRS
|
UTM CRS for the given location. |
Source code in agribound/io/crs.py
reproject_raster ¶
reproject_raster(src_path: str | Path, dst_path: str | Path, dst_crs: Any, resolution: float | None = None, resampling: str = 'nearest') -> str
Reproject a raster to a different CRS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_path
|
str or Path
|
Source raster file. |
required |
dst_path
|
str or Path
|
Destination raster file. |
required |
dst_crs
|
CRS or str
|
Target coordinate reference system. |
required |
resolution
|
float or None
|
Output pixel resolution. If None, computed automatically. |
None
|
resampling
|
str
|
Resampling method: |
'nearest'
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the reprojected raster. |
Source code in agribound/io/crs.py
get_raster_info ¶
Read metadata from a raster file without loading pixel data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to the raster file (GeoTIFF). |
required |
Returns:
| Type | Description |
|---|---|
RasterInfo
|
Raster metadata. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist. |
Source code in agribound/io/raster.py
read_raster ¶
read_raster(path: str | Path, bands: list[int] | None = None, window: Window | None = None) -> tuple[np.ndarray, dict[str, Any]]
Read a raster file into a NumPy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to the raster file. |
required |
bands
|
list[int] or None
|
1-based band indices to read. None reads all bands. |
None
|
window
|
Window or None
|
Spatial sub-window to read. None reads the full extent. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
data |
ndarray
|
Pixel data with shape |
meta |
dict
|
Rasterio metadata dictionary (crs, transform, width, height, etc.). |
Source code in agribound/io/raster.py
write_raster ¶
write_raster(path: str | Path, data: ndarray, crs: Any, transform: Any, nodata: float | None = None, dtype: str | None = None, compress: str = 'lzw') -> str
Write a NumPy array as a GeoTIFF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Destination file path. |
required |
data
|
ndarray
|
Pixel data with shape |
required |
crs
|
CRS or str
|
Coordinate reference system. |
required |
transform
|
Affine
|
Affine transform. |
required |
nodata
|
float or None
|
Nodata value to encode in the file. |
None
|
dtype
|
str or None
|
Output data type. Defaults to the array dtype. |
None
|
compress
|
str
|
Compression method (default |
'lzw'
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the written file. |
Source code in agribound/io/raster.py
read_vector ¶
Read a vector file into a GeoDataFrame.
Supports GeoJSON, GeoPackage, Shapefile, and GeoParquet formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to the vector file. |
required |
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
Loaded vector data. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist. |
ValueError
|
If the file format is not supported. |
Source code in agribound/io/vector.py
write_vector ¶
Write a GeoDataFrame to a vector file.
When writing to .parquet, the output is fiboa-compliant GeoParquet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
Vector data to write. |
required |
path
|
str or Path
|
Destination file path. |
required |
format
|
str or None
|
Override output format. If None, inferred from the file extension. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the written file. |