Using Map Tile Servers in QGIS 2.4

As I explained in a comment on my previous article, the otherwise fantastic OpenLayers plugin is currently not compatible with the freshly released QGIS 2.4 unfortunately. This means two things:

  1. You can’t open any QGS project files that contain a reference to such an OpenLayers base map.
  2. You can’t use it to insert OpenLayers base maps (e.g. OSM, Google, Bing, Stamen, Yahoo, …) into your new map projects anymore.

In my comment yesterday I already provided a small hack on how to solve problem number one, but let me repeat it here in a cleaner and easier to find environment:

You could either load the project in question on another machine in an older QGIS version, or manually edit the QPS project file to remove the layer. Just make sure you don’t forget a single reference! In my case I had not only to remove the corresponding <legendlayer> block in the <legend> block, but also the corresponding <maplayer> block in the <projectlayers> block, and also the layercount attribute in said <projectlayers> block.

So now at least you can open and work with your old project files, but I’m sure just like me you still want to be able to use these base maps in your projects. So here’s a quick and dirty solution to the second problem:

Following the hints and information I found here, here, and especially here, I created an XML file that allows me to load the tiles from the Stamen Toner map tile server as a raster layer in QGIS. The file looks like this:

<GDAL_WMS>
    <Service name="TMS">
        <ServerUrl>http://b.tile.stamen.com/toner/${z}/${x}/${y}.png</ServerUrl>
    </Service>
    <DataWindow>
        <UpperLeftX>-20037508.34</UpperLeftX>
        <UpperLeftY>20037508.34</UpperLeftY>
        <LowerRightX>20037508.34</LowerRightX>
        <LowerRightY>-20037508.34</LowerRightY>
        <TileLevel>18</TileLevel>
        <TileCountX>1</TileCountX>
        <TileCountY>1</TileCountY>
        <YOrigin>top</YOrigin>
    </DataWindow>
    <Projection>EPSG:3857</Projection>
    <BlockSizeX>256</BlockSizeX>
    <BlockSizeY>256</BlockSizeY>
    <BandsCount>3</BandsCount>
    <Cache />
</GDAL_WMS>

Of course the most interesting lines are the ones highlighted above:
Line 3 sets the URL for where the map tiles can be found. As you can see, here I referenced the Stamen Toner map, but you can easily replace the URL with the TMS server you’re interested in. You can find the necessary information on most map tile provider’s websites.
Line 15 sets the projection for the map tiles. In most cases this should be either EPSG 3857 or 900913, which is an unofficial alias for 3857 (spelling GOOGLE in quasi-leetspeak).

And there you go: Stamen Toner map tiles in QGIS 2.4! Obviously I will update this article once the great OpenLayers plugin becomes compatible with QGIS 2.4. There seems to be an update already looming in the GitHub repo… UPDATE: As of today (July 8th, 2014) the OpenLayers plugin has been updated to work in QGIS 2.4! Big thanks have to go out to Pirmin Kalberer, the plugin author, and all supporters. Only one little caveat: Whereas in the past the OpenLayers plugin’s menu resided in the Plugins menu, it now has a new home in the Web menu.

Stamen Toner map tiles in QGIS 2.4

Stamen Toner map tiles in QGIS 2.4

6 Comments

    1. Hi Anne

      I have had the same [problem, but just worked through -- I reinstalled the open layers plugin under the plugin menu and then it appeared in the dropbox under the web menu as it’s new location -- openstreetmap is there.
      Good luck -- this one was a real pain so I’m glad it’s sorted :C)
      Margs

      Reply

  1. Hi,

    Thank you! I couldn’t find where the new plugin was located. However, once I found it. I am still getting an error. I get an error with any of the OpenLayer styles. I am wondering if you happen to know what is going on. I am bookmarking this site. You explained and lot and I just found the site tonight.

    Thank you!
    Ashley

    An error has occured while executing Python code:

    Traceback (most recent call last):
    File “/Users/ashleyhaynes/.qgis2/python/plugins/openlayers_plugin/weblayers/weblayer.py”, line 97, in addLayer
    self._addLayerCallback(self)
    File “/Users/ashleyhaynes/.qgis2/python/plugins/openlayers_plugin/openlayers_plugin.py”, line 135, in addLayer
    self.setMapCrs(coordRefSys)
    File “/Users/ashleyhaynes/.qgis2/python/plugins/openlayers_plugin/openlayers_plugin.py”, line 176, in setMapCrs
    extMap = coodTrans.transform(extMap, QgsCoordinateTransform.ForwardTransform)
    QgsCsException: forward transform of
    (-146617.433350, 84491.070530)
    PROJ.4: +proj=longlat +datum=WGS84 +no_defs +to +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs
    Error: latitude or longitude exceeded limits

    Python version:
    2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
    [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]

    QGIS version:
    2.4.0-Chugiak Chugiak,

    Reply

    1. I’m glad I could help. Does your problem still exist? Have you tried turning it off and on again…? (Sorry, uncalled-for IT Crowd reference.) In all seriousness, some people report that uninstalling and reinstalling plugins solves many Python-related issues. Let us know how it went!

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*