[GIS] MapProxy with WMTS source and reprojection

coordinate systemmapproxywmts

I am trying to consume Lantmateriet's WMTS source with EPSG:3006 and convert that to iOS TileOverlay compatible (GoogleMaps compatible) tile server. I cannot get it working. Can someone check this out and say what I am doing wrong.

mapproxy.yaml:

services:
  tms:
    use_grid_names: false
    origin: 'nw'
layers:
  - name: sweden
    title: sweden
    sources: [cache_sweden]
    tile_sources: [cache_sweden]

caches:
  cache_sweden:
    sources: [cache_sweden_original]
    grids: [GLOBAL_MERCATOR]
    meta_size: [4, 4]
    cache:
      type: mbtiles
  cache_sweden_original:
    sources: [source_sweden]
    grids: [grid_sweden]
    disable_storage: true
sources:
  source_sweden:
    type: tile
    grid: grid_sweden   
    url: 'https://api.lantmateriet.se/open/topowebb-ccby/v1/wmts/token/mytoken/?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=topowebb&STYLE=default&TILEMATRIXSET=3006&TILEMATRIX=%(z)s&TILEROW=%(y)s&TILECOL=%(x)s&FORMAT=image/png'
grids:
  grid_sweden:
    srs: 'EPSG:3006'
    bbox: [-1200000.000000, 4305696.000000, 2994304.000000, 8500000.000000]
    origin: nw

This is what it looks now:
This is what it looks now

Capabilities of the WMTS source I am trying to use can be seen:
GetCapabilities.xml

Best Answer

The problem was with the res-parameter. I had to calculate the scales based on the GetCapabilities. Here is a good guide how to do it properly https://lists.osgeo.org/pipermail/mapproxy/2013-August/001674.html

The final grid definition was

grid_sweden_3006:
   srs: 'EPSG:3006'
   bbox: [-1200000, 4305696, 2994304, 8500000]
   origin: nw
   res: [
     #  res            level     scale @90.7 DPI
     4096.0000000000, #  0    14628571.42857143
     2048.0000000000, #  1     7314285.71428571
     1024.0000000000, #  2     3657142.85714286
      512.0000000000, #  3     1828571.42857143
      256.0000000000, #  4      914285.71428571
      128.0000000000, #  5      457142.85714286
       64.0000000000, #  6      228571.42857143
       32.0000000000, #  7      114285.71428571
       16.0000000000, #  8       57142.85714286
        8.0000000000, #  9       28571.42857143
   ]                  # the end