I have been able to download tiles from a WMTS request in .tif format using owslib in standalone python:
from owslib.wmts import WebMapTileService wmts = WebMapTileService('wmts_url') img = wmts.gettile(layer='v0Lw1953KMdH', tilematrixset='WGS84', tilematrix='16', row='20480', column='32001', format='image/tif') out = open('C:\\out\\test_out.tif', 'wb') bytes_written = out.write(img.read()) out.close()
This .tif file is not spatially referenced. The WMTS Layer has the tag:
<ows:WGS84BoundingBox crs="urn:ogc:def:crs:OGC:2:84"> <ows:LowerCorner>-7.793077 49.852539</ows:LowerCorner> <ows:UpperCorner>1.790425 60.894042</ows:UpperCorner> </ows:WGS84BoundingBox>
and the WMTS TileMatrixSet has the tag:
<ows:Title>WGS84</ows:Title> <ows:Abstract>WGS84 EPSG:4326</ows:Abstract> <ows:Identifier>WGS84</ows:Identifier> <ows:SupportedCRS>urn:ogc:def:crs:EPSG::4326</ows:SupportedCRS>
which to someone of my limited knoweledge indicates that there could be a way to obtain a spatially referenced .tif from these tiles. However, I haven't been able to obtain a spatially referenced .tif, despite trying to include the crs in
gettile(). Where am I going wrong?
Failing this, are there any other methods that I could use to obtain spatially referenced tiles?