10

I've created a map in qgis 2.0. The map uses the OpenLayers plug-in to add the OSM layer as a basemap. I would like to restrict the basemap to be visible only inside a given polygon defined in a shapefile layer. How do I achieve this?

  • 1
    You would have to have to use the WMS osm layer (converted to a local geo-raster layer) then you can use Raster>Extraction>Clipper and use the Mask option with your polygon. see docs.qgis.org/2.0/html/en/docs/user_manual/plugins/… – Mapperz Oct 1 '13 at 16:43
  • I thought I'd try your method, but can't make it work. I create a new project, with default CRS EPSG:4326. I add my polygon shapefile boundary (washington, DC), which is in State-Plane, but I have enabled reproject on-the-fly. I then search for the OSM WMS server and select the one labled OSM with description WMS. I connect, select layer 7 (highways), and click "Add". The layer name appears in the layers pane, but nothing appears on the map. If I zoom to layer extent, I'm way off in nowhere land (longitude -121°, DC is around -77, which is where my polygon is), but do see roads. – Llaves Oct 2 '13 at 0:14
9

This way it works for me:

  1. Create a worldwide polygon shapefile stretching from +180°E to -179,99°E and from +85.5°N to -85.5°N with a text file containing

    Nr;WKT

    1;POLYGON ((180 85.5, -179.9 85.5, -179.99 -85.5, 180 -85.5, 180 85.5))

  2. Add that file as Text delimited layer, using semicolon as separator and WGS84 as CRS.

  3. Save the layer as shapefile in the CRS of your polygon, add that to the canvas and delete the text file layer.

  4. Subtract your polygon shapefile from that, and set the fill of the remaining polygon to 100% white.

  5. Put it on top the Openlayers layer, and only the wanted area will be visible for all zoom levels:

enter image description here

  • 1
    I considered this, but was wondering if there was a more "elegant" solution such as Mapperz gives above. But this does work, and unlike Mapperz solution, it remains connected to the layer, so detail scales dynamically as you zoon. – Llaves Oct 1 '13 at 17:21

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.