0

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?


EDIT

running the command

gdalinfo --debug on mapboxTMS.xml

returns the following output:

GDAL: Auto register C:\OSGEO4~1\bin\gdalplugins\gdal_ECW_JP2ECW.dll using GDALRegister_ECW_JP2ECW.
GDAL: GDALOpen(mapboxTMS.xml, this=0000000002BCEA30) succeeds as WMS.
Driver: WMS/OGC Web Map Service
Files: mapboxTMS.xml
Size is 67108864, 67108864
Coordinate System is:
PROJCS["WGS 84 / Pseudo-Mercator",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Mercator_1SP"],
    PARAMETER["central_meridian",0],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["X",EAST],
    AXIS["Y",NORTH],
    EXTENSION["PROJ4","+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"],
    AUTHORITY["EPSG","3857"]]
Origin = (-20037508.340000000000000,20037508.340000000000000)
Pixel Size = (0.597164283394814,-0.597164283394814)
Image Structure Metadata:
  INTERLEAVE=PIXEL
OGRCT: PROJ >= 4.8.0 features enabled
OGRCT: Using locale-safe proj version
OGRCT: Source: +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 +no_defs
OGRCT: Target: +proj=longlat +ellps=WGS84 +no_defs
Corner Coordinates:
Upper Left  (-20037508.340,20037508.340) (180d 0' 0.00"W, 85d 3' 4.06"N)
Lower Left  (-20037508.340,-20037508.340) (180d 0' 0.00"W, 85d 3' 4.06"S)
Upper Right (20037508.340,20037508.340) (180d 0' 0.00"E, 85d 3' 4.06"N)
Lower Right (20037508.340,-20037508.340) (180d 0' 0.00"E, 85d 3' 4.06"S)
Center      (   0.0000000,   0.0000000) (  0d 0' 0.01"E,  0d 0' 0.01"N)
Band 1 Block=256x256 Type=Byte, ColorInterp=Red
  Overviews: 33554432x33554432, 16777216x16777216, 8388608x8388608, 4194304x4194304, 2097152x2097152, 1048576x1048576, 524288x524288, 262144x262144, 131072x131072, 65536x65536, 32768x32768, 16384x16384, 8192x8192, 4096x4096, 2048x2048, 1024x1024, 512x512, 256x256
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
  Overviews: 33554432x33554432, 16777216x16777216, 8388608x8388608, 4194304x4194304, 2097152x2097152, 1048576x1048576, 524288x524288, 262144x262144, 131072x131072, 65536x65536, 32768x32768, 16384x16384, 8192x8192, 4096x4096, 2048x2048, 1024x1024, 512x512, 256x256
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
  Overviews: 33554432x33554432, 16777216x16777216, 8388608x8388608, 4194304x4194304, 2097152x2097152, 1048576x1048576, 524288x524288, 262144x262144, 131072x131072, 65536x65536, 32768x32768, 16384x16384, 8192x8192, 4096x4096, 2048x2048, 1024x1024, 512x512, 256x256
GDAL: GDALClose(mapboxTMS.xml, this=0000000002BCEA30)

It doesn't look like there's something wrong with it :/

7
  • 1
    that is because it isn't a raster, it is a picture of a map.
    – Ian Turton
    Commented Jun 6, 2018 at 12:11
  • 1
    Dear Etherlind, as Ian Turton already mentioned before the map that you want to visualize is not just a raster map. Because TMS layer is a set of tiles that obey own scheme and visualization rules. Therefore, you can "perform some raster operations" only on a single tile or with a loop through all tiles.
    – Taras
    Commented Jun 6, 2018 at 12:52
  • It should work through GDAL and XML file. What is the exact problem with it? Running gdalinfo with "--debug on" may give some information.
    – user30184
    Commented Jun 6, 2018 at 16:13
  • It did not work in gis.stackexchange.com/questions/222650/using-gdal-tms-in-qgis nor could I make the OSM example from gdal.org/frmt_wms.html to work with QGIS. I would try to use the XML file with gdal_translate.
    – user30184
    Commented Jun 6, 2018 at 17:08
  • Cross-posted as stackoverflow.com/questions/50716919/…
    – PolyGeo
    Commented Jun 6, 2018 at 22:57

1 Answer 1

0

"Add raster layer" in QGIS is using GDAL for reading raster data and all raster formats which are supported by GDAL should work with QGIS. However, in case of the GDAL WMS driver http://www.gdal.org/frmt_wms.html it seems that it does not work properly with QGIS. See question Using GDAL TMS in QGIS? that deals with the same issue. I guess that QGIS may not know how to access tiles from the correct zoom level. If it tries to read all the tiles from the whole world at zoom level 18 that would for sure make some trouble. Adding an optional <OverviewCount>into the XML file could perhaps help. However, I am only guessing and a mail to QGIS-developer mailing list should yield some correct information.

If QGIS cannot utilize the XML configuration file correctly you can always read it with gdal_translate. Usage example:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.