I'm working on using imagery from a web map tile service which I've cached locally as a gdal dataset. I have both 256x256 tiles and 512x512 tiles; the latter are the "retina" versions of the former; i.e. they cover the exact same area but at twice the resolution.
Here's the wmts.xml
file:
<?xml version="1.0"?>
<GDAL_WMTS>
<GetCapabilitiesUrl>/path/to/my_tile_service.xml</GetCapabilitiesUrl>
<Layer>all-activity</Layer>
<Style>activity</Style>
<TileMatrixSet>google3857</TileMatrixSet>
<DataWindow>
<UpperLeftX>-20037508.3428</UpperLeftX>
<UpperLeftY>20037508.3428</UpperLeftY>
<LowerRightX>20037508.34278254</LowerRightX>
<LowerRightY>-20037508.34278254</LowerRightY>
</DataWindow>
<BandsCount>4</BandsCount>
<Cache>
<Path>../cached_tiles</Path>
<Depth>2</Depth>
<Extension>.png</Extension>
</Cache>
<UnsafeSSL>true</UnsafeSSL>
<ZeroBlockHttpCodes>204,404</ZeroBlockHttpCodes>
<ZeroBlockOnServerException>false</ZeroBlockOnServerException>
</GDAL_WMTS>
and here's the referenced my_tile_service.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd"
version="1.0.0">
<ows:ServiceIdentification>
<ows:Title>My Tileset</ows:Title>
<ows:Abstract>
</ows:Abstract>
<ows:ServiceType>OGC WMTS</ows:ServiceType>
<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
<ows:Fees>none</ows:Fees>
<ows:AccessConstraints></ows:AccessConstraints>
</ows:ServiceIdentification>
<Contents>
<Layer>
<ows:Title>All Activity</ows:Title>
<ows:Abstract></ows:Abstract>
<ows:Identifier>all-activity</ows:Identifier>
<Style isDefault="true">
<ows:Identifier>activity</ows:Identifier>
</Style>
<Format>image/png</Format>
<TileMatrixSetLink>
<TileMatrixSet>google3857</TileMatrixSet>
</TileMatrixSetLink>
<ResourceURL format="image/png"
template="file:///path/to/my/tiles/{TileMatrix}/{TileCol}/{TileRow}.png"
resourceType="tile"/>
</Layer>
<TileMatrixSet>
<ows:Identifier>google3857</ows:Identifier>
<ows:BoundingBox crs="urn:ogc:def:crs:EPSG:6.18.3:4326">
<ows:LowerCorner>-180 -90</ows:LowerCorner>
<ows:UpperCorner>180 90</ows:UpperCorner>
</ows:BoundingBox>
<ows:SupportedCRS>urn:ogc:def:crs:EPSG:6.18.3:3857</ows:SupportedCRS>
<WellKnownScaleSet>urn:ogc:def:wkss:OGC:1.0:GoogleMapsCompatible</WellKnownScaleSet>
<TileMatrix>
<ows:Identifier>14</ows:Identifier>
<ScaleDenominator>34123.6733416</ScaleDenominator>
<TopLeftCorner>-20037508.3428 20037508.3428</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>16384</MatrixWidth>
<MatrixHeight>16384</MatrixHeight>
</TileMatrix>
</TileMatrixSet>
</Contents>
</Capabilities>
(this was adapted from a service description that had several zoom levels, I removed all but zoom level 14).
This works just fine as is, using my 256x256 tiles; e.g. the command:
gdalwarp -dstnodata 255 -co COMPRESS=DEFLATE -of GTiff -r lanczos -crop_to_cutline -cutline sample_area.json wmts.xml clipped_region.tif
outputs a GeoTIFF file containing the pixels from my map tiles bounded by the polygon specified (in GeoJSON) in sample_area.json
.
However, I can't seem to figure out how to make the same thing work with the 512x512 tiles. I've tried just changing the TileWidth
and TileHeight
values, but that appears to change the indexing, i.e. the same lat/lon is looking at different tile IDs.
What else do I need to change?