pub struct CrsTransformer { /* private fields */ }Expand description
Transformer for coordinate reference system conversions
When the crs-transform feature is enabled, this uses the oxigdal-proj
backend (pure-Rust proj4rs) for arbitrary CRS pairs. The two hardcoded
paths (WGS84↔Web Mercator) are kept as a fallback so that the API behaves
identically when the feature is disabled.
§Area-of-use handling
A point that lies outside the source CRS’s declared area of use is handled
according to CrsTransformer’s OutOfAreaPolicy (default
OutOfAreaPolicy::PassThrough). See CrsTransformer::with_out_of_area_policy
and CrsTransformer::transform_coordinates_reporting.
Implementations§
Source§impl CrsTransformer
impl CrsTransformer
Sourcepub fn with_out_of_area_policy(self, policy: OutOfAreaPolicy) -> Self
pub fn with_out_of_area_policy(self, policy: OutOfAreaPolicy) -> Self
Sets the policy for coordinates outside the source CRS’s area of use.
Returns self for builder-style chaining. Under
OutOfAreaPolicy::Error, the proj backend (when the crs-transform
feature is enabled) is rebuilt with strict area-of-use validation so that
out-of-area points are actually detected and surfaced as errors rather
than silently transformed or passed through.
Sourcepub fn out_of_area_policy(&self) -> OutOfAreaPolicy
pub fn out_of_area_policy(&self) -> OutOfAreaPolicy
Returns the currently configured OutOfAreaPolicy.
Sourcepub fn from_common(source: CommonCrs, target: CommonCrs) -> Result<Self>
pub fn from_common(source: CommonCrs, target: CommonCrs) -> Result<Self>
Creates a transformer from common CRS types
Sourcepub fn transform_coordinate(&self, coord: &Coordinate) -> Result<Coordinate>
pub fn transform_coordinate(&self, coord: &Coordinate) -> Result<Coordinate>
Transforms a single coordinate
§Arguments
coord- Input coordinate in source CRS
§Returns
Transformed coordinate in target CRS
§Area of use
When the crs-transform feature is enabled, a point that lies outside
the source CRS’s declared area of use is handled per the configured
OutOfAreaPolicy (see Self::with_out_of_area_policy). Under the
default OutOfAreaPolicy::PassThrough such a point is returned
unchanged in the source CRS (with a debug-level log); under
OutOfAreaPolicy::Error it produces an error. To transform a whole
geometry and learn which vertices fell out of area without aborting, use
Self::transform_coordinates_reporting.
§Errors
Returns error if transformation fails, or if a coordinate is outside the
area of use and the policy is OutOfAreaPolicy::Error.
Sourcepub fn transform_coordinates(
&self,
coords: &[Coordinate],
) -> Result<Vec<Coordinate>>
pub fn transform_coordinates( &self, coords: &[Coordinate], ) -> Result<Vec<Coordinate>>
Transforms multiple coordinates efficiently
Sourcepub fn transform_coordinates_reporting(
&self,
coords: &[Coordinate],
) -> Result<(Vec<Coordinate>, Vec<usize>)>
pub fn transform_coordinates_reporting( &self, coords: &[Coordinate], ) -> Result<(Vec<Coordinate>, Vec<usize>)>
Transforms multiple coordinates, reporting the indices of any that fell outside the source CRS’s area of use (and were passed through unchanged).
This lets callers detect and reject/filter a geometry that would
otherwise silently mix coordinate systems, without switching to the
hard-error OutOfAreaPolicy::Error. The returned index list is always
empty unless the crs-transform feature is active and the current policy
is OutOfAreaPolicy::PassThrough.
§Errors
Propagates any transformation error (including out-of-area errors when
the policy is OutOfAreaPolicy::Error).
Sourcepub fn transform_point(&self, point: &Point) -> Result<Point>
pub fn transform_point(&self, point: &Point) -> Result<Point>
Transforms a point
Sourcepub fn transform_linestring(
&self,
linestring: &LineString,
) -> Result<LineString>
pub fn transform_linestring( &self, linestring: &LineString, ) -> Result<LineString>
Transforms a linestring
Sourcepub fn transform_polygon(&self, polygon: &Polygon) -> Result<Polygon>
pub fn transform_polygon(&self, polygon: &Polygon) -> Result<Polygon>
Transforms a polygon
Sourcepub fn transform_geometry(&self, geometry: &Geometry) -> Result<Geometry>
pub fn transform_geometry(&self, geometry: &Geometry) -> Result<Geometry>
Transforms a geometry
Auto Trait Implementations§
impl !Freeze for CrsTransformer
impl RefUnwindSafe for CrsTransformer
impl Send for CrsTransformer
impl Sync for CrsTransformer
impl Unpin for CrsTransformer
impl UnsafeUnpin for CrsTransformer
impl UnwindSafe for CrsTransformer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more