[MapProxy] Restricting a layer to a polygon extent

Paul Norman penorman at mac.com
Thu Sep 6 20:09:29 PDT 2012


> From: mapproxy-bounces at lists.osgeo.org [mailto:mapproxy-
> bounces at lists.osgeo.org] On Behalf Of Paul Norman
> Sent: Tuesday, September 04, 2012 5:16 PM
> To: mapproxy at lists.osgeo.org
> Subject: [MapProxy] Restricting a layer to a polygon extent
> 
> I have a mapproxy server that I am going to be using to mosaic several
> imagery layers together. Some are local caches of WMS layers but one of
> them is a cache of a TMS layer with the lower zoom tiles pre-cached.
> 
> To mosaic the imagery I need to have it transparent outside a polygon
> extent, unfortunately the tile layer is black outside of its extent and
> not transparent. To get around this I was intending to use the
> authorization API.

I got everything working, so I'm posting what worked for me so the next
person asking these questions has a better chance of finding answers.

I had to add a wrapper function around make_wsgi_app. The following example
allows all calls except GetMap calls and only allows GetMap to return one
layer within a polygon. I point WSGI at it through the apache config

def auth(service, layers=[], environ=None, **kw):
    if service != 'wms.map':
        return {'authorized':'full'}
    else:
        return {
            'authorized':'partial',
            'layers': 
            {
                'surrey2011': 
                {
                    'map': True,
                    'limited_to': 
                    {
                        'geometry': 'MULTIPOLYGON(((-122.931300
49.229840,-122.846600 49.229760,-122.685300 49.229430,-122.656500
49.229350,-122.658100 48.995400,-122.706800 48.995530,-122.752000
48.995640,-122.792200 48.995720,-122.792100 49.010100,-122.890600
49.010240,-122.890500 49.076810,-122.931500 49.076840,-122.931300
49.229840)))',
                        'srs': 'EPSG:4326'
                    }
                }
            }
        }
    
from mapproxy.wsgiapp import make_wsgi_app

_application = make_wsgi_app(r'/srv/tiles/mapproxy/config/mapproxy.yaml')

def application(environ, start_response):
    environ['mapproxy.authorize'] = auth
    return _application(environ, start_response)

I had to set up mapproxy to use itself as a remote WMS server. Briefly, I
had (portions omitted)

layers:
- name: bc_gvrd_west_2009
  sources: [bc_gvrd_west_2009_cache]
- name: bc_mosaic
  sources: [bc_mosaic_cache]
- name: surrey2011	
  sources: [surrey2011_cache]

caches:
  bc_gvrd_west_2009_cache:
    sources: [bc_gvrd_west_2009_wms]
  bc_mosaic_cache:
    meta_size: [1, 1]
    meta_buffer: 0
    sources: [lower_quality_layers, bc_gvrd_west_2009_tms, surrey2011_wms]
  surrey2011_cache:
    sources: [merry_surrey2011_tms]
sources:
  bc_gvrd_west_2009_wms:
    type: wms
    ... details on the slow remote server
  merry_surrey2011_tms:
    type: tile
    url: my home server with the full imagery on a slow connection
    ...
  surrey2011_wms:
    type: wms
    supported_srs: ['EPSG:900913']
    concurrent_requests: 8
    supported_formats: ['image/png']
    coverage:
      polygons: 'wkt/surrey2011.wkt'
      polygons_srs: 'EPSG:4326'
    req:
      url: http://127.0.0.1/path_to_mapproxy/service?
      transparent: true
      layers: surrey2011
  bc_gvrd_west_2009_tms:
    type: tile
    url:
http://imagery.paulnorman.ca/tiles/bc_gvrd_west_2009/%(tms_path)s.png

I also had to set palletted: false, use image/png RGBA for everything and
add lots of transparent:true

I hope this helps the next person trying to do this. I intend to
periodically prune bc_mosaic_cache as it can be regenerated without any
requests to remote servers.



More information about the MapProxy mailing list