Coder Social home page Coder Social logo

rust-proj's Introduction

PROJ

High-level Rust bindings for the latest stable version of PROJ (7.0.x), compatible with the Georust ecosystem.

Examples

Convert from NAD 83 US Survey Feet to NAD 83 Meters Using EPSG Codes

use proj::Proj;

extern crate geo_types;
use geo_types::Point;

let from = "EPSG:2230";
let to = "EPSG:26946";
let ft_to_m = Proj::new_known_crs(&from, &to, None).unwrap();
let result = ft_to_m
    .convert(Point::new(4760096.421921, 3744293.729449))
    .unwrap();
assert_almost_eq(result.x(), 1450880.29);
assert_almost_eq(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:

  • define the operation as a pipeline operation
  • define step 1 as an inverse transform, yielding geodetic coordinates
  • define step 2 as a forward transform to projected coordinates, yielding metres.

Convert from NAD 83 US Survey Feet to NAD 83 Meters Using the pipeline Operator

use proj::Proj;

extern crate geo_types;
use geo_types::Point;

let ft_to_m = Proj::new("
    +proj=pipeline
    +step +inv +proj=lcc +lat_1=33.88333333333333
    +lat_2=32.78333333333333 +lat_0=32.16666666666666
    +lon_0=-116.25 +x_0=2000000.0001016 +y_0=500000.0001016001 +ellps=GRS80
    +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs
    +step +proj=lcc +lat_1=33.88333333333333 +lat_2=32.78333333333333 +lat_0=32.16666666666666
    +lon_0=-116.25 +x_0=2000000 +y_0=500000
    +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
").unwrap();
// The Presidio, approximately
let result = ft_to_m.convert(Point::new(4760096.421921, 3744293.729449)).unwrap();
assert_eq!(result.x(), 1450880.29);
assert_eq!(result.y(), 1141263.01);

Inverse Projection from Stereo70 to Geodetic

use proj::Proj;

extern crate geo_types;
use geo_types::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 +lat_0=46 +lon_0=25 +k=0.99975 +x_0=500000 +y_0=500000
    +ellps=krass +towgs84=33.4,-146.6,-76.3,-0.359,-0.053,0.844,-0.84
    +units=m +no_defs
    ").unwrap();
let rp = stereo70.project(
    Point::new(500119.70352012233, 500027.77896348457), true
).unwrap();
assert_eq!(rp, Point::new(0.436332, 0.802851));

Bulk Transformations

The Proj::convert_array() method is available for bulk conversions. It accepts a mutable slice (or anything that can Deref to a mutable slice) of Point<T: Float> or Into<Point<T: Float> elements.

License

Licensed under either of

at your option.

rust-proj's People

Contributors

bors[bot] avatar eminence avatar frewsxcv avatar lnicola avatar urschrei avatar woshilapin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.