morecantile.models
morecantile.models ¶
Pydantic modules for OGC TileMatrixSets (www.ogc.org/standards/tms)
CRS ¶
Bases: RootModel[Union[str, Union[CRSUri, CRSWKT, CRSRef]]]
CRS model.
Ref: github.com/opengeospatial/ogcapi-tiles/blob/master/openapi/schemas/common-geodata/crs.yaml
Code generated using koxudaxi/datamodel-code-generator
TMSBoundingBox ¶
TileMatrix ¶
Bases: BaseModel
Tile Matrix Definition
A tile matrix, usually corresponding to a particular zoom level of a TileMatrixSet.
ref: github.com/opengeospatial/2D-Tile-Matrix-Set/blob/master/schemas/tms/2.0/json/tileMatrix.json
TileMatrixSet ¶
Bases: BaseModel
Tile Matrix Set Definition
A definition of a tile matrix set following the Tile Matrix Set standard.
For tileset metadata, such a description (in tileMatrixSet
property) is only required for offline use,
as an alternative to a link with a http://www.opengis.net/def/rel/ogc/1.0/tiling-scheme
relation type.
ref: github.com/opengeospatial/2D-Tile-Matrix-Set/blob/master/schemas/tms/2.0/json/tileMatrixSet.json
_invert_axis
cached
property
¶
_invert_axis: bool
Check if CRS has inverted AXIS (lat,lon) instead of (lon,lat).
rasterio_geographic_crs
cached
property
¶
rasterio_geographic_crs
Return the geographic CRS as a rasterio CRS.
_lr ¶
_matrix_origin ¶
_matrix_origin(matrix: TileMatrix) -> Coords
Return the Origin coordinates of the matrix.
_tile ¶
_ul ¶
bounds ¶
bounds(*tile: Tile) -> BoundingBox
children ¶
Get the children of a tile
The children are ordered: top-left, top-right, bottom-right, bottom-left.
Parameters¶
tile : Tile or sequence of int May be be either an instance of Tile or 3 ints, X, Y, Z. zoom : int, optional Determines the zoom level of the returned child tiles. This defaults to one higher than the tile (the immediate children).
Returns¶
list: list of Tile
custom
classmethod
¶
custom(extent: List[float], crs: CRS, tile_width: int = 256, tile_height: int = 256, matrix_scale: Optional[List] = None, extent_crs: Optional[CRS] = None, minzoom: int = 0, maxzoom: int = 24, title: Optional[str] = None, id: Optional[str] = None, ordered_axes: Optional[List[str]] = None, screen_pixel_size: float = 0.00028, decimation_base: int = 2, **kwargs: Any)
Construct a custom TileMatrixSet.
Attributes¶
crs: pyproj.CRS
Tile Matrix Set coordinate reference system
extent: list
Bounding box of the Tile Matrix Set, (left, bottom, right, top).
tile_width: int
Width of each tile of this tile matrix in pixels (default is 256).
tile_height: int
Height of each tile of this tile matrix in pixels (default is 256).
matrix_scale: list
Tiling schema coalescence coefficient (default: [1, 1] for EPSG:3857).
Should be set to [2, 1] for EPSG:4326.
see: docs.opengeospatial.org/is/17-083r2/17-083r2.html#14
extent_crs: pyproj.CRS
Extent's coordinate reference system, as a pyproj CRS object.
(default: same as input crs)
minzoom: int
Tile Matrix Set minimum zoom level (default is 0).
maxzoom: int
Tile Matrix Set maximum zoom level (default is 24).
title: str, optional
Tile Matrix Set title
id: str, optional
Tile Matrix Set identifier
ordered_axes: list of str, optional
Override Axis order (e.g ["N", "S"]
) else default to CRS's metadata
screen_pixel_size: float, optional
Rendering pixel size. 0.28 mm was the actual pixel size of a common display from 2005 and considered as standard by OGC.
decimation_base: int, optional
How tiles are divided at each zoom level (default is 2). Must be greater than 1.
kwargs: Any
Attributes to forward to the TileMatrixSet
Returns:¶
TileMatrixSet
feature ¶
feature(tile: Tile, fid: Optional[str] = None, props: Optional[Dict] = None, buffer: Optional[NumType] = None, precision: Optional[int] = None, projected: bool = False) -> Dict
Get the GeoJSON feature corresponding to a tile.
Originally from github.com/mapbox/mercantile/blob/master/mercantile/__init__.py
Parameters¶
tile : Tile or sequence of int May be be either an instance of Tile or 3 ints, X, Y, Z. fid : str, optional A feature id. props : dict, optional Optional extra feature properties. buffer : float, optional Optional buffer distance for the GeoJSON polygon. precision: float If >= 0, geometry coordinates will be rounded to this number of decimal, otherwise original coordinate values will be preserved (default). projected : bool, optional Return coordinates in TMS projection. Default is false.
Returns¶
dict
from_v1
classmethod
¶
from_v1(tms: Dict) -> TileMatrixSet
Makes a TMS from a v1 TMS definition
Attributes
supportedCRS: CRS Tile Matrix Set coordinate reference system title: str Title of TMS abstract: str (optional) Abstract of CRS keywords: str (optional) Keywords identifier: str TMS Identifier wellKnownScaleSet: AnyHttpUrl (optional) WKSS URL boundingBox: TMSBoundingBox (optional) Bounding box of TMS tileMatrix: List[TileMatrix] List of Tile Matrices
Returns:¶
TileMatrixSet
intersect_tms ¶
intersect_tms(bbox: BoundingBox) -> bool
Check if a bounds intersects with the TMS bounds.
lnglat ¶
Transform point(x,y) to geographic longitude and latitude.
lr ¶
minmax ¶
neighbors ¶
The neighbors of a tile
The neighbors function makes no guarantees regarding neighbor tile ordering.
The neighbors function returns up to eight neighboring tiles, where tiles will be omitted when they are not valid.
Parameters¶
tile : Tile or sequence of int May be be either an instance of Tile or 3 ints, X, Y, Z.
Returns¶
list
parent ¶
Get the parent of a tile
The parent is the tile of one zoom level lower that contains the given "child" tile.
Parameters¶
tile : Tile or sequence of int May be be either an instance of Tile or 3 ints, X, Y, Z. zoom : int, optional Determines the zoom level of the returned parent tile. This defaults to one lower than the tile (the immediate parent).
Returns¶
list: list of Tile
quadkey ¶
quadkey_to_tile ¶
tile ¶
tiles ¶
tiles(west: float, south: float, east: float, north: float, zooms: Sequence[int], truncate: bool = False) -> Iterator[Tile]
Get the tiles overlapped by a geographic bounding box
Original code from github.com/mapbox/mercantile/blob/master/mercantile/__init__.py#L424
Parameters¶
west, south, east, north : sequence of float Bounding values in decimal degrees (geographic CRS). zooms : int or sequence of int One or more zoom levels. truncate : bool, optional Whether or not to truncate inputs to TMS limits.
Yields¶
Tile
Notes¶
A small epsilon is used on the south and east parameters so that this function yields exactly one tile when given the bounds of that same tile.
truncate_lnglat ¶
Truncate geographic coordinates to TMS geographic bbox.
Adapted from github.com/mapbox/mercantile/blob/master/mercantile/__init__.py
ul ¶
xy ¶
Transform geographic longitude and latitude coordinates to TMS CRS.
xy_bounds ¶
xy_bounds(*tile: Tile) -> BoundingBox
zoom_for_res ¶
zoom_for_res(res: float, max_z: Optional[int] = None, zoom_level_strategy: str = 'auto', min_z: Optional[int] = None) -> int
Get TMS zoom level corresponding to a specific resolution.
Parameters:
-
res
(float
) –Resolution in TMS unit.
-
max_z
(int
, default:None
) –Maximum zoom level (default is tms maxzoom).
-
zoom_level_strategy
(str
, default:'auto'
) –Strategy to determine zoom level (same as in GDAL 3.2). LOWER will select the zoom level immediately below the theoretical computed non-integral zoom level. On the contrary, UPPER will select the immediately above zoom level. Defaults to AUTO which selects the closest zoom level. ref: gdal.org/drivers/raster/cog.html#raster-cog
-
min_z
(int
, default:None
) –Minimum zoom level (default is tms minzoom).
Returns:
-
int
(int
) –TMS zoom for a given resolution.
Examples:
>>> zoom_for_res(430.021)