OpenLayers – How to Clip an OpenLayers OSM Background to a Vector Boundary

clipopenstreetmapqgisraster

I'm new to QGIS. In my project i have two layers: one is my vector (city boundaries) and the other is the OSM (obtained with the plugin). How can I cut the OSM along the edges of the vector? I want to obtain only a region of the map, to save it as an image.

Best Answer

This way it works:

  1. unselect your vector data, to show only the Openstreetmap background

  2. File -> Save as Image

  3. Load the image as raster, set EPSG:3857 as CRS

  4. Delete the Openstreetmap background layer

  5. Raster -> Projection -> Reproject, choosing EPSG:3857 as source CRS and the CRS of the vector data as target CRS, saving as Geotiff under a different name, adding that to the canvas

  6. Remove the image loaded in step 3

  7. Raster -> Extraction -> Clipper check Mask layer with the vector data, and add the result to the canvas

  8. Remove the unclipped raster layer from step 5


EDIT

If you want the clipping for all zoom levels, see my answer here:

How do I clip OSM basemap with a polygon?

Related Question