Rust bindings for PROJ, v6.2.x
```rust use proj::Proj;
extern crate geotypes; use geotypes::Point;
let from = "EPSG:2230"; let to = "EPSG:26946"; let fttom = Proj::newknowncrs(&from, &to, None).unwrap(); let result = fttom .convert(Point::new(4760096.421921, 3744293.729449)) .unwrap(); assertalmosteq(result.x(), 1450880.29); assertalmosteq(result.y(), 1141263.01); ```
Note that as of v5.0.0, PROJ uses the pipeline
operator, which allows an arbitrary number of steps in a conversion. The example below works as follows:
pipeline
operationstep
1 as an inv
erse transform, yielding geodetic coordinatesstep
2 as a forward transform to projected coordinates, yielding metres.pipeline
Operator```rust use proj::Proj;
extern crate geotypes; use geotypes::Point;
let fttom = Proj::new(" +proj=pipeline +step +inv +proj=lcc +lat1=33.88333333333333 +lat2=32.78333333333333 +lat0=32.16666666666666 +lon0=-116.25 +x0=2000000.0001016 +y0=500000.0001016001 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +nodefs +step +proj=lcc +lat1=33.88333333333333 +lat2=32.78333333333333 +lat0=32.16666666666666 +lon0=-116.25 +x0=2000000 +y0=500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +nodefs ").unwrap(); // The Presidio, approximately let result = fttom.convert(Point::new(4760096.421921, 3744293.729449)).unwrap(); asserteq!(result.x(), 1450880.29); asserteq!(result.y(), 1141263.01); ```
```rust use proj::Proj;
extern crate geotypes; use geotypes::Point;
// Carry out an inverse projection from Pulkovo 1942(58) / Stereo70 (EPSG 3844) into geodetic lon and lat coordinates (in radians) let stereo70 = Proj::new( "+proj=sterea +lat0=46 +lon0=25 +k=0.99975 +x0=500000 +y0=500000 +ellps=krass +towgs84=33.4,-146.6,-76.3,-0.359,-0.053,0.844,-0.84 +units=m +nodefs" ).unwrap(); let rp = stereo70.project(Point::new(500119.70352012233, 500027.77896348457), true).unwrap(); asserteq!(rp, Point::new(0.436332, 0.802851)); ```
Licensed under either of
at your option.