3
votes

I'm looking for a way to display a Mapbox map in QGis in so it's recognized as a raster layer.

I've already tried this, and I succeeded adding the TMS layer via TileLayer Plugin, using my mapbox url like this: https://a.tiles.mapbox.com/styles/v1/[my_username]/[map_ID]/tiles/256/{z}/{x}/{y}?access_token=[my_access_token]

The problem is, adding a layer in this way is not recognized by QGIS as a raster layer, and I need to perform some raster operations on it.

On the other hand, I tried to create an XML file like this:

<GDAL_WMS>
    <Service name="TMS">
        <ServerUrl>https://a.tiles.mapbox.com/styles/v1/[my_username]/[map_ID]/tiles/256/${z}/${x}/${y}?access_token=[my_access_token]</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>

but it's not working.

Using the exact same XML with the Google TMS url http://mt.google.com/vt/lyrs=s&amp;x=${x}&amp;y=${y}&amp;z=${z} works ok.

Am I missing something here?

1

1 Answers

1
votes

So the XML file I was trying to import to QGIS was already correct. Using the GDAL command

gdalinfo --debug on mapboxTMS.xml

returned a coherent output.

Also, using the command gdal_translate resulted in a correct extraction of an area, which was exactly the raster operation I wanted to perform. In my case I used it like this:

gdal_translate -projwin 1499373.73124 3010255.99556 1499925.16592 3009716.74729 -of GTiff mapboxTMS.xml result.tif

So the problem actually seems to be on the QGIS side. According to this answer it is probably caused by the GDAL WMS driver not working properly with QGIS.