RSGISLib Tile Cache Tools
Convert Indexing
- rsgislib.tools.tilecacheutils.convert_between_tms_xyz(tiles_dir)
A function which converts between TMS and XYZ tile indexing. The conversion is performed in-situ with the files simply renamed. If a tile cache is in TMS format then this function will convert it to XYZ, while if it is in XYZ format then it will convert it to TMS (they are easily interchangeable)
The TMS format uses a grid with the origin at the bottom-left. While the XYZ format is uses a grid with the origin in the top-left.
XYZ grids can be loads into QGIS and other GIS systems as layers. TMS grids are outputted by gdal2tiles.py.
- Parameters:
tiles_dir – The input directory for the tile cache.
- rsgislib.tools.tilecacheutils.flip_xyz_tms_tiles(tile_x, tile_y, zoom)
If you put in a XYZ tile index you will have returned an TMS index. If you put in a TMS index you will have returned XYZ.
- Parameters:
tile_x – The x index for the tile.
tile_y – The y index for the tile (will change if TMS or XYZ indexing).
zoom – the zoom level for the tile.
- Returns:
(tile_x, tile_y, zoom)
Find Path/Tile
- rsgislib.tools.tilecacheutils.get_quadkey_for_tile_path(tile_x, tile_y, zoom, tms=True)
Get the quadkey of the tile
- Parameters:
tile_x – The x index for the tile.
tile_y – The y index for the tile (will change if TMS or XYZ indexing).
zoom – the zoom level for the tile.
tms – if TMS is True then a tile grid in TMS format is returned with the grid origin at the bottom-left. If False then an XYZ tile grid format is used with the origin in the top-left.
- Returns:
a quadkey for the tile.
- rsgislib.tools.tilecacheutils.get_tile_path_from_quadkey(quadkey, tms=True)
Return the tile path for an inputted quadkey.
- Parameters:
quadkey – the inputted quadkey for the tile.
tms – if TMS is True then a tile grid in TMS format is returned with the grid origin at the bottom-left. If False then an XYZ tile grid format is used with the origin in the top-left.
- Returns:
(tile_x, tile_y, zoom)
- rsgislib.tools.tilecacheutils.get_tiles(bbox, zooms, tms=True, truncate=False)
Gets a list of tile indexes for all the zoom levels specified. The tile indexes are returned as a dict with the zoom as the key which references a list of tiles.
- Parameters:
bbox – A bounding box in WGS84 longitude/latitude values (MinX, MaxX, MinY, MaxY).
zooms – list of zoom levels
tms – if TMS is True then a tile grid in TMS format is returned with the grid origin at the bottom-left. If False then an XYZ tile grid format is used with the origin in the top-left.
truncate – Whether to truncate or clip inputs to web mercator limits.
- Returns:
dict[zoom] = [(tile_x, tile_y, zoom), (tile_x, tile_y, zoom) … (tile_x, tile_y, zoom)]
- rsgislib.tools.tilecacheutils.get_web_mercator_xy(lon_deg, lat_deg, truncate=False)
Convert a WGS84 longitude, latitude coordinate to a web mercator coordinate (meters).
- Parameters:
lon_deg – float with longitude value.
lat_deg – float with latitude value.
truncate – Whether to truncate or clip inputs to web mercator limits.
- Returns:
(meter_x, meter_y)
- rsgislib.tools.tilecacheutils.get_xy_mercator_lonlat(meter_x, meter_y, truncate=False)
Convert a web mercator coordinate (meters) to a WGS84 longitude, latitude coordinate.
- Parameters:
meter_x – x coordinate in the web mercator coordinate system
meter_y – y coordinate in the web mercator coordinate system
truncate – Whether to truncate or clip inputs to web mercator limits.
- Returns:
(longitude, latitude)
- rsgislib.tools.tilecacheutils.xy_mercator_bounds(tile_x, tile_y, zoom, tms=True)
Returns the bounding box of a tile in the web mercator coordinate system (meters).
- Parameters:
tile_x – The x index for the tile.
tile_y – The y index for the tile (will change if TMS or XYZ indexing).
zoom – the zoom level for the tile.
tms – if TMS is True then a tile grid in TMS format is returned with the grid origin at the bottom-left. If False then an XYZ tile grid format is used with the origin in the top-left.
- Returns:
(MinX, MaxX, MinY, MaxY)
Tile Info
- rsgislib.tools.tilecacheutils.get_tile_for_point(lon_deg, lat_deg, zoom, tms=True, tile_size=256)
- Parameters:
lon_deg – float with longitude value.
lat_deg – float with latitude value.
zoom – the zoom level for the tile.
tms – if TMS is True then a tile grid in TMS format is returned with the grid origin at the bottom-left. If False then an XYZ tile grid format is used with the origin in the top-left.
tile_size – is the size, in pixels, of the tiles (default 256).
- Returns:
(tile_x, tile_y, zoom)
- rsgislib.tools.tilecacheutils.get_tile_tl_lonlat(tile_x, tile_y, zoom, tms=True)
Returns the Top-Left coordinate for the tile.
- Parameters:
tile_x – The x index for the tile.
tile_y – The y index for the tile (will change if TMS or XYZ indexing).
zoom – the zoom level for the tile.
tms – if TMS is True then a tile grid in TMS format is returned with the grid origin at the bottom-left. If False then an XYZ tile grid format is used with the origin in the top-left.
- Returns:
(longitude, latitude)
- rsgislib.tools.tilecacheutils.get_tile_bbox(tile_x, tile_y, zoom, tms=True)
Returns the bounding box (BBOX) of a tile
- Parameters:
tile_x – The x index for the tile.
tile_y – The y index for the tile (will change if TMS or XYZ indexing).
zoom – the zoom level for the tile.
tms – if TMS is True then a tile grid in TMS format is returned with the grid origin at the bottom-left. If False then an XYZ tile grid format is used with the origin in the top-left.
- Returns:
(MinLon, MaxLon, MinLat, MaxLat)
Internal Functions
- rsgislib.tools.tilecacheutils.resolution(zoom)
Calculate the image resolution for a zoom level.
- Returns:
float image pixel resolution
- rsgislib.tools.tilecacheutils.truncate_lng_lat(lon_deg, lat_deg)
A function which truncates latitude and londitude values to be better -180 to 180 and -90 to 90.
- Parameters:
lon_deg – float with longitude value.
lat_deg – float with latitude value.
- Returns:
(lon_deg, lat_deg)