Trait proj::Transform

source ·
pub trait Transform<T> {
    type Output;

    // Required methods
    fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>;
    fn transformed(&self, proj: &Proj) -> Result<Self::Output, ProjError>;

    // Provided methods
    fn transform_crs_to_crs(
        &mut self,
        source_crs: &str,
        target_crs: &str
    ) -> Result<(), TransformError> { ... }
    fn transformed_crs_to_crs(
        &self,
        source_crs: &str,
        target_crs: &str
    ) -> Result<Self::Output, TransformError> { ... }
}
Expand description

Transform a geometry using PROJ.

Required Associated Types§

Required Methods§

source

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

Transform a Geometry by mutating it in place.

Examples

Transform a geometry using a PROJ string definition:

use geo_types;
use proj::{Proj, Transform};

let mut point = geo_types::point!(x: -36.508f32, y: -54.2815f32);
let proj = Proj::new("+proj=axisswap +order=2,1,3,4").expect("invalid proj string");
 point.transform(&proj);

assert_relative_eq!(
    point,
    geo_types::point!(x: -54.2815f32, y: -36.508f32)
);
source

fn transformed(&self, proj: &Proj) -> Result<Self::Output, ProjError>

Immutable flavor of Transform::transform, which allocates a new geometry.

Examples

Transform a geometry using a PROJ string definition:

use geo_types;
use proj::{Proj, Transform};

let point = geo_types::point!(x: -36.508f32, y: -54.2815f32);
let proj = Proj::new("+proj=axisswap +order=2,1,3,4").expect("invalid proj string");

assert_relative_eq!(
    point.transformed(&proj).unwrap(),
    geo_types::point!(x: -54.2815f32, y: -36.508f32)
);

// original `point` is untouched
assert_relative_eq!(
    point,
    geo_types::point!(x: -36.508f32, y: -54.2815f32)
);

Provided Methods§

source

fn transform_crs_to_crs( &mut self, source_crs: &str, target_crs: &str ) -> Result<(), TransformError>

Transform a geometry from one CRS to another CRS by modifying it in place.

Examples
use proj::Transform;
use geo_types::{point, Point};

let mut point: Point<f32> = point!(x: -36.508f32, y: -54.2815f32);
point.transform_crs_to_crs("EPSG:4326", "EPSG:3857").unwrap();

assert_relative_eq!(point, point!(x: -4064052.0f32, y: -7223650.5f32));
source

fn transformed_crs_to_crs( &self, source_crs: &str, target_crs: &str ) -> Result<Self::Output, TransformError>

Immutable flavor of Transform::transform_crs_to_crs, which allocates a new geometry.

Examples
use proj::Transform;
use geo_types::{point, Point};

let mut point: Point<f32> = point!(x: -36.508f32, y: -54.2815f32);

assert_relative_eq!(
    point.transformed_crs_to_crs("EPSG:4326", "EPSG:3857").unwrap(),
    point!(x: -4064052.0f32, y: -7223650.5f32)
);

Implementations on Foreign Types§

source§

impl<T> Transform<T> for Polygon<T>where T: CoordinateType,

§

type Output = Polygon<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

source§

impl<T> Transform<T> for LineString<T>where T: CoordinateType,

§

type Output = LineString<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

source§

impl<T> Transform<T> for GeometryCollection<T>where T: CoordinateType,

§

type Output = GeometryCollection<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

source§

impl<T> Transform<T> for Line<T>where T: CoordinateType,

§

type Output = Line<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

source§

impl<T> Transform<T> for Geometry<T>where T: CoordinateType,

§

type Output = Geometry<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

source§

impl<T> Transform<T> for Point<T>where T: CoordinateType,

§

type Output = Point<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

source§

impl<T> Transform<T> for Triangle<T>where T: CoordinateType,

§

type Output = Triangle<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

source§

impl<T> Transform<T> for Rect<T>where T: CoordinateType,

§

type Output = Rect<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

source§

impl<T> Transform<T> for MultiPoint<T>where T: CoordinateType,

§

type Output = MultiPoint<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

source§

impl<T> Transform<T> for MultiLineString<T>where T: CoordinateType,

§

type Output = MultiLineString<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

source§

impl<T> Transform<T> for Coord<T>where T: CoordinateType,

§

type Output = Coord<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

source§

impl<T> Transform<T> for MultiPolygon<T>where T: CoordinateType,

§

type Output = MultiPolygon<T>

source§

fn transformed(&self, proj: &Proj) -> Result<Self, ProjError>

source§

fn transform(&mut self, proj: &Proj) -> Result<(), ProjError>

Implementors§