Module rast_gdal

rast_gdal — bridge to GDAL for windowed raster I/O.

Description

rast_gdal — bridge to GDAL for windowed raster I/O.

rast does not implement raster I/O, reprojection, COG, CRS or nodata semantics — GDAL owns all of that (ARCHITECTURE.md §8). This module is the seam. It is a **CLI port** driven via open_port({spawn_executable, ...}) (no shell, so no Windows quoting hell): metadata via gdalinfo -json, windowed reads via gdal_translate -srcwin into a headerless ENVI raw that Erlang reads back. (Per-tile subprocess spawn is the simple first cut; a persistent port or a dedicated NIF over the gdal crate is the later optimization.)

Writes go the other way: GDAL cannot easily patch a sub-window into an existing raster from the CLI, so the output is owned by Erlang as a flat raw file — workers pwrite their tiles at the right offsets — and a single gdal_translate wraps the finished raw into a GeoTIFF at the end.

GDAL location: application:get_env(rast, gdal_bin_dir), else $GDAL_BIN_DIR, else the platform default (C:/Program Files/GDAL on Windows), else PATH.

Data Types

handle()

handle() = #{source := string(), width := pos_integer(), height := pos_integer(), bands := pos_integer(), dtype := binary()}

out()

out() = #{path := string(), fd := file:io_device(), width := pos_integer(), height := pos_integer(), bpp := pos_integer(), dtype := binary()}

window()

window() = rast_tiling:tile()

Function Index

available/0Whether the GDAL CLI can actually be run.
close/1Release the handle (no-op for the CLI port).
create_output/4Create a flat raw output sized W × H, ready for windowed pwrites.
finalize/1Close the raw file and wrap it into a GeoTIFF at Path via a single gdal_translate.
info/1Metadata map for an open handle.
open/1Open a raster source and read its metadata via gdalinfo -json.
read_window/2Read band 1 of a window as a little-endian binary in the source dtype.
read_window/3Read Band of a window as a little-endian binary in the source dtype.
write_window/3Scatter a tile result into the flat output: TH row-writes at the tile's byte offsets in the full-width raster.

Function Details

available/0

available() -> boolean()

Whether the GDAL CLI can actually be run. Probes by executing gdalinfo --version; a missing or non-runnable binary yields false (so the GDAL-backed tests skip cleanly rather than fail).

close/1

close(Handle::handle()) -> ok

Release the handle (no-op for the CLI port).

create_output/4

create_output(Path::string(), W::pos_integer(), H::pos_integer(), X4::map()) -> {ok, out()} | {error, term()}

Create a flat raw output sized W × H, ready for windowed pwrites. DType is the *output* dtype (e.g. <<"Float32">> for NDVI results).

finalize/1

finalize(X1::out()) -> {ok, string()} | {error, term()}

Close the raw file and wrap it into a GeoTIFF at Path via a single gdal_translate. Writes a minimal ENVI header so GDAL can read the raw.

info/1

info(Handle::handle()) -> {ok, map()} | {error, term()}

Metadata map for an open handle.

open/1

open(Source::string()) -> {ok, handle()} | {error, term()}

Open a raster source and read its metadata via gdalinfo -json.

read_window/2

read_window(Handle::handle(), Window::window()) -> {ok, binary()} | {error, term()}

Read band 1 of a window as a little-endian binary in the source dtype.

read_window/3

read_window(X1::handle(), X2::window(), Band::pos_integer()) -> {ok, binary()} | {error, term()}

Read Band of a window as a little-endian binary in the source dtype. For convolution, pass a window already grown by the halo width.

write_window/3

write_window(X1::out(), X2::window(), Bin::binary()) -> ok | {error, term()}

Scatter a tile result into the flat output: TH row-writes at the tile's byte offsets in the full-width raster.


Generated by EDoc