GlobalMercator

Struct GlobalMercator 

Source
pub struct GlobalMercator { /* private fields */ }

Implementations§

Source§

impl GlobalMercator

Source

pub fn new(tile_size: u64) -> Self

Create a new instance of the coordinate transformer

Example:

 let transformer = webmerc::GlobalMercator::new(256);
 assert_eq!(transformer.tile_size(), 256);
Source

pub fn tile_size(&self) -> u64

Get the tile_size used to instantiate the transformer

Example:

let transformer = webmerc::GlobalMercator::new(256);
assert_eq!(transformer.tile_size(), 256);
Source

pub fn lat_lon_to_meters(&self, lon: f64, lat: f64) -> (f64, f64)

Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:3857

Example:

let transformer = webmerc::GlobalMercator::new(256);
let (x, y) = transformer.lat_lon_to_meters(10.0, 10.0);
assert_relative_eq!(x, 1113194.91, epsilon = 1e-2);
assert_relative_eq!(y, 1118889.97, epsilon = 1e-2);
Source

pub fn meters_2_lat_lon(&self, mx: f64, my: f64) -> (f64, f64)

Converts XY point from Spherical Mercator EPSG:3857 to lat/lon in WGS84 Datum

let transformer = webmerc::GlobalMercator::new(256);
let (lon, lat) = transformer.meters_2_lat_lon(-20037508.0, -20037508.0);
assert_relative_eq!(lon, -179.999997, epsilon = 1e-6);
assert_relative_eq!(lat, -85.051129, epsilon = 1e-6);
Source

pub fn pixels_to_meters(&self, px: u64, py: u64, zoom: u64) -> (f64, f64)

Converts pixel coordinates in given Zoom level of pyramid to EPSG:3857

Source

pub fn meters_to_pixels(&self, mx: f64, my: f64, zoom: u64) -> (u64, u64)

Converts EPSG:3857 to pyramid pixel coordinates in given Zoom level

Source

pub fn pixels_to_tile(&self, px: u64, py: u64) -> (u64, u64)

Returns a Tile covering region in given pixel coordinates

Source

pub fn pixels_to_raster(&self, px: u64, py: u64, zoom: u64) -> (u64, u64)

Move the origin of pixel coordinates to top-left corner

Source

pub fn meters_to_tile(&self, mx: f64, my: f64, zoom: u64) -> (u64, u64)

Returns tile for given mercator coordinates

Source

pub fn tile_bounds(&self, tx: u64, ty: u64, zoom: u64) -> (f64, f64, f64, f64)

Returns bounds of the given tile in EPSG:3857 coordinates

Source

pub fn tile_lat_lon_bounds( &self, tx: u64, ty: u64, zoom: u64, ) -> (f64, f64, f64, f64)

Returns bounds of the given tile in latitude/longitude using WGS84 datum

Source

pub fn resolution(&self, zoom: u64) -> f64

Resolution (meters/pixel) for given zoom level (measured at Equator)

Source

pub fn zoom_for_pixel_size(&self, pixel_size: f64) -> u64

Maximal scaledown zoom of the pyramid closest to the pixelSize.

Source

pub fn google_tile(&self, tx: u64, ty: u64, zoom: u64) -> (u64, u64)

Converts TMS tile coordinates to Google Tile coordinates and vice versa

Source

pub fn quad_tree(&self, tx: u64, ty: u64, zoom: u64) -> String

Converts TMS tile coordinates to Microsoft quad_tree

Trait Implementations§

Source§

impl Debug for GlobalMercator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.