TmsWms2Geotiff¶
Downloads the map tiles of an online service over a region and joins them into a single GeoTIFF image, in Web Mercator. It brings a background map, as an orthophoto or a topographic map, into the analyses that need a raster, or offline. The service can be a tile service, with the tile indexes in its url, as most of the web maps, or a WMS.
The size of the image grows fast with the zoom level: each level halves the size of the cells and quadruples the tiles. The terms of use of most of the services limit the bulk downloads of tiles, so the module is meant for small regions.
Details¶
The service is a tile service (TMS, XYZ or WMTS with the indexes in the url) or a WMS. The url of a tile service has the placeholders ZZZ, XXX and YYY, replaced by the zoom level and the column and row of each tile, as https://tile.example.org/ZZZ/XXX/YYY.png. The rows are numbered from the north, as in most of the web maps (the Google schema, also called XYZ), or from the south (the OGC TMS schema). The url of a WMS has the placeholders WWW, SSS, EEE and NNN, replaced by the bounds of each tile in longitude and latitude: it has to ask for images of 256x256 pixels in EPSG:4326.
The tiles of the zoom level that cover the bounds of the region of interest are joined in an RGB image in Web Mercator (EPSG:3857) with the extent of the whole tiles, so a bit larger than the region. Each zoom level halves the size of the cells: at zoom 18 they are about 0.6 m at the equator, and the tiles of a large region quickly become millions, too many for a single image. A tile that can’t be downloaded stays black, with an error message. The terms of use of the services usually limit the bulk downloads of tiles.
Parameters¶
Downloads the map tiles of an online service over a region and joins them into a GeoTIFF image.
Toolbox folder: Raster Processing
Status: Certified
Keywords: Raster, Vector, TMS, WMS, Tiles, Download
Authors: Andrea Antonello
Class: org.hortonmachine.gears.modules.r.tmsgenerator.TmsWms2Geotiff
Inputs
Parameter |
Type |
Unit |
Default |
Description |
|---|---|---|---|---|
|
String |
The url of the service, with ZZZ, XXX and YYY in place of the tile indexes, or WWW, SSS, EEE, NNN in place of the bounds of a WMS. |
||
|
vector file |
The vector whose bounds are the region to download. |
||
|
String |
|
The numbering of the tile rows: from the north (Google, XYZ) or from the south (OGC TMS). Allowed values: |
|
|
String |
|
The type of service: tiles or WMS. Allowed values: |
|
|
Integer |
|
The zoom level of the tiles. |
Outputs
Parameter |
Type |
Unit |
Description |
|---|---|---|---|
|
output file |
The output GeoTIFF path. |
Example¶
The example downloads the tiles over the basin of ExtractBasin; the url is a placeholder for the one of the service to use:
import org.hortonmachine.gears.modules.r.tmsgenerator.TmsWms2Geotiff
// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"
// the tiles of a web map over the basin of ExtractBasin, at zoom level 15 (cells of about 3 m)
var tms = new TmsWms2Geotiff()
// change it to the url of the service to use, with the placeholders of the tile indexes
tms.inServiceUrl = "https://tiles.example.org/ZZZ/XXX/YYY.png"
// the rows numbered from the north, as in most of the web maps
tms.pSchemaType = "Google"
tms.pSourceType = "TMS"
tms.pZoomlevel = 15
tms.inRoiPath = folder + "basin.shp"
tms.outRaster = folder + "basin_tiles.tif"
tms.process()