Skip to main content

CrsTransformer

Struct CrsTransformer 

Source
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

Source

pub fn new( source_crs: impl Into<String>, target_crs: impl Into<String>, ) -> Result<Self>

Creates a new CRS transformer

§Arguments
  • source_crs - Source CRS (e.g., “EPSG:4326”)
  • target_crs - Target CRS (e.g., “EPSG:3857”)
§Returns

A new transformer

§Errors

Returns error if CRS definitions are invalid

Source

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.

Source

pub fn out_of_area_policy(&self) -> OutOfAreaPolicy

Returns the currently configured OutOfAreaPolicy.

Source

pub fn from_common(source: CommonCrs, target: CommonCrs) -> Result<Self>

Creates a transformer from common CRS types

Source

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.

Source

pub fn transform_coordinates( &self, coords: &[Coordinate], ) -> Result<Vec<Coordinate>>

Transforms multiple coordinates efficiently

Source

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).

Source

pub fn transform_point(&self, point: &Point) -> Result<Point>

Transforms a point

Source

pub fn transform_linestring( &self, linestring: &LineString, ) -> Result<LineString>

Transforms a linestring

Source

pub fn transform_polygon(&self, polygon: &Polygon) -> Result<Polygon>

Transforms a polygon

Source

pub fn transform_geometry(&self, geometry: &Geometry) -> Result<Geometry>

Transforms a geometry

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more