mapcache icon indicating copy to clipboard operation
mapcache copied to clipboard

mapcache: metabuffer size violates max extents for epsg:3857 wms

Open computerchemist opened this issue 8 years ago • 0 comments

using mapcache 1.6.1, mapserver 7.0.4 & 7.2.1

mapcache xml fragment:

<tileset name="test"> <source>orbis</source> <cache>goog</cache> <grid>GoogleMapsCompatible</grid> <format>PNG</format> <metatile>8 8</metatile> <metabuffer>200</metabuffer> <expires>99999999999</expires> </tileset> <cache name="goog" type="disk" layout="template"> <template>/var/gis/globe/mapcache/map/{z}/{x}/{inv_y}.{ext}</template> </cache>

with a corresponding 'labelcache_map_edge_buffer' '-200' in mapserver map file.

Unwanted wraparound distortion artefacts from rasters are produced in a mapserver render when rendering the planet using mapcache_seed at levels 0 through 14, centered on the antemeridian.

Examination of the WMS log shows the following bbox for a level 3 request from mapcache, which is a full planet grab in one WMS call: &BBOX=-23951084.190990%2c-23951084.190990%2c23951084.190990%2c23951084.190990&WIDTH=2448&HEIGHT=2448

It should be fairly obvious that the bounds are outside of the expected 3857 range - i.e. 20037508.342789 in all directions.

If the metabuffer is set to zero, and the corresponding 'labelcache_map_edge_buffer' mapserver entry removed, the following bbox is returned from mapcache - this does not produce any raster distortion effects but labels are clipped as expected (this is obviously not what is wanted). The important point to note is the bbox is within the bounds for a 3857 projection.

&BBOX=-20037508.342789%2c-20037508.342789%2c20037508.342789%2c20037508.342789&WIDTH=2048&HEIGHT=2048

The difference here is that both width and height are 400 pixels less, i.e. the metabuffer * 2 - in other words, the metabuffer being calculated by mapcache is exceeding the permissible bounds of an epsg:3857 when close to the antemeridian.

There is no "perfect solution" to this problem as mapserver generally goes crazy when any attempt to cross the antemeridian is made using rasters. I would suggest a good workaround would be in mapcache to swap the bounds checking in tileset.c for mapcache_tileset_metatile_get so that the checking and clipping is performed AFTER the metabuffer is added to the metatile size, and any potential buffer overflow which would intersect the antemeridian is simply discarded (i.e. recalculated) before being sent to wms..

Any thoughts on a sensible way forward are appreciated; it's very unlikely that mapserver will ever be fixed from this feature (although vectors are now correctly parsed, and in theory raster with "LOAD_WHOLE_IMAGE=YES" should work, in my use case they do not, and there are many long standing requests for this to be fixed from 10+ years ago - I know it is a non-trivial exercise to fix in mapserver).

To summarise, I would suggest that when seeding (or indeed a normal request is made) a bounds check is required post-buffer calculation which would adjust the image size and extents so that no crossing of the antemeridian is attempted before attempting to call WMS. Does that sound reasonable?

computerchemist avatar Nov 21 '18 10:11 computerchemist