4

Let's say I have a shapefile that contains multiple polygons and I open it on QGIS:

enter image description here

Let's also say that I activate the OpenStreetMap tiles layer under it:

enter image description here

I'd like to find a way to extract the tiles layer under the polygons as a raster layer. Is it possible to do something like this while controlling the level of zoom that I want (since on different levels of zoom I have different images) in QGIS?

1 Answer 1

7

You can export OSM XYT Tiles background map as raster file: right click on the OpenStreetMap layer and select Export / Save as... to save a copy of the background tiled map as raster file. Be sure to define the extent and resolution of the raster.

To get the extent of a layer, simply click Calculate from Layer... in the Extent section of the dialog window (see dialog window on the right in the screenshot, in dem middle). If you only want to keep those pixels that intersect the polygons, use Menu Processing / Toolbox / Clip raster by mask layer (see documentation).

However, you don't write why you need to do so, what you ultimately want to do with this raster. Maybe there are better ways to achieve that.

OSM XYZ Tiles map (brighter, in the background), and exported raster file (darker, in the middle): enter image description here

Note Tile Usage policies, for example OSM Carto servers run by OpenStreetMap Foundation ( see https://operations.osmfoundation.org/policies/tiles/ ) heavily discourage bulk tile downloading and

In particular, downloading an area of over 250 tiles at zoom level 13 or higher for offline or later usage is forbidden.

5
  • I'm not sure if I'm missing a step. But I'm getting the raster of the current visible screen. Should it work for getting the intersection of all the polygons from a layer with the tiles layer?
    – raylight
    Commented Nov 7, 2021 at 23:10
  • I didn't describe my ultimate goal because it'd be too broad, but it's getting the image from all parks that I have in a city in a raster. I've already extracted the shapefile from OSM. The next step will be to separate the small polygons that I have in it... But that I asked in this other question... I think your suggestion of solution in that question would work fine for that. :)
    – raylight
    Commented Nov 7, 2021 at 23:13
  • 1
    To get the extent of a layer, simply click Calculate from Layer... in the Extent section of the dialog window (see dialog window on the right in the screenshot, in dem middle).
    – Babel
    Commented Nov 7, 2021 at 23:15
  • I'm not sure what's happening wrong. But when I try the procedure from your answer I get exactly the same error from this other question... The solution there also seems to work for me though, probably it'll be better to open a new question because the problem that I'm having now is a different one...
    – raylight
    Commented Nov 8, 2021 at 3:53
  • 1
    I understood what was the problem with the procedure. Apparently, I can't use the functionality Clip raster by mask layer on a XYZ tiles map... I need first to get a raster layer from the tiles map and after that, I clip the raster with the polygons... Then it works fine!
    – raylight
    Commented Nov 8, 2021 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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