[−][src]Module geo::algorithm::map_coords
Apply a function to all Coordinates
of a Geometry
.
Advanced Example: Fallible 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());
Traits
MapCoords | Map a function over all the coordinates in an object, returning a new one |
MapCoordsInplace | Map a function over all the coordinates in an object in place |
TryMapCoords | Map a fallible function over all the coordinates in a geometry, returning a Result |