Skip to content

Transformations

Module for performing reference systems transformations.

Transformer

A class for performing coordinate transformations between two different EPSG projections.

Parameters:

Name Type Description Default
epsg_from int

EPSG code of the source projection.

required
epsg_to int

EPSG code of the target projection.

required
transform3d bool

Flag indicating whether to perform 3D transformations. Defaults to False.

required
geoid_path Union[str, Path]

Path to a raster file containing geoid undulation data. Required if transform3d is True. Defaults to None.

None

Raises:

Type Description
AssertionError

If epsg_from and epsg_to are the same or not of integer type.

Attributes:

Name Type Description
epsg_from int

EPSG code of the source projection.

epsg_to int

EPSG code of the target projection.

crs_from CRS

CRS object of the source projection.

crs_to CRS

CRS object of the target projection.

_transformer Transformer

Transformer object for performing the coordinate transformation.

transform3d bool

Flag indicating whether to perform 3D transformations.

geoid_path Union[str, Path]

Path to a raster file containing geoid undulation data.

Methods:

Name Description
transform

float, lon: float, ellh: float = None) -> Tuple[float, float] or Tuple[float, float, float]: Transforms a given set of latitude, longitude, and, optionally, ellipsoidal height coordinates from the source projection to the target projection.

Args: lat (float): Latitude coordinate in decimal degrees. lon (float): Longitude coordinate in decimal degrees. ellh (float, optional): Ellipsoidal height coordinate in meters. Required if transform3d is True.

Returns: A tuple containing the transformed x, y, and z (if transform3d` is True) coordinates.

Raises: ValueError: If transform3d is True but geoid_path is not provided.

__init__(epsg_from, epsg_to, transfrom3d=False, geoid_path=None)

Initializes a Transformer object for coordinate transformations.

Parameters:

Name Type Description Default
epsg_from int

EPSG code of the input coordinate reference system (CRS).

required
epsg_to int

EPSG code of the output CRS.

required
transform3d bool

Indicates whether the transform should include a height component. Defaults to False.

required
geoid_path Union[str, Path]

Path to a geoid undulation raster file for height correction. Defaults to None.

None

Raises:

Type Description
AssertionError

Raised if epsg_from and epsg_to are the same integer value.

transform(lat, lon, ellh=None)

Transforms a given set of latitude, longitude, and, optionally, ellipsoidal height coordinates from the source projection to the target projection.

Parameters:

Name Type Description Default
lat float

Latitude coordinate in decimal degrees.

required
lon float

Longitude coordinate in decimal degrees.

required
ellh float

Ellipsoidal height coordinate in meters. Required if transform3d is True.

None

Returns:

Type Description
Tuple[float, float, float]

A tuple containing the transformed x, y, and z (if transform3d is True) coordinates.

Raises:

Type Description
ValueError

If transform3d is True but geoid_path is not provided.

AssertionError

If ellh is not provided for 3D transformations.

bilinear_interpolate(im, x, y)

Performs bilinear interpolation on a 2D array (single channel image given x, y arrays of unstructured query points. Args: im (np.ndarray): Single channel image. x (np.ndarray): nx1 array of x coordinates of query points. y (np.ndarray): nx1 array of y coordinates of query points.

Returns:

Type Description
ndarray

np.ndarray: nx1 array of the interpolated color.

get_geoid_undulation(geoid_path)

Returns the geoid undulation and its affine transformation matrix from a geoid raster file.

Parameters:

Name Type Description Default
geoid_path Union[str, Path]

Path to the geoid raster file.

required

Returns:

Type Description
Tuple[ndarray, Affine]

Tuple[np.ndarray, Affine]: A tuple containing the geoid undulation as a NumPy array and its affine transformation matrix as a Rasterio Affine object.

Raises:

Type Description
ImportError

Raised if rasterio is not installed in the system.

rc2xy(tform, row, col)

Converts row, column coordinates to x, y coordinates using an affine transformation, as stored in the rasterio dataset (i.e., the transformation that maps pixel coordinates to world coordinates)

Parameters:

Name Type Description Default
tform Affine

The affine transformation matrix.

required
row float

The row coordinate.

required
col float

The column coordinate.

required

Returns:

Type Description
Tuple[float, float]

Tuple[float, float]: The x, y coordinates.

xy2rc(tform, x, y)

Converts x, y coordinates to row, column coordinates using an affine transformation, as stored in the rasterio dataset (i.e., the transformation that maps pixel coordinates to world coordinates)

Parameters:

Name Type Description Default
tform Affine

The affine transformation matrix.

required
x float

The x coordinate.

required
y float

The y coordinate.

required

Returns:

Type Description
Tuple[float, float]

Tuple[float, float]: The row, column coordinates.