MapProxy – How to Load WMS Info to an XYZ Tile

tileswmsxyz-tiles

I am trying to create XYZ tiles from a WMS source. I tried to do it somewhat manually, run into problems (described here), so now I would like to do it using MapProxy. I follow the Getting started part of their website (bottom of the page):

sudo aptitude install python-imaging python-yaml libproj0
sudo pip install mapproxy
mapproxy-util create -t base-config ./
mapproxy-util serve-develop ./mapproxy.yaml

As a result, a server is running locally. I can view the 16/34852/24230 OpenStreetMap tile (chosen as an example) by loading http://localhost:8080/tiles/osm/webmercator/16/34852/24230.png:

enter image description here

mapproxy.yaml is:

# -------------------------------
# MapProxy example configuration.
# -------------------------------
#
# This is a minimal MapProxy configuration.
# See full_example.yaml and the documentation for more options.
#

# Starts the following services:
# Demo:
#     http://localhost:8080/demo
# WMS:
#     capabilities: http://localhost:8080/service?REQUEST=GetCapabilities
# WMTS:
#     capabilities: http://localhost:8080/wmts/1.0.0/WMTSCapabilities.xml
#     first tile: http://localhost:8080/wmts/osm/webmercator/0/0/0.png
# Tile service (compatible with OSM/etc.)
#     first tile: http://localhost:8080/tiles/osm/webmercator/0/0/0.png
# TMS:
#     note: TMS is not compatible with OSM/Google Maps/etc.
#     first tile: http://localhost:8080/tms/1.0.0/osm/webmercator/0/0/0.png
# KML:
#     initial doc: http://localhost:8080/kml/osm/webmercator

services:
  demo:
  tms:
    use_grid_names: true
    # origin for /tiles service
    origin: 'nw'
  kml:
      use_grid_names: true
  wmts:
  wms:
    md:
      title: MapProxy WMS Proxy
      abstract: This is a minimal MapProxy example.

layers:
  - name: osm
    title: Omniscale OSM WMS - osm.omniscale.net
    sources: [osm_cache]

caches:
  osm_cache:
    grids: [webmercator]
    sources: [osm_wms]

sources:
  osm_wms:
    type: wms
    req:
      url: https://maps.omniscale.net/v2/demo/style.default/service?
      layers: osm

grids:
    webmercator:
        base: GLOBAL_WEBMERCATOR

globals:

I would like to load information about the same geographical area, but instead of OpenStreetMap data, I would like to have data from this WMS:

https://wms.cartografia.agenziaentrate.gov.it/inspire/wms/ows01.php

provided by the Italian Revenue Agency. I run into problems, unfortunately.

I think I need to replace the url field (https://maps.omniscale.net/v2/demo/style.default/service?) in the above yaml. The original url ends with service?, just like many others on the examples page.

If I extend the link in the original yaml file by REQUEST=GetCapabilities, and query for https://maps.omniscale.net/v2/demo/style.default/service?REQUEST=GetCapabilities, I get a normal-looking capabilities XML.

I am unsure what /service?-ending URL I should use for the Italian WMS. Based on the capabilities URL of the Italian WMS, my best guess is https://wms.cartografia.agenziaentrate.gov.it/inspire/wms/ows01.php?language=ita&SERVICE https://wms.cartografia.agenziaentrate.gov.it/inspire/wms/ows01.php?language=ita& (modified based on comments).

Another obstacle is that while the omniscale Capabilities XML does seem to support EPSG:3857 (it has the line <SRS>EPSG:3857</SRS>), the Italian Capabilities link does not mention 3857. For example, it does mention EPSG:25832.

I attempt to specify a supported projection of the WMS via the srs field:

srs: ['EPSG:25832']

The [omniscale Capabilities XML] does mention layer name:

<Layer queryable="1" opaque="0" cascaded="0">
<Name>CP.CadastralParcel</Name>

My new yaml file, mapproxy_edited.yaml is:

# -------------------------------
# MapProxy example configuration.
# -------------------------------
#
# This is a minimal MapProxy configuration.
# See full_example.yaml and the documentation for more options.
#

# Starts the following services:
# Demo:
#     http://localhost:8080/demo
# WMS:
#     capabilities: http://localhost:8080/service?REQUEST=GetCapabilities
# WMTS:
#     capabilities: http://localhost:8080/wmts/1.0.0/WMTSCapabilities.xml
#     first tile: http://localhost:8080/wmts/osm/webmercator/0/0/0.png
# Tile service (compatible with OSM/etc.)
#     first tile: http://localhost:8080/tiles/osm/webmercator/0/0/0.png
# TMS:
#     note: TMS is not compatible with OSM/Google Maps/etc.
#     first tile: http://localhost:8080/tms/1.0.0/osm/webmercator/0/0/0.png
# KML:
#     initial doc: http://localhost:8080/kml/osm/webmercator

services:
  demo:
  tms:
    use_grid_names: true
    # origin for /tiles service
    origin: 'nw'
  kml:
      use_grid_names: true
  wmts:
  wms:
    srs: ['EPSG:25832']
    md:
      title: MapProxy WMS Proxy
      abstract: This is a minimal MapProxy example.

layers:
  - name: osm
    title: Omniscale OSM WMS - osm.omniscale.net
    sources: [osm_cache]

caches:
  osm_cache:
    grids: [webmercator]
    sources: [osm_wms]

sources:
  osm_wms:
    type: wms
    req:
      url: https://wms.cartografia.agenziaentrate.gov.it/inspire/wms/ows01.php?language=ita&
      layers: CP.CadastralParcel

grids:
    webmercator:
        base: GLOBAL_WEBMERCATOR

globals:

I launch the server again via mapproxy-util serve-develop ./mapproxy_edited.yaml. Quite unexpectedly, the page http://localhost:8080/tiles/osm/webmercator/16/34852/24230.png still returns the same image as above. I think this might be due to caching, so I check a completely different tile:

http://localhost:8080/tiles/osm/webmercator/16/35726/24974.png

The response I get:

no image returned from source WMS:
https://wms.cartografia.agenziaentrate.gov.it/inspire/wms/ows01.php?language=ita&&layers=CP.CadastralParcel&format=image%2Fpng&bbox=1807391.752317136,-1810219.9223636861,1810219.9223636861,-1807391.752317136&width=1184&height=1184&srs=EPSG%3A3857&request=GetMap&version=1.1.1&service=WMS&styles=

How can I view the data the WMS server has, for a particular tile?


I expect 16/34852/24230.png to look something like, but not exactly like this:

enter image description here

(I borrowed this image from the question which inspired this question.)

Best Answer

A client (such as MapProxy) shouldn't request images from a service in a CRS that isn't reported as being supported by the service in the GetCapabilities response.

MapProxy can do reprojection of received images, so you just need to let MapProxy know which CRS are supported by the input source using the supported_srs value in your yaml file, like:

sources:
    osm_wms:
        type: wms
        supported_srs: ['EPSG:25832']
        req:
            url: https://wms.cartografia.agenziaentrate.gov.it/inspire/wms/ows01.php?language=ita&
            layers: CP.CadastralParcel