3

Is there anyway to clip/extract raster from a loaded XYZ Tiles basemap?

I am trying to use Google Satellite imagery, but every time I use the Clip Raster by Extent GDAL tool, I get an error. I am trying to input this in my Graphical Modeler for automation purposes. My current method is to right-click Google Satellite imagery --> export --> select Save As GeoTiff, but this procedure is very time-consuming.

4

You could use GDAL (i.e. gdal_translate) to crop your WMS/XYZ/WMTS rasters.

As an example load the OpenStreetMap TMS Example into QGIS (drag & drop XML file into map canvas).

Use gdal_translate to clip the datasource into a virtual raster (VRT):

gdal_translate -of VRT -projwin 1774709 6166823 1868433 6112638 "<GDAL_WMS><Service name='TMS'><ServerUrl>https://tile.openstreetmap.org/${z}/${x}/${y}.png</ServerUrl></Service><DataWindow><UpperLeftX>-20037508.34</UpperLeftX><UpperLeftY>20037508.34</UpperLeftY><LowerRightX>20037508.34</LowerRightX><LowerRightY>-20037508.34</LowerRightY><TileLevel>18</TileLevel><TileCountX>1</TileCountX><TileCountY>1</TileCountY><YOrigin>top</YOrigin></DataWindow><Projection>EPSG:3857</Projection><BlockSizeX>256</BlockSizeX><BlockSizeY>256</BlockSizeY><BandsCount>3</BandsCount><UserAgent>QGIS</UserAgent><Cache /></GDAL_WMS>" vienna.vrt

Then replace the datasource of the OSM layer with the content of the VRT using the QGIS changeDataSource plugin. The big advantage of this method is that you can share the project with others without copying the raster. enter image description here

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.