Crate mercantile

source ·
Expand description

§Mercantile

This module provides utility functions for working with geographical coordinates and tiles. It includes functions for converting between latitude/longitude (LngLat) coordinates and web mercator projected coordinates (XY), as well as functions for working with map tiles and their bounding boxes.

§Examples

use mercantile::*;

// Create a new tile object
let tile = Tile::new(486, 332, 10);

// Calculate the upper-left geographical coordinates of the tile
let ul_coordinates = ul(tile);
println!("Upper-left coordinates: {:?}", ul_coordinates);

// Calculate the bounding box of the tile in geographical coordinates
let bbox = bounds(tile);
println!("Bounding box: {:?}", bbox);

// Calculate the bounding box of the tile in web mercator coordinates
let xy_bbox = xy_bounds(tile);
println!("XY Bounding box: {:?}", xy_bbox);

// Convert LngLat coordinates to XY coordinates
let lng_lat = LngLat { lng: -9.140625, lat: 53.33087298301705 };
let xy_coordinates = convert_xy(lng_lat);
println!("XY coordinates: {:?}", xy_coordinates);

// Convert XY coordinates back to LngLat coordinates
let xy_coordinates = XY { x: -1017529.7205322663, y: 7044436.526761846 };
let lng_lat = convert_lng_lat(xy_coordinates);
println!("LngLat coordinates: {:?}", lng_lat);

Structs§

  • Represents a bounding box in web mercator projected coordinates
  • Represents a geographical coordinate in longitude and latitude
  • Represents a bounding box in geographical coordinates
  • Represents a tile on a map
  • Represents a point in web mercator projected coordinates

Functions§

  • Calculates the bounding box of a given tile in geographical coordinates
  • Converts web mercator projected coordinates (XY) to geographical coordinates (LngLat)
  • Converts geographical coordinates (LngLat) to web mercator projected coordinates (XY)
  • Calculates the upper-left geographical coordinates of a given tile
  • Calculates the bounding box of a given tile in web mercator projected coordinates