#projection #geo #proj #osgeo

proj

High-level Rust bindings for the latest stable version of PROJ

39 releases (17 breaking)

new 0.20.2 Aug 1, 2020
0.20.1 Jul 31, 2020
0.19.0 Jul 3, 2020
0.15.1 Mar 9, 2020
0.1.1 Jul 1, 2015

#16 in Science

Download history 958/week @ 2020-04-17 613/week @ 2020-04-24 213/week @ 2020-05-01 228/week @ 2020-05-08 315/week @ 2020-05-15 645/week @ 2020-05-22 607/week @ 2020-05-29 757/week @ 2020-06-05 1900/week @ 2020-06-12 1506/week @ 2020-06-19 1112/week @ 2020-06-26 1115/week @ 2020-07-03 448/week @ 2020-07-10 577/week @ 2020-07-17 1201/week @ 2020-07-24 772/week @ 2020-07-31

3,621 downloads per month
Used in 2 crates

MIT/Apache

63KB
866 lines

PROJ

High-level Rust bindings for the latest stable version of PROJ (7.1.x), compatible with the Georust ecosystem. Includes network grid download functionality.

Requirements

By default, this crate depends on a pre-built libproj, so PROJ v7.1.x must be present on your system. While this crate may be backwards-compatible with older PROJ 7 and PROJ 6 versions, this is neither tested nor supported.

Two features are available:

proj = { version = "0.19.0", features = ["pkg_config"] }
proj = = { version = "0.19.0", features = ["bundled_proj"] }

The pkg_config feature enables the use of pkg-config when linking against libproj – note that pkg-config must be available on your system.

The bundled_proj feature allows you to use a statically-linked libproj included with (and built from source by) the proj-sys crate. Note that this feature requires Sqlite3 and libtiff to be present on your system.

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_approx_eq!(result.x() as f64, 1450880.2910605003);
assert_approx_eq!(result.y() as f64, 1141263.0111604529);

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
", false).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() and Proj::project_array()methods are available for bulk conversions. Both accept mutable slices (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.

Dependencies

~9–15MB
~218K SLoC