tile_grid/
tile.rs

1use serde_json::json;
2
3/// A xmin,ymin,xmax,ymax coordinates tuple.
4#[derive(Debug, Clone, PartialEq)]
5pub struct BoundingBox {
6    /// min horizontal coordinate.
7    pub left: f64,
8    /// min vertical coordinate.
9    pub bottom: f64,
10    /// max horizontal coordinate.
11    pub right: f64,
12    /// max vertical coordinate.
13    pub top: f64,
14}
15
16impl BoundingBox {
17    /// Create a new BoundingBox.
18    pub fn new(left: f64, bottom: f64, right: f64, top: f64) -> Self {
19        Self {
20            left,
21            bottom,
22            right,
23            top,
24        }
25    }
26}
27
28/// A x,y Coordinates pair.
29#[derive(Debug, Clone, PartialEq)]
30pub struct Coords {
31    /// horizontal coordinate input projection unit.
32    pub x: f64,
33    /// vertical coordinate input projection unit.
34    pub y: f64,
35}
36
37impl Coords {
38    /// Create a new Coords.
39    pub fn new(x: f64, y: f64) -> Self {
40        Self { x, y }
41    }
42}
43
44/// TileMatrixSet X,Y,Z tile indices.
45#[derive(Debug, Clone, PartialEq)]
46pub struct Xyz {
47    /// horizontal index.
48    pub x: u64,
49    /// vertical index.
50    pub y: u64,
51    /// zoom level.
52    pub z: u8,
53}
54
55impl Xyz {
56    /// Create a new Tile.
57    pub fn new(x: u64, y: u64, z: u8) -> Self {
58        Self { x, y, z }
59    }
60}
61
62/// Create a GeoJSON feature from a bbox.
63pub fn bbox_to_feature(west: f64, south: f64, east: f64, north: f64) -> serde_json::Value {
64    json!({
65        "type": "Polygon",
66        "coordinates": [
67            [[west, south], [west, north], [east, north], [east, south], [west, south]]
68        ],
69    })
70}