gedih3.raster.export#
Raster Export Module
This module provides utilities for exporting raster data to various formats, with support for GeoTIFF compression, tiling, and batch operations.
Attributes#
Functions#
|
Export xarray Dataset to GeoTIFF file. |
|
Export raster partition(s) to file(s). |
|
Rasterize and export GeoDataFrame partitions to individual files. |
|
Build a GDAL VRT file mosaicking a list of GeoTIFF tiles. |
|
Write a VRT mosaic as XML using rasterio only — no |
|
Build a VRT mosaic, downgrading any failure to a warning. |
|
Rasterize all partitions and merge into a single output file. |
|
Compute basic statistics for each variable in a raster dataset. |
Module Contents#
- gedih3.raster.export.logger#
- gedih3.raster.export.export_raster(xras: xarray.Dataset, output_path: str, compress: str = 'LZW', tiled: bool = True, blocksize: int = 256, bigtiff: bool = True) str[source]#
Export xarray Dataset to GeoTIFF file.
- Parameters:
- xrasxr.Dataset
Raster dataset to export
- output_pathstr
Output file path
- compressstr
Compression method (‘LZW’, ‘ZSTD’, ‘DEFLATE’, ‘NONE’)
- tiledbool
Use tiled output format
- blocksizeint
Tile block size in pixels
- bigtiffbool
Use BigTIFF format for large files
- Returns:
- str
Output file path
- gedih3.raster.export.export_raster_partition(data: pandas.Series | xarray.Dataset, output_dir: str, fmt: str = 'tif', compress: str = 'LZW', partition_id_attr: str | None = None) str[source]#
Export raster partition(s) to file(s).
This function handles the case where a Series may contain multiple rasters from different spatial tiles. Each raster is exported to its own file based on its tile ID attribute.
- Parameters:
- datapd.Series or xr.Dataset
Raster data (Series of DataArrays/Datasets or single Dataset)
- output_dirstr
Output directory
- fmtstr
Output format (‘tif’, ‘nc’)
- compressstr
Compression method for GeoTIFF
- partition_id_attrstr, optional
Attribute name containing partition ID for filename
- Returns:
- str
Output file path(s), comma-separated if multiple files written
- gedih3.raster.export.rasterize_and_export_partitions(gdf: geopandas.GeoDataFrame | dask.dataframe.DataFrame, output_dir: str, rasterize_func, columns: List[str] | None = None, fmt: str = 'tif', compress: str = 'LZW', show_progress: bool = True, **rasterize_kwargs) List[str][source]#
Rasterize and export GeoDataFrame partitions to individual files.
- Parameters:
- gdfGeoDataFrame or dask GeoDataFrame
Input spatially-indexed data
- output_dirstr
Output directory for raster files
- rasterize_funccallable
Function to rasterize each partition (e.g., rasterize_h3_partition)
- columnslist of str, optional
Columns to include in rasterization
- fmtstr
Output format (‘tif’, ‘nc’)
- compressstr
Compression method for GeoTIFF
- show_progressbool
Show Dask progress bar
- Returns:
- list of str
Paths to output files
- gedih3.raster.export.build_vrt(tif_files, vrt_path)[source]#
Build a GDAL VRT file mosaicking a list of GeoTIFF tiles.
Uses the
osgeo.gdalbindings when they are importable, and falls back tobuild_vrt_xml()otherwise. The GDAL bindings are not pip-installable without a version-matched system libgdal, so pip-only installs take the fallback; conda / HPC installs keep the authoritative backend.- Parameters:
- tif_fileslist of str
Paths to input GeoTIFF files
- vrt_pathstr
Output VRT file path
- Returns:
- str
Path to the written VRT
- gedih3.raster.export.build_vrt_xml(tif_files, vrt_path)[source]#
Write a VRT mosaic as XML using rasterio only — no
osgeobindings.Handles the narrow case gedih3’s own writers emit: north-up GeoTIFF tiles sharing one CRS and one pixel size. Anything outside that (rotated geotransforms, mixed CRS) raises rather than emitting a subtly wrong mosaic — use the
osgeobackend for the general case.As with
build_vrt(), the mosaic resolution is pinned to the first tile so partial edge tiles cannot drag it off the canonical grid.- Parameters:
- tif_fileslist of str
Paths to input GeoTIFF files
- vrt_pathstr
Output VRT file path
- Returns:
- str
Path to the written VRT
- Raises:
- GediRasterizationError
If the tiles are rotated, span multiple CRS, or use a dtype with no GDAL equivalent.
- gedih3.raster.export.build_vrt_safe(tif_files, vrt_path)[source]#
Build a VRT mosaic, downgrading any failure to a warning.
The
.tiftiles are the deliverable; the VRT is a convenience mosaic over them. A missing GDAL backend or an unmosaicable tile set must not discard a completed rasterization job.- Parameters:
- tif_fileslist of str
Paths to input GeoTIFF files
- vrt_pathstr
Output VRT file path
- Returns:
- str or None
Path to the written VRT, or None if it could not be built.
- gedih3.raster.export.merge_and_export_rasters(gdf: geopandas.GeoDataFrame | dask.dataframe.DataFrame, output_path: str, rasterize_func, columns: List[str] | None = None, compress: str = 'LZW', show_progress: bool = True, **rasterize_kwargs) str[source]#
Rasterize all partitions and merge into a single output file.
- Parameters:
- gdfGeoDataFrame or dask GeoDataFrame
Input spatially-indexed data
- output_pathstr
Output file path
- rasterize_funccallable
Function to rasterize each partition
- columnslist of str, optional
Columns to include in rasterization
- compressstr
Compression method for GeoTIFF
- show_progressbool
Show Dask progress bar
- Returns:
- str
Path to output file