1

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.)
1

What I did when I needed to sample the spectral profile of a web map layer was to right click the layer, export the Raw Data to GeoTiff, choose an appropriate extent, and set an appropriate resolution for the layer (it likely will not set a value other than 0, which will yield a failed export).

Then, you do you work off this rendered image. Not ideal, but has worked in a pinch for me when I've needed to sample/work with a raster tile layer directly.

enter image description here

  • 1
    Thanks! I thought I had tried this already without success, but now tried again, and it worked. But what is the unit for "Resolution" in this dialog? Meter per pixel? (I checked the latest QGIS-testing-UserGuide (released yesterday), and the parameter is mentioned on page 141 (of 607), but it is not explained, and no unit is given. – clüles Jul 30 at 12:10
  • The unit per pixel should be tied to the CRS of the project, I believe, which should do on the fly CRS transformation of the web layer (which will normally be EPSG:3857 (degrees) ). For me, I was working in a local state plane CRS, so my unit was feet per pixel. – Saijin_Naib Jul 30 at 13:12
  • 1
    Yes, that makes sense. So "resolution" means in any case "geographical real world length unit per map pixel" (where GRWLU can be meter, feet, degree, etc.), and not image resolution in "dots per inch" or "pixel per inch" . Thanks for the help. – clüles Jul 30 at 15:32
  • Yeah, I would think of it more as Ground Sample Distance than what we normally think of as resolution when thinking of images/imagery in daily life. – Saijin_Naib Jul 30 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.