6 releases

0.3.0 Feb 19, 2021
0.2.2 Jan 30, 2021
0.2.1 Jul 29, 2019
0.1.1 Jul 27, 2019

#46 in Geospatial

Download history 44/week @ 2022-11-28 55/week @ 2022-12-05 123/week @ 2022-12-12 85/week @ 2022-12-19 20/week @ 2022-12-26 15/week @ 2023-01-02 147/week @ 2023-01-09 101/week @ 2023-01-16 133/week @ 2023-01-23 124/week @ 2023-01-30 70/week @ 2023-02-06 121/week @ 2023-02-13 107/week @ 2023-02-20 98/week @ 2023-02-27 63/week @ 2023-03-06 17/week @ 2023-03-13

305 downloads per month
Used in 3 crates (2 directly)

MIT license

31KB
752 lines

tile-grid

Crates.io Documentation

tile-grid is a library for map tile grid calculations.

Included standard grids are Web Mercator and WGS 84.

Usage

Predefined grids

use tile_grid::{Extent, Grid};

let grid = Grid::wgs84();
assert_eq!(
    grid.tile_extent(0, 0, 0),
    Extent {
        minx: -180.0,
        miny: -90.0,
        maxx: 0.0,
        maxy: 90.0,
    }
);

Grid iterators

use tile_grid::{Grid, GridIterator};

let grid = Grid::web_mercator();
let tile_limits = grid.tile_limits(grid.extent.clone(), 0);
let griditer = GridIterator::new(0, 2, tile_limits);
for (z, x, y) in griditer {
    println!("Tile {}/{}/{}", z, x, y);
}

Custom grids

use tile_grid::{Extent, Grid, Unit, Origin};

let grid = Grid::new(
    256,
    256,
    Extent {
        minx: 2420000.0,
        miny: 1030000.0,
        maxx: 2900000.0,
        maxy: 1350000.0,
    },
    2056,
    Unit::Meters,
    vec![
        4000.0, 3750.0, 3500.0, 3250.0, 3000.0, 2750.0, 2500.0, 2250.0, 2000.0, 1750.0, 1500.0,
        1250.0, 1000.0, 750.0, 650.0, 500.0, 250.0, 100.0, 50.0, 20.0, 10.0, 5.0, 2.5, 2.0,
        1.5, 1.0, 0.5,
    ],
    Origin::TopLeft,
);
assert_eq!(
    grid.tile_extent(0, 0, 15),
    Extent {
        minx: 2420000.0,
        miny: 1222000.0,
        maxx: 2548000.0,
        maxy: 1350000.0,
    }
);

Credits

License

tile-grid is released under the MIT License.

No runtime deps