Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

MapProxy config

The test MapProxy instance is configured via D:\mapproxytest\mapproxy.yaml and available in a local browser on the server via http://localhost:84/ and http://localhost:81/iShareGISTEST.WebLocal/mapproxy/ (via a Rewrite rule). The test instance has the MapProxy demo available at http://localhost:84/demo/.

Review WMTS capabilities

The first thing to do is to open the WMTS in QGIS the available Layers and TileMatrixSets that the WMTS is capable of providing.

Once you have tested the layers in QGIS and decided which are of interestopen the capabilities XML document in a browser to view the details of the WMTS that will be required to configure MapProxy.

Of particular interest:

The URL that GetTile requests must be sent:

The Layers (one in this instance). We’re interested in the ows:Identifier (layer name), Formats and the names of the TileMatrixSets (tile grids). Here I’ve highlighted the layer name 2021_UK_100mm and the OsEPSG27700Scales TileMatrixSet which we will use.

I’ve selected the OsEPSG27700Scales TileMatrixSet as it uses numeric Identifiers for each TileMatrix which is currently the only format supported by MapProxy. I have a branch which contains support for non-numeric TileMatrix Identifiers which might make it into MapProxy in future.

The OsEPSG27700Scales TileMatrixSet looks like this:

Creating a grid

In the MapProxy config (D:\mapproxytest\mapproxy.yaml) we first define a grid, then a source which uses that grid, followed by a cache which uses the grid and source and finally a layer which uses the cache (smile). The grid is configured according to these instructions: [MapProxy] seed a WMTS service and create a WMS service.

The final grid looks like this:

grids:
    getmapping__os_gb__grid:
      origin: nw
      bbox: [0, 0, 700000, 1344000]
      bbox_srs: 'EPSG:27700'
      srs: 'EPSG:27700'
      tile_size: [250, 250]
      res: [
        #  res            level     scale @90.7 DPI
        896.0000000000, #  0     3200000.00000000
        448.0000000000, #  1     1600000.00000000
        224.0000000000, #  2      800000.00000000
        112.0000000000, #  3      400000.00000000
         56.0000000000, #  4      200000.00000000
         28.0000000000, #  5      100000.00000000
         14.0000000000, #  6       50000.00000000
          7.0000000000, #  7       25000.00000000
          3.5000000000, #  8       12500.00000000
          1.7500000000, #  9        6250.00000000
          0.8750000000, # 10        3125.00000000
          0.4375000000, # 11        1562.50000000
          0.2187500000, # 12         781.25000000
          0.1093750000, # 13         390.62500000
      ]

The name of the grid which will be used elsewhere in mapproxy.yaml is getmapping__os_gb__grid

The origin is generally nw for an WMTS compatible grid.

The SRS values are taken from the ows:BoundingBox and ows:SupportedCRS elements

The bbox is derived from ows:BoundingBox.

Tile size from TileWidth and TileHeight (not sure why they don’t just use the default of 256 or 512).

The resolutions are derived from each of the ScaleDenominator values via the scales command of the mapproxy-util command-line tool as follows in cmd.exe:

cd /d d:\MapProxyTest\
venv\Scripts\activate
mapproxy-util scales --as-res-conf 3200000 1600000 800000 400000 200000 100000 50000 25000 12500 6250 3125 1562.5 781.25 390.625

The above, changes to the MapProxy install directory and activates the Python virtual environment (which provides access to the mapproxy-util script) before calling mapproxy-util scales with the list of scales to convert to resolutions. The output from the command is then copied to the grid in mapproxy.yaml.

Creating source

A source will requests tiles from the Get Mapping WMTS in order for them to be cached. The final source looks like this:

sources:
  getmapping__2021_UK_100mm__os_gb__wmts:
    type: tile
    grid: getmapping__os_gb__grid
    url: https://www.getmapping.com/GmWMTS/NNNNNNNN-NNNN-NNNN-NNNN-NNNNNNNNNNNN/ORG.wmtsx?Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%%2Fpng&layer=2021_UK_100mm&style=Default&tilematrixset=OsEPSG27700Scales&TileMatrix=%(z)s&TileCol=%(x)s&TileRow=%(y)s
    transparent: true

The name of the source is getmapping__2021_UK_100mm__os_gb__wmts.

It’s a tile source which uses the getmapping__os_gb__grid grid we have just defined.

We’ve set transparent: true in this instance so we can combine data from this source another later on.

The url is a template which MapProxy will update with appropriate values in order to fetch a given tile. We’re specifying the layer (2021_UK_100mm), the tilematrixset (OsEPSG27700Scales) and format (image/png) and using placeholders for TileMatrix (zoom level), TileCol and TileRow.

Creating a cache

A cache uses the source and grid we have just defined, there are a few options for where cache data is stored, we’re using the default file cache.

caches:
  getmapping__2021_UK_100mm__os_gb__cache:
    grids: [getmapping__os_gb__grid]
    sources: [getmapping__2021_UK_100mm__os_gb__wmts]

The tiles can be found in D:\mapproxytest\cache_data.

Creating a layer

A layer defines a WMS or WMTS layer that MapProxy will make available to clients.

layers:
  - name: getmapping__2021_UK_100mm__os_gb
    title: '2021 10cm Digital Aerial Photography (Get Mapping OS grid)'
    sources: [getmapping__2021_UK_100mm__os_gb__cache]

The name is the used in WMS GetMap and WMTS GetTile requests.

The title is the friendly name commonly displayed in desktop clients such as QGIS.

The sources property is a list of either direct un-cached sources or caches from which to request data. I this instance we’re using the cache we’ve just defined (getmapping__2021_UK_100mm__os_gb__cache).

Testing and debugging

You can test the MapProxy config via the demo service: http://localhost:84/demo/ and via QGIS by adding a WMS or WMTS source:

  • No labels