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 13 Next »

iShare v6 and later uses MapProxy to create and display cached map data, for example aerial or historic maps. MapProxy may also be useful in other circumstances, for example:

  1. You may have to provide a customer API Key in the URL for each request, as in the case with the OS Maps API. If this were to be used directly in iShare, the key would have to be transferred to the client which could expose it to misuse.

  2. Proxying the basemap through MapProxy allows us to also query it directly with WMS which then means that it should work seamlessly with printing.

Create a cached WMS for Aerial Photography

When you have Aerial Photography (or historic mapping etc.) available as raster images (GeoTIFF or similar) it’s common to configure a MapServer mapfile to read the source data and provide access via WMS; this allows the data to be displayed in iShare Maps/GIS and also desktop clients such as QGIS or MapInfo as a base map.

It’s often desirable to improve performance and reduce server load by caching base map tiles. In the past TileCache has been used to produce a tile cache, MapProxy is now preferred over TileCache as it provides a WMS service compatible with desktop clients, support for other services such as WMTS and support for other tile sources.

Below we will take demonstrate configuring MapProxy to cache aerial photography served via MapServer as a WMS.

Configuration Overview

MapProxy uses a YAML configuration file to define the service - this file will normally be stored with the MapProxy application, for example at D:\mapproxy\mapproxy.yaml. Full documentation on configuring the YAML file are at: https://mapproxy.org/docs/latest/configuration.html, and a sample YAML file is attached to this page.

Adding a WMS or WMTS base map in Studio is covered in this section: BaseMaps Details .

The YAML file can be edited in a text editor such as Notepad++. The following are the main sections of the YAML file which need to be configured for each layer:

  • Layers: the layers that are available in the service

  • Caches: where the cache is stored

  • Sources: the source of the data to be cached

  • Grid: the Coordinate Reference System used in the layer, and the scales/resolutions available.

Troubleshooting configuration

Bear in mind the following when setting up a MapProxy installation:

  • the syntax and indentation shown in the example file and in the MapProxy documentation should be followed exactly in order to avoid errors

  • any errors will be recorded in the mapproxy.log file, which is normally in the same folder as the mapproxy.yaml file

  • you will need to make sure that any referenced folders are accessible by the MapProxy IIS application pool, and that the MapServer application pool has access to the source data and images

The MapProxy demo application is useful for testing MapProxy layers. The live MapProxy demo is accessible via http://localhost:83/demo; the test MapProxy demo is at http://localhost:84/demo.

Detailed Configuration

Layers

This section defines one or more layers to be served by MapProxy. Each layer should have:

  • name: used as a reference by Studio in the Details dialog

  • title: descriptive name for display purposes

  • sources: a reference to one or more sources defined elsewhere in the YAML file, defining the data to be displayed

See the example below.

layers:
  - name: aerial2013
    title: Aerial 2013
    sources: [aerial2013_cache]
  - name: aerial2018
    title: Aerial 2018
    sources: [aerial2018_cache]

Caches

This section defines the location of the cached data. The cache reference in the first line is referenced by the layers section, and the cache also identifies the source of the data.

Each cache will have:

  • grid: a reference to a grid definition elsewhere in the YAML file

  • sources: a reference to one or more source sections - if this is a MapServer WMS, the source includes both the reference to the source name in the YAML file (e.g. aerial_wms_2013) and the name of the layer or group in the map file (e.g. aerial2013)

caches:
  aerial2013_cache:
    grids: [grid_gb]
    sources: ['aerial_wms_2013:aerial2013']
  aerial2018_cache:
    grids: [grid_gb]
    sources: ['aerial_wms_2018:aerial2018']

As we have not specified a cache type or location the default file cache will be used. The location of the tiles is found at the bottom of mapproxy.yaml and should look something like this:

globals:
    cache:
        base_dir: E:\Tiles\Live

Sources

This section defines the source of the data to be displayed and cached. It will contain one or more sources, of which a single layer can reference one or more. The first line of the source will be used in the sources section of the layer as a reference. Each source will also have:

  • type: the type of source being referenced

    • wms: for example a MapServer layer configured in Studio, or an external WMS

    • tile: for example an existing tilecache or WMTS server

  • grid: a reference to a grid definition elsewhere in the YAML file

  • url: the location for the tilecache or WMS

 sources:
  aerial_wms_2013:
    type: wms
    req:
      url: http://127.0.0.1/Mapserver/ms761?map=E:/iShareData/LIVE/_MapServerConfig/base_raster_aerial_2013.map
    http:
      ssl_no_cert_checks: true
  aerial_wms_2018:
    type: wms
    req:
      url: http://127.0.0.1/Mapserver/ms761?map=E:/iShareData/LIVE/_MapServerConfig/base_raster_aerial_2018.map
    http:
      ssl_no_cert_checks: true

Grids

This section contains details of the coordinate reference system used by the cache. The first line contains the referenced used by the caches section. Each grid contains:

  • origin: the origin point of the grid in relation to the grid area - the default is sw

  • srs: the coordinate reference system/spatial reference system being used by the data, using the EPSG code

  • bbox: the bounding box of the grid, i.e. the extent of the data, using the units specified in bbox_srs

  • bbox_srs: the SRS of the units specified in bbox

  • res: the resolutions that MapProxy will cache

grids:
    grid_gb:
        srs: 'EPSG:27700'
        bbox: [0,0,700000,1300000]
        bbox_srs: 'EPSG:27700'
        res: [72,37.99999999999999,25,16.666607646976313,8,5.291747064678806,3.528118349260536,2.116774531941753,1.0586554968815869,0.5,0.25,0.125]
        origin: sw

Scales and resolutions

iShare base maps are configured with a list of scales while MapProxy uses resolutions. MapProxy provides a mapproxy-util scales command that supports converting between scales and resolutions.

Convert resolutions to scales (for iShare):

mapproxy-util scales --res-to-scale 25600 19200 12800 9600 6400 4800 3200 2400 1600 1200 800 600 400 300 200 150 100 75 50 37.5 25 18.75 10 7.5 5 3.75 2.5 1.875 1 0.75 0.5 0.25 0.125 0.0625

Convert scales to resolutions (for MapProxy grid configuration):

mapproxy-util scales --as-res-conf 91428571.4285714328 68571428.5714285821 45714285.7142857164 34285714.2857142910 22857142.8571428582 17142857.1428571455 11428571.4285714291 8571428.5714285728 5714285.7142857146 4285714.2857142864 2857142.8571428573 2142857.1428571432 1428571.4285714286 1071428.5714285716 714285.7142857143 535714.2857142858 357142.8571428572 267857.1428571429 178571.4285714286 133928.5714285714 89285.7142857143 66964.2857142857 35714.2857142857 26785.7142857143 17857.1428571429 13392.8571428571 8928.5714285714 6696.4285714286 3571.4285714286 2678.5714285714 1785.7142857143 892.8571428571 446.4285714286 223.2142857143

Adding additional scales to a base map

The default scales may not cover the range of scales you wish to provide for your base map, and MapProxy can help with this. The cache upscale_tiles as described in the cache documentation can scale tiles up depending on your requirements.

chc_my_basemap:
  grids: [ "grd_my_basemap" ]
  sources: [ "src_my_basemap"]
  meta_buffer: 0
  minimize_meta_requests: true
  upscale_tiles: 1
  cache_rescaled_tiles: true

This lets MapProxy know that any tiles that cannot be retrieved from the source should be rescaled from the next level up. Please note that this will not happen if there is an error returned from the source, just if the source is limited on what resolutions it can return. Again, please read the documentation for more information.

sources:
  src_my_basemap:
    type: tile
    grid: grd_my_basemap
    url: https://mymaps.com/maps/raster/v1/wmts?height=256&width=256&style=default&layer=My_Basemap&version=1.0.0&service=WMTS&Request=GetTile&format=image/png&TileMatrixSet=EPSG:27700&TileMatrix=EPSG:27700:%(z)s&TileRow=%(y)s&TileCol=%(x)s
    max_res: 0.109375
    min_res: 896.0

We need to set a max_res and min_res in the source to specify what resolutions the source supports returning.

grd_my_basemap:
  origin: nw
  srs: 'EPSG:27700'
  bbox: [-238375.0,0.0,900000.0,1376256.0]
  bbox_srs: 'EPSG:27700'
  res: [896.0, 448.0, 224.0, 112.0, 56.0, 28.0, 14.0, 7.0, 3.5, 1.75, 0.875, 0.4375, 0.21875, 0.109375, 0.0546875, 0.02734375, 0.013671875, 0.0068359375]

The final step is to increase the number of resolutions that are available for the basemap so that the client will pick them up, just remember that any specific WMTS scale is the previous scale divided by two. In the example above, the following resolutions will be scaled as they are outside the source max/min res limits.

0.0546875, 0.02734375, 0.013671875, 0.0068359375

  • No labels