4

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.

AndreJ
  • 76,698
  • 5
  • 86
  • 162
Ryan
  • 43
  • 1
  • 1
  • 3
  • 1
    Please 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? – underdark Dec 14 '13 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. – Ryan Dec 14 '13 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. – AndreJ Dec 15 '13 at 08: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_radicals Feb 18 '15 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 Stimson Sep 30 '15 at 23:01

1 Answers1

7

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?

AndreJ
  • 76,698
  • 5
  • 86
  • 162
  • 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?
    – Ryan Dec 14 '13 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. – Ryan Dec 14 '13 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. – AndreJ Dec 15 '13 at 08:08