pub trait TryMapCoords<T, NT, E> {
    type Output;

    // Required method
    fn try_map_coords(
        &self,
        func: impl Fn((T, T)) -> Result<(NT, NT), E> + Copy
    ) -> Result<Self::Output, E>
       where T: CoordNum,
             NT: CoordNum;
}
👎Deprecated since 0.21.0: use MapCoords::try_map_coords which takes a Coord instead of an (x,y) tuple
Expand description

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

Required Associated Types§

source

type Output

👎Deprecated since 0.21.0: use MapCoords::try_map_coords which takes a Coord instead of an (x,y) tuple

Required Methods§

source

fn try_map_coords( &self, func: impl Fn((T, T)) -> Result<(NT, NT), E> + Copy ) -> Result<Self::Output, E>where T: CoordNum, NT: CoordNum,

👎Deprecated since 0.21.0: use MapCoords::try_map_coords which takes a Coord instead of an (x,y) tuple

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

Examples
use approx::assert_relative_eq;
#[allow(deprecated)]
use geo::TryMapCoords;
use geo::Point;

let p1 = Point::new(10., 20.);
#[allow(deprecated)]
let p2 = p1
    .try_map_coords(|(x, y)| -> Result<_, std::convert::Infallible> {
        Ok((x + 1000., y * 2.))
    }).unwrap();

assert_relative_eq!(p2, Point::new(1010., 40.), epsilon = 1e-6);
Advanced Example: Geometry coordinate conversion using PROJ
use approx::assert_relative_eq;
// activate the [use-proj] feature in cargo.toml in order to access proj functions
use geo::{Coord, Point};
#[allow(deprecated)]
use geo::TryMapCoords;
use proj::{Coord as ProjCoord, Proj, ProjError};
// 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| -> Result<_, ProjError> {
    // proj can accept Point, Coord, 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);
#[allow(deprecated)]
let usa_ft = usa_m.try_map_coords(|(x, y)| f(x, y)).unwrap();
assert_relative_eq!(6693625.67217475, usa_ft.x(), epsilon = 1e-6);
assert_relative_eq!(3497301.5918027186, usa_ft.y(), epsilon = 1e-6);

Implementors§

source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for Geometry<T>

§

type Output = Geometry<NT>

source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for GeometryCollection<T>

source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for Line<T>

§

type Output = Line<NT>

source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for LineString<T>

§

type Output = LineString<NT>

source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for MultiLineString<T>

source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for MultiPoint<T>

§

type Output = MultiPoint<NT>

source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for MultiPolygon<T>

source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for Point<T>

§

type Output = Point<NT>

source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for Polygon<T>

§

type Output = Polygon<NT>

source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for Rect<T>

§

type Output = Rect<NT>

source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for Triangle<T>

§

type Output = Triangle<NT>