[][src]Trait geo::algorithm::map_coords::TryMapCoords

pub trait TryMapCoords<T, NT> {
    type Output;
    pub fn try_map_coords(
        &self,
        func: impl Fn(&(T, T)) -> Result<(NT, NT), Box<dyn Error + Send + Sync>> + Copy
    ) -> Result<Self::Output, Box<dyn Error + Send + Sync>>
    where
        T: CoordNum,
        NT: CoordNum
; }

Map a fallible function over all the coordinates in a geometry, returning a Result

Associated Types

Loading content...

Required methods

pub fn try_map_coords(
    &self,
    func: impl Fn(&(T, T)) -> Result<(NT, NT), Box<dyn Error + Send + Sync>> + Copy
) -> Result<Self::Output, Box<dyn Error + Send + Sync>> where
    T: CoordNum,
    NT: CoordNum
[src]

Map a fallible function over all the coordinates in a geometry, returning a Result

Examples

use geo::algorithm::map_coords::TryMapCoords;
use geo::Point;

let p1 = Point::new(10., 20.);
let p2 = p1
    .try_map_coords(|&(x, y)| Ok((x + 1000., y * 2.)))
    .unwrap();

assert_eq!(p2, Point::new(1010., 40.));

Advanced Example: Geometry coordinate conversion using PROJ

// activate the [use-proj] feature in cargo.toml in order to access proj functions
use geo::{Coordinate, Point};
use geo::algorithm::map_coords::TryMapCoords;
use proj::Proj;
// GeoJSON uses the WGS 84 coordinate system
let from = "EPSG:4326";
// The NAD83 / California zone 6 (ftUS) coordinate system
let to = "EPSG:2230";
let to_feet = Proj::new_known_crs(&from, &to, None).unwrap();
let f = |x: f64, y: f64| {
    // proj can accept Point, Coordinate, Tuple, and array values, returning a Result
    let shifted = to_feet.convert((x, y))?;
    Ok((shifted.x(), shifted.y()))
};
// 👽
let usa_m = Point::new(-115.797615, 37.2647978);
let usa_ft = usa_m.try_map_coords(|&(x, y)| f(x, y)).unwrap();
assert_eq!(6693625.67217475, usa_ft.x());
assert_eq!(3497301.5918027186, usa_ft.y());
Loading content...

Implementors

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for Geometry<T>[src]

type Output = Geometry<NT>

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for GeometryCollection<T>[src]

type Output = GeometryCollection<NT>

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for Line<T>[src]

type Output = Line<NT>

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for LineString<T>[src]

type Output = LineString<NT>

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for MultiLineString<T>[src]

type Output = MultiLineString<NT>

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for MultiPoint<T>[src]

type Output = MultiPoint<NT>

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for MultiPolygon<T>[src]

type Output = MultiPolygon<NT>

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for Point<T>[src]

type Output = Point<NT>

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for Polygon<T>[src]

type Output = Polygon<NT>

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for Rect<T>[src]

type Output = Rect<NT>

impl<T: CoordNum, NT: CoordNum> TryMapCoords<T, NT> for Triangle<T>[src]

type Output = Triangle<NT>

Loading content...