CoordinateTransformer#
Class Methods
Create a transformer from a PROJ pipeline definition. |
|
|
Create a coordinate transformer from source CRS to target CRS. |
Methods
Return whether the coordinate array has a Z component. |
|
|
Transform coordinates using the configured transformer chain. |
Properties
Return the source CRS of the transformer chain. |
|
Return the target CRS of the transformer chain. |
- class weitsicht.CoordinateTransformer(transformer: Transformer)[source]#
- class weitsicht.CoordinateTransformer(transformer: list[Transformer])
Bases:
objectClass to handle transformations of coordinates. Basically a little pyproj wrapper with basic functions needed in the package.
- Parameters:
transformer (Transformer | list[Transformer])
- __init__(transformer: Transformer)[source]#
- __init__(transformer: list[Transformer])
Create a transformer wrapper.
- Parameters:
transformer (Transformer | list[Transformer]) – A single pyproj transformer or a chain of transformers.
- property source_crs: CRS | None#
Return the source CRS of the transformer chain.
- property target_crs: CRS | None#
Return the target CRS of the transformer chain.
- classmethod from_pipeline(proj_pipeline: str)[source]#
Create a transformer from a PROJ pipeline definition.
- Parameters:
proj_pipeline (str) – PROJ pipeline string.
- Returns:
Transformer instance.
- Return type:
- Raises:
CoordinateTransformationError – If the pipeline cannot be established.
- classmethod from_crs(crs_s: CRS | None, crs_t: CRS | None) CoordinateTransformer | None[source]#
Create a coordinate transformer from source CRS to target CRS.
If both CRSs are
Noneor equal, this returnsNone(no transformation required).- Parameters:
crs_s (CRS | None) – Source CRS, or
None.crs_t (CRS | None) – Target CRS, or
None.
- Returns:
Coordinate transformer or
Noneif no transformation is required.- Return type:
CoordinateTransformer | None
- Raises:
ValueError – If only one CRS is
None.CoordinateTransformationError – If establishing a transformation fails.
- static is_3d(coo: ArrayNx2 | ArrayNx3)[source]#
Return whether the coordinate array has a Z component.
- Parameters:
coo (ArrayNx2 | ArrayNx3) – Coordinate array.
- Returns:
Trueif the input has shape N×3.- Return type:
bool
- transform(coordinates: ArrayNx3 | ArrayNx2, direction: str = 'forward') ArrayNx3 | ArrayNx2[source]#
Transform coordinates using the configured transformer chain.
- Parameters:
coordinates (ArrayNx3 | ArrayNx2) – Coordinates to transform as N×2 (2D) or N×3 (3D).
direction (str) – Transform direction (
forward,inverse,identity), defaults toforward.
- Returns:
Transformed coordinates with the same dimensionality as input.
- Return type:
ArrayNx3 | ArrayNx2
- Raises:
CoordinateTransformationError – If input dimensions are invalid or a transformation fails.
- transform_vector(coordinates_start: ArrayNx3, vector: ArrayNx3, direction: str = 'forward') ArrayNx3[source]#
Transform direction vectors using the configured transformer chain.
Vectors can not be transformed directly through most CRS transformations, therefore this helper transforms two points per vector and derives the resulting direction:
startandstart + unit(vector) * 10(i.e. 10 units along the provided vector direction).- Parameters:
coordinates_start (ArrayNx3) – Start coordinates (N×3).
vector (ArrayNx3) – Direction vectors in the source CRS (N×3 or single 3-vector).
direction (str) – Transform direction (
forward,inverse,identity), defaults toforward.
- Returns:
Unit direction vectors in the target CRS (N×3).
- Return type:
ArrayNx3
- Raises:
ValueError – If input shapes are incompatible or vectors have zero length.
CoordinateTransformationError – If transforming coordinates fails.