Skip to main content

TileMatrixSet

Struct TileMatrixSet 

Source
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: i32

Spatial reference system of the extent, and of the pyramid.

§min_x: f64

Minimum x (west edge).

§min_y: f64

Minimum y (south edge).

§max_x: f64

Maximum x (east edge).

§max_y: f64

Maximum y (north edge).

Implementations§

Source§

impl TileMatrixSet

Source

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.

Source

pub fn width(&self) -> f64

Returns the width of the extent in ground units.

Source

pub fn height(&self) -> f64

Returns the height of the extent in ground units.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn web_mercator_quad() -> Self

Returns the extent of the standard web mercator quad (EPSG:3857), the tiling scheme every XYZ basemap uses.

Source

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.

Source

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.

Source

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.

Source

pub fn tile_to_xyz( &self, matrix: &TileMatrix, coord: TileCoord, ) -> Result<(i64, i64, i64), TileError>

Returns the XYZ z/x/y address of one of this pyramid’s tiles.

§Errors

As Self::xyz_to_tile.

Trait Implementations§

Source§

impl Clone for TileMatrixSet

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TileMatrixSet

Source§

impl Debug for TileMatrixSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TileMatrixSet

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TileMatrixSet

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.