4

I have two MapServer WMS layers that I want to overlay on each other in OpenLayers. One comes from vector data in a PostGIS table, and the other comes from raster data in another PostGIS table. They both have the same projection in PostGIS, the mapfile, and OpenLayers (EPSG:4326). The vector layer is simply a 0.5° x 0.5° grid, the raster layer has a resolution of 0.5° and they have the same origin, so they should align with each other. However, depending upon the bounding box of the WMS request issued by OpenLayers, they don't. It seems like MapServer is unable to return part cells from the PostGIS raster.

Here is an example WMS request:

http://46.43.3.32/cgi-bin/mapserv?map=/var/www/mapfiles/testing1.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=rasters,grid&SRS=EPSG:4326&STYLES=&WIDTH=2024&HEIGHT=600&BBOX=-14.840529126958776,32.55961652888951,7.395798998041224,39.15141340388951

Which gives:

GetMap request showing misaligned layers

The alignment changes depending upon the bounding box. If I round the bounding box coordinates to integers, the two layers align correctly with each other (almost) reliably, but unsurprisingly this creates an unfortunate 'jumping around' effect in OpenLayers, where the user pans to a particular location but the map then jumps to slightly different location.

It seems to be a MapServer issue caused by the relatively large cell size in the raster.

I'm using MapServer 6.4.1, GDAL 1.10.1, PostgreSQL 9.4.9, PostGIS 2.1.4, OpenLayers 4.0.1, WMS 1.1.1

0

1 Answer 1

2

I opened the same service layers in QGIS and can't replicate the problem, whatever the zoom or location, the layers are always aligned. I ask for the two layers separately.

raster and grid WMS layers in QGIS

Suggested strategy for OpenLayers then would be to ask for the layers separately.

Oddly, this single request also works for me:

http://46.43.3.32/cgi-bin/mapserv?map=/var/www/mapfiles/testing1.map&&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=19.99647818503929386,23.94108767768300794,28.97272303358786871,33.50801373835698627&CRS=EPSG:4326&WIDTH=907&HEIGHT=852&LAYERS=rasters,grid&STYLES=,&FORMAT=image/png&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE

Gives:

WMS 1.3.0 GetMap with aligned grid

Similarly

http://46.43.3.32/cgi-bin/mapserv?map=/var/www/mapfiles/testing1.map&&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=30.56028970048615179,-11.53845925556137963,40.87960453561225904,1.923729518252944359&CRS=EPSG:4326&WIDTH=1058&HEIGHT=812&LAYERS=rasters,grid&STYLES=,&FORMAT=image/png&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE

Gives:

WMS 1.3.0 GetMap with aligned grid

I converted my WMS 1.3.0 request to a WMS 1.1.1 as below, and now I am replicating your issue.

So http://46.43.3.32/cgi-bin/mapserv?map=/var/www/mapfiles/testing1.map&&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX=-11.53845925556137963,30.56028970048615179,1.923729518252944359,40.87960453561225904&SRS=EPSG:4326&WIDTH=1058&HEIGHT=812&LAYERS=rasters,grid&STYLES=,&FORMAT=image/png&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE

Gives:

WMS 1.1.1 GetMap with misaligned grid

So I'm not sure why, but it looks like the version of WMS you are using might make a difference.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.