[MapProxy] Limit coverage to a polygon

dirk.thalheim at bkg.bund.de dirk.thalheim at bkg.bund.de
Sun Jul 17 23:14:43 PDT 2016


Hi,

as far as I understand, MapProxy just checks if the requested bbox intersects with the defined shape. If so it returns the full image. So clipping is not out of the box possible within the configuration of your service.

However you can accomplish this with authorization filters (@see https://mapproxy.org/docs/latest/auth.html). This is how we do it. We use PasteDeploy and a custom AuthFilter.

Here is the paste config:
  paste.filter_app_factory = clipping:GeometryAuthFilter
  shape = /path/to/shape.shp

And here the filter code (clipping is implemented for all layers within a wms):
  import logging

  from mapproxy.util.geom import (
      load_datasource,
      load_ogr_datasource,
      load_polygons,
      require_geom_support,
      build_multipolygon,
  )

  LOGGER = logging.getLogger('mapproxy.clipping')

  class GeometryAuthFilter(object):
      def __init__(self, app, global_conf, shape, where=None, srs='EPSG:4326'):
          self.app = app
          LOGGER.info('Loading clipping shape %s' % shape)
          geom = load_ogr_datasource(shape, where)
          self.bbox, self.geom = build_multipolygon(geom, simplify=True)
          self.srs = srs

      def __call__(self, environ, start_reponse):
          # put authorize callback function into environment
          environ['mapproxy.authorize'] = self.authorize
          return self.app(environ, start_reponse)

      def authorize(self, service, layers=[], environ=None, **kw):
          if service.startswith('wms.'):
              rights = {'authorized': 'partial', 'layers': {}}
              for layer in layers:
                  rights['layers'][layer] = { 'map': True, 'limited_to': { 'geometry': self.geom, 'srs': self.srs } }
              return rights
          return {'authorized': 'full'}

Kind regards,

Dirk

Von: MapProxy [mailto:mapproxy-bounces at lists.osgeo.org] Im Auftrag von Pestereva, Anna
Gesendet: Freitag, 15. Juli 2016 19:39
An: mapproxy at lists.osgeo.org
Betreff: Re: [MapProxy] Limit coverage to a polygon

Marcus,

I've had the same experience with cropped WMS. Note that as you zoom in to your AOI, you should see imagery being cropped closer to the polygon - like on the northern side of the red line in the example below.
If there is a better solution, I'd like to learn about it too.

[Inline image 1]
--
Anna Pestereva, GISP | Application Developer & Cartographer
Aerial Services, Inc. (ASI)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapproxy/attachments/20160718/dd022e83/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 29315 bytes
Desc: image001.png
URL: <http://lists.osgeo.org/pipermail/mapproxy/attachments/20160718/dd022e83/attachment-0001.png>


More information about the MapProxy mailing list