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
, accessed by the proj-sys
crate: if PROJ v7.1.x is present on your system and can be located by the build script, it will be used. As a fallback, libproj
will be built from source. While this crate may be backwards-compatible with older PROJ 7 and PROJ 6 versions, this is neither tested nor supported.
Feature Flags
pkg_config
: enables the use ofpkg-config
when linking againstlibproj
— note thatpkg-config
must be available on your system. This feature andbundled_proj
are mutually exclusive.bundled_proj
: buildslibproj
from source bundled in theproj-sys
crate. Note that this feature requires Sqlite3 andlibtiff
to be present on your system. This feature andbundled_proj
are mutually exclusive.network
: exposes APIs which, when enabled, can fetch grid data from the internet to improve projection accuracy. Seeenable_network
for details.
Examples
Convert from NAD 83 US Survey Feet to NAD 83 Meters Using EPSG Codes
use Proj;
extern crate geo_types;
use Point;
let from = "EPSG:2230";
let to = "EPSG:26946";
let ft_to_m = new_known_crs.unwrap;
let result = ft_to_m
.convert
.unwrap;
assert_approx_eq!;
assert_approx_eq!;
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 aninv
erse 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;
extern crate geo_types;
use Point;
let ft_to_m = new.unwrap;
// The Presidio, approximately
let result = ft_to_m.convert.unwrap;
assert_eq!;
assert_eq!;
Inverse Projection from Stereo70 to Geodetic
use Proj;
extern crate geo_types;
use Point;
// Carry out an inverse projection from Pulkovo 1942(58) / Stereo70 (EPSG 3844)
// into geodetic lon and lat coordinates (in radians)
let stereo70 = new.unwrap;
let rp = stereo70.project.unwrap;
assert_eq!;
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
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.