MappingGeorefArray#

For deeper information about the concept see: GeorefArray Mapper

Class Methods

MappingGeorefArray.from_dict(mapper_dict)

Create a mapper from a configuration dictionary.

Main API Methods

MappingGeorefArray.map_coordinates_from_rays(...)

Map coordinates by intersecting rays with the raster surface.

MappingGeorefArray.map_heights_from_coordinates(...)

Sample heights for given coordinates using bilinear interpolation.

Methods Raster specific

This functions can be used to interact with the raster and coordinates

MappingGeorefArray.pixel_to_coordinate(...)

Convert pixel indices to coordinates in raster CRS.

MappingGeorefArray.pixel_valid(px_row, px_col)

Vectorized validity check for pixel coordinates.

MappingGeorefArray.coordinate_on_raster(...)

Test if given coordinates in raster CRS are on the raster

MappingGeorefArray.coordinate_to_pixel(x, y)

Convert raster CRS coordinates to pixel indices.

Properties

MappingGeorefArray.type

Return the mapper type.

MappingGeorefArray.param_dict

Return the mapper configuration dictionary.

MappingGeorefArray.crs

Return the CRS of the mapper (if set).

MappingGeorefArray.crs_wkt

Return the CRS as WKT string, or None if not set.

MappingGeorefArray.transform

Return the affine geo-transform.

MappingGeorefArray.width

Return raster width in pixels.

MappingGeorefArray.height

Return raster height in pixels.

class weitsicht.MappingGeorefArray(raster_array: ndarray[tuple[Any, ...], dtype[_ScalarT]], geo_transform: Affine, crs: CRS | None)[source]#

Bases: MappingBase

Mapping backend using an in-memory geo-referenced raster array.

This backend is typically used internally (e.g. for raster window caching) and supports height sampling and ray intersections using bilinear patches.

Parameters:
  • raster_array (ArrayNxN)

  • geo_transform (Affine)

  • crs (CRS | None)

__init__(raster_array: ndarray[tuple[Any, ...], dtype[_ScalarT]], geo_transform: Affine, crs: CRS | None)[source]#

Create a mapper backed by a numpy array and an affine geo-transform.

Parameters:
  • raster_array (ArrayNxN) – Raster data array (rows × cols) holding height values.

  • geo_transform (Affine) – Affine transformation mapping pixel indices to raster CRS coordinates.

  • crs (CRS | None) – CRS of the raster array, defaults to None.

Raises:

CRSnoZaxisError – If a specified CRS does not define a Z axis.

property transform#

Return the affine geo-transform.

Returns:

Affine geo-transform.

Return type:

Affine

property width#

Return raster width in pixels.

property height#

Return raster height in pixels.

classmethod from_dict(mapper_dict: Mapping[str, Any]) MappingGeorefArray[source]#

Create a mapper from a configuration dictionary.

This is currently not supported for MappingGeorefArray.

Raises:

NotImplementedError – Always raised.

Parameters:

mapper_dict (Mapping[str, Any])

Return type:

MappingGeorefArray

property type: MappingType#

Return the mapper type.

property param_dict: dict#

Return the mapper configuration dictionary.

This is currently not supported for MappingGeorefArray.

Raises:

NotImplementedError – Always raised.

pixel_to_coordinate(px_row: ArrayN_, px_col: ArrayN_) tuple[source]#

Convert pixel indices to coordinates in raster CRS.

Parameters:
  • px_row (ArrayN_) – Pixel row coordinate

  • px_col (ArrayN_) – Pixel column coordinate

Returns:

(x, y) coordinates in raster CRS.

Return type:

tuple[ArrayN_, ArrayN_]

coordinate_to_pixel(x: ArrayN_, y: ArrayN_) tuple[ArrayN_, ArrayN_][source]#

Convert raster CRS coordinates to pixel indices.

Parameters:
  • x (ArrayN_) – X coordinate in raster CRS.

  • y (ArrayN_) – Y coordinate in raster CRS.

Returns:

(row, col) pixel coordinates.

Return type:

tuple[ArrayN_, ArrayN_]

pixel_valid(px_row: ArrayN_, px_col: ArrayN_) MaskN_[source]#

Vectorized validity check for pixel coordinates.

Parameters:
  • px_row (ArrayN_) – Pixel row coordinate

  • px_col (ArrayN_) – Pixel column coordinate

Returns:

Boolean mask for valid pixels.

Return type:

MaskN_

pixel_valid_index_ray_bilinear_shifted(px_row: ArrayN_, px_col: ArrayN_) ndarray[source]#

Return indices of pixels valid for bilinear ray intersection.

This check assumes pixel coordinates are already shifted by 0.5. Border pixels are excluded because bilinear patches require 4 surrounding corner points.

Parameters:
  • px_row (ArrayN_) – Pixel row coordinate already shifted by 0.5

  • px_col (ArrayN_) – Pixel column coordinate already shifted by 0.5

Returns:

Indices of valid pixels.

Return type:

numpy.ndarray

coordinate_on_raster(x_crs: ArrayN_, y_crs: ArrayN_) bool[source]#

Test if given coordinates in raster CRS are on the raster

Parameters:
  • x_crs (ArrayN_) – X coordinate

  • y_crs (ArrayN_) – Y coordinate

Returns:

True if all coordinates are within raster bounds.

Return type:

bool

map_coordinates_from_rays_old_sampling(ray_vectors_crs_s: ArrayNx3, ray_start_crs_s: ArrayNx3, crs_s: CRS) ArrayNx3 | None[source]#

Legacy ray intersection method using dense sampling (deprecated).

Parameters:
  • ray_vectors_crs_s (ArrayNx3) – Ray direction vectors (N×3).

  • ray_start_crs_s (ArrayNx3) – Ray start points (N×3).

  • crs_s (CRS) – CRS of the input rays.

Returns:

Intersection coordinates or None if no intersection was found.

Return type:

ArrayNx3 | None

Raises:

CoordinateTransformationError – If coordinate transformation fails.

map_coordinates_from_rays(ray_vectors_crs_s: ArrayNx3, ray_start_crs_s: ArrayNx3, crs_s: CRS | None = None, transformer: CoordinateTransformer | None = None) MappingResultSuccess | ResultFailure[Issue][source]#

Map coordinates by intersecting rays with the raster surface.

Parameters:
  • ray_vectors_crs_s (ArrayNx3) – Ray direction vectors (N×3).

  • ray_start_crs_s (ArrayNx3) – Ray start points (N×3), same shape as ray_vectors_crs_s.

  • crs_s (CRS | None) – CRS of the input rays, defaults to None.

  • transformer (CoordinateTransformer | None) – Coordinate transformer to mapper CRS, defaults to None.

Returns:

Mapping result containing intersection coordinates and a validity mask.

Return type:

MappingResult

Raises:
map_heights_from_coordinates(coordinates_crs_s: ArrayNx3 | ArrayNx2, crs_s: CRS | None = None, transformer: CoordinateTransformer | None = None) MappingResultSuccess | ResultFailure[Issue][source]#

Sample heights for given coordinates using bilinear interpolation.

Parameters:
  • coordinates_crs_s (ArrayNx3 | ArrayNx2) – Coordinates to sample (N×2 or N×3).

  • crs_s (CRS | None) – CRS of the input coordinates, defaults to None.

  • transformer (CoordinateTransformer | None) – Coordinate transformer to mapper CRS, defaults to None.

Returns:

Mapping result containing sampled coordinates and a validity mask.

Return type:

MappingResult

Raises: