[GIS] Mapproxy as transparent OpenStreetMap cache

mapproxyopenstreetmaptiles

I followed the guide from https://wiki.openstreetmap.org/wiki/MapProxy to create a locale tile proxy for OpenStreetMap, because I need to access the same tiles over and over again. However, there seem to be some problems with the grid definitions.

As a example if I try to access http://localhost:8080/tms/1.0.0/osm/EPSG900913/6/12/11.png the URL is translated to http://c.tile.openstreetmap.org/7/12/116.png

What has to be changed in the config that mapproxy acts as a purely transparent proxy?

Best Answer

There a lot of things that can go wrong, especially srs / grid / bbox, as I've found out trying to work this out... So here is full working example for transparent OSM cache, to help next poor soul finding this:

services:
  #sets up how to make the source data available
  demo:
  tms:
    use_grid_names: true
    # origin for /tiles service
    origin: 'nw'
  wms:
    #srs sets the coordinate reference systems as which you want to make your data available. MapProxy reprojects the source data very well to these projections.
    srs: ['EPSG:3857']
    image_formats: ['image/png']
    md:
      # metadata used in capabilities documents
      title: Mapproxy OSM cache
      abstract: This is the MapProxy
      fees: 'None'


layers:
  #sets up which layers you want to make available using the services above. You can add many, but let's stick to osm data here.
  - name: osm_demo      # access in JOSM as TMS: http://localhost:8080/tiles/1.0.0/osm_demo/webmercator/{zoom}/{x}/{y}.png
    title: Open Streetmap Tiles (test)
    sources: [osm_cache]

caches:
  #setup the cache for the open streetmap tiles. This cache is used by the layer above.
  osm_cache:
    sources: [osm_tiles]
    format: image/png
    grids: [webmercator]

sources:
  osm_tiles:
    #the osm_tiles source refers to the openstreetmap.org tiles. These will be downloaded upon request (if not already cached) and served by MapProxy
    type: tile
    url: http://c.tile.openstreetmap.org/%(tms_path)s.%(format)s
    grid: webmercator

grids:
  webmercator:
    base: GLOBAL_WEBMERCATOR

globals:
  #next are some global configuration options for MapProxy. They mostly explain themselves, or can be looked-up in the MapProxy docs.
  cache:
    # where to store the cached images
    base_dir: './cache_data'
    # where to store lockfiles
    lock_dir: './cache_data/locks'

P.S. note that you need to access it as http://localhost:8080/tiles/1.0.0/osm_demo/webmercator/{zoom}/{x}/{y}.png not as default http://localhost:8080/tms/1.0.0/osm_demo/webmercator/{zoom}/{x}/{y}.png shown as setup page, as that will give you dreaded "empty blue" tiles...

Related Question