[−][src]Struct proj::Proj
A PROJ
instance
Methods
impl Proj
[src]
pub fn new(definition: &str) -> Option<Proj>
[src]
Try to instantiate a new PROJ
instance
Note: for projection operations, definition
specifies
the output projection; input coordinates
are assumed to be geodetic in radians, unless an inverse projection is intended.
For conversion operations, definition
defines input, output, and
any intermediate steps that are required. See the convert
example for more details.
Safety
This method contains unsafe code.
pub fn new_known_crs(from: &str, to: &str, area: Option<Area>) -> Option<Proj>
[src]
Create a transformation object that is a pipeline between two known coordinate reference systems.
from
and to
can be:
- an
"AUTHORITY:CODE"
, like"EPSG:25832"
. When using that syntax for a source CRS, the created pipeline will expect that the values passed toproject()
orconvert()
respect the axis order and axis unit of the official definition ( so for example, for EPSG:4326, with latitude first and longitude next, in degrees). Similarly, when using that syntax for a target CRS, output values will be emitted according to the official definition of this CRS. - a PROJ string, like
"+proj=longlat +datum=WGS84"
. When using that syntax, the axis order and unit for geographic CRS will be longitude, latitude, and the unit degrees. - the name of a CRS as found in the PROJ database, e.g
"WGS84"
,"NAD27"
, etc. - more generally, any string accepted by
new()
If you wish to alter the particular area of use, you may do so using area_set_bbox()
extern crate proj; use proj::Proj; extern crate geo_types; use geo_types::Point; let from = "EPSG:2230"; let to = "EPSG:26946"; let nad_ft_to_m = Proj::new_known_crs(&from, &to, None).unwrap(); let result = nad_ft_to_m .convert(Point::new(4760096.421921f64, 3744293.729449f64)) .unwrap(); assert_approx_eq!(result.x(), 1450880.29f64, 1.0e-2); assert_approx_eq!(result.y(), 1141263.01f64, 1.0e-2);
Safety
This method contains unsafe code.
pub fn area_set_bbox(&mut self, new_area: Option<Area>)
[src]
Set the bounding box of the area of use
This bounding box will be used to specify the area of use
for the choice of relevant coordinate operations.
In the case of an area of use crossing the antimeridian (longitude +/- 180 degrees),
west
must be greater than east
.
Safety
This method contains unsafe code.
pub fn def(&self) -> String
[src]
pub fn project<T>(
&self,
point: Point<T>,
inverse: bool
) -> Result<Point<T>, Error> where
T: Float,
[src]
&self,
point: Point<T>,
inverse: bool
) -> Result<Point<T>, Error> where
T: Float,
Project geodetic Point
coordinates (in radians) into the projection specified by definition
Note: specifying inverse
as true
carries out an inverse projection to geodetic coordinates
(in radians) from the projection specified by definition
.
Safety
This method contains unsafe code.
pub fn convert<T>(&self, point: Point<T>) -> Result<Point<T>, Error> where
T: Float,
[src]
T: Float,
Convert Point
coordinates using the PROJ pipeline
operator
This method makes use of the pipeline
functionality available since v5.0.0, which differs significantly from the v4.x series
It has the advantage of being able to chain an arbitrary combination of projection, conversion, and transformation steps, allowing for extremely complex operations.
The following example converts from NAD83 US Survey Feet (EPSG 2230) to NAD83 Metres (EPSG 26946) Note the steps:
- 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.
extern crate proj; use proj::Proj; extern crate geo_types; use geo_types::Point; let nad_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(); let result = nad_ft_to_m.convert(Point::new(4760096.421921f64, 3744293.729449f64)).unwrap(); assert_approx_eq!(result.x(), 1450880.29f64, 1.0e-2); assert_approx_eq!(result.y(), 1141263.01f64, 1.0e-2);
Safety
This method contains unsafe code.
pub fn convert_array<'a, T>(
&self,
points: &'a mut [Point<T>]
) -> Result<&'a mut [Point<T>], Error> where
T: Float,
[src]
&self,
points: &'a mut [Point<T>]
) -> Result<&'a mut [Point<T>], Error> where
T: Float,
Convert a mutable slice (or anything that can deref into a mutable slice) of Point
coordinates
The following example converts from NAD83 US Survey Feet (EPSG 2230) to NAD83 Metres (EPSG 26946)
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 mut v = vec![Point::new(4760096.421921, 3744293.729449), Point::new(4760197.421921, 3744394.729449)]; ft_to_m.convert_array(&mut v); assert_approx_eq!(v[0].x(), 1450880.2910605003f64); assert_approx_eq!(v[1].y(), 1141293.7960220212f64);
Safety
This method contains unsafe code.
Trait Implementations
Auto Trait Implementations
impl Unpin for Proj
impl !Sync for Proj
impl !Send for Proj
impl UnwindSafe for Proj
impl RefUnwindSafe for Proj
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,