Sidereon.Terrain.MmapTerrain (Sidereon v0.39.0)

Copy Markdown View Source

Memory-mappable terrain store conversion and lookup.

A terrain store is a single byte container built from DTED tiles. The reader can be opened from bytes with from_bytes/1 or from a path with from_path/1. Heights returned by this module are typed as orthometric height H in metres above the EGM96 mean sea level geoid. Use the ellipsoidal conversion functions when a WGS84 ellipsoidal height h = H + N is needed.

Terrain lookup axes are always (longitude_deg, latitude_deg).

Summary

Types

Who computed the checksum carried by a terrain handle.

Terrain interpolation method.

t()

Parsed terrain store handle.

Terrain datum conversion or geoid-grid loading error.

Terrain store conversion or parse error.

Functions

Return a checksum for a parsed store handle or terrain store bytes.

Return who computed the checksum carried by this terrain handle.

Convert a DTED tile tree into terrain store bytes.

Return WGS84 ellipsoidal terrain height using the embedded EGM96 1-degree grid.

Return WGS84 ellipsoidal terrain height with an explicit geoid model.

Return WGS84 ellipsoidal terrain height with lookup options.

Parse terrain store bytes into a reader handle.

Open a terrain store file as a reader handle.

Open a terrain store file using a caller-attested full-store checksum.

Parse owned terrain store bytes into a reader handle.

Evaluate (longitude_deg, latitude_deg) points as orthometric heights.

Return orthometric terrain height at (longitude_deg, latitude_deg).

Return orthometric terrain height at (longitude_deg, latitude_deg) with lookup options.

Evaluate (longitude_deg, latitude_deg) points as typed orthometric heights.

Return typed orthometric terrain height at (longitude_deg, latitude_deg).

Return typed orthometric terrain height with lookup options.

Return the FNV-1a checksum for terrain store bytes.

Return parsed tile index records.

Return canonical terrain store bytes from a parsed handle.

Verify tile payloads and any caller-attested full-store checksum.

Return the file-level vertical datum.

Convert a DTED tile tree and write terrain store bytes to out_path.

Types

digest_provenance()

@type digest_provenance() :: :verified | :attested

Who computed the checksum carried by a terrain handle.

interpolation()

@type interpolation() :: :bilinear | :nearest_posting

Terrain interpolation method.

t()

@type t() :: %Sidereon.Terrain.MmapTerrain{handle: reference()}

Parsed terrain store handle.

terrain_datum_error()

@type terrain_datum_error() :: Sidereon.Terrain.MmapTerrain.TerrainDatumError.t()

Terrain datum conversion or geoid-grid loading error.

terrain_store_error()

@type terrain_store_error() :: Sidereon.Terrain.MmapTerrain.TerrainStoreError.t()

Terrain store conversion or parse error.

Functions

checksum64(bytes)

@spec checksum64(t() | binary()) :: non_neg_integer()

Return a checksum for a parsed store handle or terrain store bytes.

digest_provenance(mmap_terrain)

@spec digest_provenance(t()) :: digest_provenance()

Return who computed the checksum carried by this terrain handle.

dted_tree_to_mmap_store(root)

@spec dted_tree_to_mmap_store(String.t()) ::
  {:ok, binary()} | {:error, terrain_store_error() | term()}

Convert a DTED tile tree into terrain store bytes.

ellipsoidal_height_m(terrain, longitude_deg, latitude_deg, opts \\ [])

@spec ellipsoidal_height_m(t(), number(), number(), keyword()) ::
  {:ok, Sidereon.Terrain.MmapTerrain.EllipsoidalHeightM.t()}
  | {:error, terrain_datum_error() | term()}

Return WGS84 ellipsoidal terrain height using the embedded EGM96 1-degree grid.

ellipsoidal_height_m_with_model(mmap_terrain, longitude_deg, latitude_deg, model, opts \\ [])

@spec ellipsoidal_height_m_with_model(
  t(),
  number(),
  number(),
  Sidereon.Terrain.MmapTerrain.TerrainGeoidModel.t() | :egm96_one_degree,
  keyword()
) ::
  {:ok, Sidereon.Terrain.MmapTerrain.EllipsoidalHeightM.t()}
  | {:error, terrain_datum_error() | term()}

Return WGS84 ellipsoidal terrain height with an explicit geoid model.

Passing TerrainGeoidModel.egm96_fifteen_minute/1 requires a loaded Egm96FifteenMinuteGeoid; it never falls back to the embedded 1-degree grid.

ellipsoidal_height_m_with_options(mmap_terrain, longitude_deg, latitude_deg, opts)

@spec ellipsoidal_height_m_with_options(t(), number(), number(), keyword()) ::
  {:ok, Sidereon.Terrain.MmapTerrain.EllipsoidalHeightM.t()}
  | {:error, terrain_datum_error() | term()}

Return WGS84 ellipsoidal terrain height with lookup options.

from_bytes(bytes)

@spec from_bytes(binary()) :: {:ok, t()} | {:error, terrain_store_error() | term()}

Parse terrain store bytes into a reader handle.

from_path(path)

@spec from_path(String.t()) :: {:ok, t()} | {:error, terrain_store_error() | term()}

Open a terrain store file as a reader handle.

The file is memory-mapped read-only and the reader owns the mapping, so opening a store does not cost its size in process memory. The mapping is demand-paged: a reader querying a geographically local region faults in only the pages covering those tiles, and construction parses the header, datum tag, and tile index and nothing else.

from_path_attested(path, claimed_checksum64)

@spec from_path_attested(String.t(), non_neg_integer()) ::
  {:ok, t()}
  | {:error, terrain_store_error() | {:invalid_checksum64, term()} | term()}

Open a terrain store file using a caller-attested full-store checksum.

The file is memory-mapped read-only. Construction validates its header, datum tag, tile index, dimensions, and payload bounds without hashing tile payloads. The claim is returned by checksum64/1 until verify/1 succeeds.

from_vec(bytes)

@spec from_vec(binary()) :: {:ok, t()} | {:error, terrain_store_error() | term()}

Parse owned terrain store bytes into a reader handle.

height_batch(terrain, points, opts \\ [])

@spec height_batch(t(), [{number(), number()}], keyword()) ::
  [ok: Sidereon.Terrain.MmapTerrain.OrthometricHeightM.t(), error: term()]
  | {:error, term()}

Evaluate (longitude_deg, latitude_deg) points as orthometric heights.

height_m(terrain, longitude_deg, latitude_deg, opts \\ [])

@spec height_m(t(), number(), number(), keyword()) ::
  {:ok, Sidereon.Terrain.MmapTerrain.OrthometricHeightM.t()} | {:error, term()}

Return orthometric terrain height at (longitude_deg, latitude_deg).

height_m_with_options(mmap_terrain, longitude_deg, latitude_deg, opts)

@spec height_m_with_options(t(), number(), number(), keyword()) ::
  {:ok, Sidereon.Terrain.MmapTerrain.OrthometricHeightM.t()} | {:error, term()}

Return orthometric terrain height at (longitude_deg, latitude_deg) with lookup options.

orthometric_height_batch(mmap_terrain, points, opts \\ [])

@spec orthometric_height_batch(t(), [{number(), number()}], keyword()) ::
  [ok: Sidereon.Terrain.MmapTerrain.OrthometricHeightM.t(), error: term()]
  | {:error, term()}

Evaluate (longitude_deg, latitude_deg) points as typed orthometric heights.

orthometric_height_m(terrain, longitude_deg, latitude_deg, opts \\ [])

@spec orthometric_height_m(t(), number(), number(), keyword()) ::
  {:ok, Sidereon.Terrain.MmapTerrain.OrthometricHeightM.t()} | {:error, term()}

Return typed orthometric terrain height at (longitude_deg, latitude_deg).

orthometric_height_m_with_options(mmap_terrain, longitude_deg, latitude_deg, opts)

@spec orthometric_height_m_with_options(t(), number(), number(), keyword()) ::
  {:ok, Sidereon.Terrain.MmapTerrain.OrthometricHeightM.t()} | {:error, term()}

Return typed orthometric terrain height with lookup options.

terrain_store_checksum64(bytes)

@spec terrain_store_checksum64(binary()) :: non_neg_integer()

Return the FNV-1a checksum for terrain store bytes.

tile_index(mmap_terrain)

Return parsed tile index records.

to_bytes(mmap_terrain)

@spec to_bytes(t()) :: binary()

Return canonical terrain store bytes from a parsed handle.

verify(mmap_terrain)

@spec verify(t()) :: :ok | {:error, terrain_store_error() | term()}

Verify tile payloads and any caller-attested full-store checksum.

On success, digest_provenance/1 returns :verified.

vertical_datum(mmap_terrain)

@spec vertical_datum(t()) :: Sidereon.Terrain.MmapTerrain.VerticalDatum.t()

Return the file-level vertical datum.

write_dted_tree_to_mmap_store(root, out_path)

@spec write_dted_tree_to_mmap_store(String.t(), String.t()) ::
  :ok | {:error, terrain_store_error() | term()}

Convert a DTED tile tree and write terrain store bytes to out_path.