When I try (in QGIS 3.8 "Zanzibar") to clip a "web layer", i.e. a raster layer provided from the web (e.g. an OSM map loaded via the QuickMapServices plugin) by the usual method
Raster > Extraction > Clip Raster by mask layer
or by extent
,
the gdalwarp command as generated by QGIS first reports:
Execution completed in x.yz seconds
Results:
{'OUTPUT': 'C:/Users/nn/Desktop/ClippedLayer.png'}
but in fact fails.
The Log output contains:
INFO GDAL execution console output
FAILURE: No target filename specified. [even though it *has* been]
Usage: gdalwarp [--help-general] [--formats]
[...]
'url' is not recognized as an internal or external command, operable program or batch file.
'zmax' is not recognized as an internal or external command, operable program or batch file.
'zmin' is not recognized as an internal or external command, operable program or batch file.
I suspect that the problem is with the URL-type string coming from the "web layer" URL: If the layer to clip exists as a real file, the gdalwarp parameters are e.g.
...
-cutline C:/Users/nn/Documents/QGIS/TEST/areaFinal_UTM.shp
-crop_to_cutline C:/OSGeo4W64/nn/TEST/terrain_UTM.tif
...
and all works well.
For a "web layer" it looks like
...
-cutline C:/Users/nn/Documents/QGIS/TEST/areaFinal_UTM.shp
-crop_to_cutline type=xyz&url=hxxp://tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png&zmax=19&zmin=0 ["hxxp" substituted for "http"]
...
which (unsurprisingly) fails.
The only way I found to "pseudo-clip" such a "web layer" was through generating an image from it via Project > Import/Export > Export Map To Image, where the extent can then come from another layer (e.g. a mask defining the extent).
However, this export dialog requires input of size and/or resolution, which in turn depend on the scale at which the map is currently viewed in QGIS, so it is not really a good general solution.
Hence the questions:
- How can a "web-supplied" raster layer be properly clipped to a limited extent in QGIS?
- How would the name of such a "web layer" be properly passed to the crop_to_cutline argument? (This would require running directly from a console, as QGIS 3.8 does not allow editing of its generated GDAL commands any more, alas.)