Skip to main content

WebMercator

Struct WebMercator 

Source
pub struct WebMercator;
Expand description

Web Mercator projection utilities.

project/unproject are fast, allocation-free wrappers over the Projection trait implementation.

Implementations§

Source§

impl WebMercator

Source

pub fn project(geo: &GeoCoord) -> WorldCoord

Project a geographic coordinate to Web Mercator world coordinates (meters).

Input is assumed to already be in valid Web Mercator range.

Source

pub fn project_checked(geo: &GeoCoord) -> Option<WorldCoord>

Checked variant of project.

Returns None when geo is outside Web Mercator valid range.

Source

pub fn project_clamped(geo: &GeoCoord) -> WorldCoord

Project with automatic Mercator clamping/wrapping.

Latitude is clamped to +/-85.051129 and longitude wrapped to [-180, 180] before projection.

Source

pub fn unproject(world: &WorldCoord) -> GeoCoord

Inverse-project Web Mercator coordinates back to geographic coordinates.

Source

pub fn max_extent() -> f64

The maximum extent of Web Mercator along one axis, in meters.

Equals R * PI where R is the projection sphere radius.

Source

pub fn world_size() -> f64

Full width/height of the Web Mercator world square, in meters.

Trait Implementations§

Source§

impl Projection for WebMercator

Source§

fn scale_factor(&self, geo: &GeoCoord) -> f64

Scale factor for Web Mercator: sec(lat) = 1 / cos(lat).

Approaches infinity near the poles, which is why the projection is limited to approximately 85.06 degrees latitude.

Source§

fn projection_bounds(&self) -> GeoBounds

Web Mercator is valid within approximately 85.06 degrees latitude and 180 degrees longitude.

Source§

fn project(&self, geo: &GeoCoord) -> WorldCoord

Project a geographic coordinate to world space (meters).
Source§

fn unproject(&self, world: &WorldCoord) -> GeoCoord

Inverse-project world coordinates back to geographic.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.