2 releases
0.1.1 | Aug 29, 2023 |
---|---|
0.1.0 | Aug 29, 2023 |
#222 in Geospatial
10KB
117 lines
geo-quadkey-rs
geo-quadkey-rs
is a Rust library for encoding and decoding geographical coordinates to and from QuadKeys, a tiling approach used by Microsoft's Bing Maps Tile System for interactive mapping solutions.
*Source: Microsoft Bing Maps Tile System
I referenced this repository made in Ruby was very helpful in creating this library: deg84/quadkey
Usage
Include geo-quadkey-rs
in your Cargo.toml
:
[dependencies]
geo-quadkey-rs = "0.1.0"
Then include it in your code:
extern crate geo_quadkey_rs;
use geo_quadkey_rs::Quadkey;
// Encode coordinates to a quadkey
let quadkey = Quadkey::encode(47.60357, -122.32945, 23);
// Decode a quadkey to coordinates
let (latitude, longitude, precision) = Quadkey::decode("12022001101101100101102");
// Find neighbors of a quadkey
let neighbors = Quadkey::neighbors("12022001101101100101102");
Functions
The Quadkey
struct provides the following methods:
encode(latitude: f64, longitude: f64, precision: usize) -> String
decode(quadkey: &str) -> (f64, f64, usize)
neighbors(quadkey: &str) -> Vec<String>
clip(n: f64, min_value: f64, max_value: f64) -> f64
map_size(precision: usize) -> f64
ground_resolution(latitude: f64, precision: usize) -> f64
coordinates_to_pixel(latitude: f64, longitude: f64, precision: usize) -> (i32, i32)
pixel_to_coordinates(pixel_x: i32, pixel_y: i32, precision: usize) -> (f64, f64)
pixel_to_tile(pixel_x: i32, pixel_y: i32) -> (i32, i32)
tile_to_pixel(tile_x: i32, tile_y: i32) -> (i32, i32)
tile_to_quadkey(tile_x: i32, tile_y: i32, precision: usize) -> String
quadkey_to_tile(quadkey: &str) -> (i32, i32, usize)
License
This project is licensed under the MIT License - see the LICENSE file for details.