pub struct TileMatrixSet {
pub srs_id: i32,
pub min_x: f64,
pub min_y: f64,
pub max_x: f64,
pub max_y: f64,
}Expand description
A gpkg_tile_matrix_set row: the exact extent of a tile pyramid, and the
spatial reference system its coordinates are in.
The extent is exact rather than informative (Requirement 144). Every tile’s
own bounding box is calculated from it, and (min_x, max_y) is the
upper-left corner of tile (0, 0) at every zoom level. Tiles may be sparse
within the extent, so it may be larger than the tiles actually present.
Fields§
§srs_id: i32Spatial reference system of the extent, and of the pyramid.
min_x: f64Minimum x (west edge).
min_y: f64Minimum y (south edge).
max_x: f64Maximum x (east edge).
max_y: f64Maximum y (north edge).
Implementations§
Source§impl TileMatrixSet
impl TileMatrixSet
Sourcepub fn new(srs_id: i32, min_x: f64, min_y: f64, max_x: f64, max_y: f64) -> Self
pub fn new(srs_id: i32, min_x: f64, min_y: f64, max_x: f64, max_y: f64) -> Self
Creates a matrix set from its spatial reference system and its four edges.
Sourcepub fn validate(&self, matrices: &[TileMatrix]) -> Result<(), TileError>
pub fn validate(&self, matrices: &[TileMatrix]) -> Result<(), TileError>
Checks a whole pyramid: the extent against Requirement 144, then every tile matrix against Requirements 45 to 53, in ascending zoom order.
matrices may be in any order and may be empty. A pyramid with no zoom
levels declared breaks no rule, because the spec requires a
gpkg_tile_matrix row only for a level that contains tiles.
§Errors
Returns the first TileError the pyramid violates, checking the
lowest zoom level first.
Sourcepub fn tile_bounds(
&self,
matrix: &TileMatrix,
column: i64,
row: i64,
) -> TileBounds
pub fn tile_bounds( &self, matrix: &TileMatrix, column: i64, row: i64, ) -> TileBounds
Returns the ground extent of one tile.
Each edge is calculated once from its index, so two adjacent tiles share an edge exactly. The outer edges of the grid are the edges of the extent.
The column and row are not bounds-checked. A column or row outside the
grid still has a calculable box, and a caller walking outwards from a
tile may need it. Use TileMatrix::check_contains to check them.
Sourcepub fn tile_at(&self, matrix: &TileMatrix, x: f64, y: f64) -> Option<(i64, i64)>
pub fn tile_at(&self, matrix: &TileMatrix, x: f64, y: f64) -> Option<(i64, i64)>
Returns the tile containing a position, or None for a position
outside the extent or with a NaN coordinate.
Every edge is inclusive. A position on an edge that two tiles share
belongs to the tile east or south of it. A position on max_x belongs
to the last column rather than to one past it, and a position on min_y
belongs to the last row.
For a grid that spans the extent (Requirement 45), the bounds that
Self::tile_bounds returns for the tile contain the position.
Also returns None for a grid with no columns or no rows, which
contains no tile for any position. Requirements 47 and 48 do not permit
that grid, and TileMatrixSet::validate rejects it, but a
TileMatrix read from another writer’s file has not been through
either check.
Sourcepub fn tile_range(
&self,
matrix: &TileMatrix,
min_x: f64,
min_y: f64,
max_x: f64,
max_y: f64,
) -> Option<TileRange>
pub fn tile_range( &self, matrix: &TileMatrix, min_x: f64, min_y: f64, max_x: f64, max_y: f64, ) -> Option<TileRange>
Returns the tiles a bounding box touches at one zoom level, clamped to
the grid, or None when the box misses the extent entirely or contains
no point: a minimum above its maximum, or a NaN edge.
The range is every tile whose Self::tile_bounds share a point with
the box, edges included. A box whose edge lies on an edge that two
tiles share therefore selects the tile on each side of it.
Sourcepub fn ladder(&self, ladder: ZoomLadder) -> Result<Vec<TileMatrix>, TileError>
pub fn ladder(&self, ladder: ZoomLadder) -> Result<Vec<TileMatrix>, TileError>
Returns the tile matrices of a power-of-two ladder over this extent.
Pixel sizes are derived from the extent rather than supplied, so Requirement 45 holds by construction. Each level’s grid spans the matrix set exactly.
§Errors
TileError::InvalidExtent for an extent no tile can be measured
against, TileError::NonPositiveDimension for a non-positive base
grid or tile size, and TileError::InvalidZoomRange for a range that
is empty, negative, or wide enough to overflow the grid.
Sourcepub fn web_mercator_quad() -> Self
pub fn web_mercator_quad() -> Self
Returns the extent of the standard web mercator quad (EPSG:3857), the tiling scheme every XYZ basemap uses.
Sourcepub fn is_web_mercator_quad(&self) -> bool
pub fn is_web_mercator_quad(&self) -> bool
Returns true if this extent is the standard web mercator quad.
This compares srs_id against 3857 literally. A file that registers web
mercator under some other srs_id, which the format allows, returns
false. Recognising that file would mean resolving CRS definitions,
which this crate does not do.
Sourcepub fn matches_xyz_grid(&self, matrix: &TileMatrix) -> bool
pub fn matches_xyz_grid(&self, matrix: &TileMatrix) -> bool
Returns true if tiles at this zoom level have the same indices an
XYZ service would give them.
That requires the standard web mercator quad, tiled as a 2^zoom
square. Tile pixel dimensions play no part because they set resolution,
not addressing, so a 512-pixel quad grid is still XYZ-addressed.
Sourcepub fn xyz_to_tile(
&self,
matrix: &TileMatrix,
z: i64,
x: i64,
y: i64,
) -> Result<TileCoord, TileError>
pub fn xyz_to_tile( &self, matrix: &TileMatrix, z: i64, x: i64, y: i64, ) -> Result<TileCoord, TileError>
Reads an XYZ z/x/y address as a tile of this pyramid.
§Errors
TileError::NotAnXyzGrid when this pyramid does not address tiles the
way XYZ does, rather than returning indices that silently point
somewhere else, and TileError::CoordOutsideMatrix for an address
outside the grid.