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.
-
1Please be more specific: Did you use the OSM plugin to download OSM vector data or did you use the Openlayers plugin to download rendered OSM tiles?– underdarkCommented Dec 14, 2013 at 11:06
-
I downloaded a shapefile with vector layers from a government site. Then I used the OSM plugin to insert a background map inside my vector. Is it possible? Because at the moment I have the vector and beside him all the map from OpenStreetMap, even if i want only an area. Sorry for my bad english and for my noobness.– RyanCommented Dec 14, 2013 at 11:18
-
From your other comment, I assume you used the Openlayers plugin. The Openstreetmap plugin loads OSM vector data, but needs a lot of handwork to get a good looking background map.– AndreJCommented Dec 15, 2013 at 8:13
-
I'm trying to do exactly what the OP asked, but going from AndreJ's answer, I get this error: ERROR 1: Attempt to create 0x0 dataset is illegal,sizes must be larger than zero. What does this mean and how can I get around this?– free_radicalsCommented Feb 18, 2015 at 21:28
-
Please don't ask a question in an answer, if you are having a similar problem then please ask a new question and reference this one. Thank you.– Michael StimsonCommented Sep 30, 2015 at 23:01
1 Answer
This way it works:
unselect your vector data, to show only the Openstreetmap background
File -> Save as Image
Load the image as raster, set EPSG:3857 as CRS
Delete the Openstreetmap background layer
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 canvasRemove the image loaded in step 3
Raster -> Extraction -> Clipper
checkMask layer
with the vector data, and add the result to the canvasRemove the unclipped raster layer from step 5
EDIT
If you want the clipping for all zoom levels, see my answer here:
-
It works, thanks! Two more questions: 1) there is a way to improve the image quality? If I zoom I can't read the name of the cities in the map 2) cutting along the boundaries is not perfect, it not match for some millimeters. Is a problem of CRS?– RyanCommented Dec 14, 2013 at 13:41
-
I solved the problem with the CRS, it was my fault when i select them during the reprojection. Still have the problem with the quality of the image.– RyanCommented Dec 14, 2013 at 13:56
-
You can zoom further in, and make several images in step 2. You have to build a virtual raster to get them all together before clipping. Or follow the link to an earlier question in my expanded answer.– AndreJCommented Dec 15, 2013 at 8:08