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:,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

  • can you add a screen shot that shows the issue
    – Ian Turton
    Sep 10, 2017 at 10:54
  • This is an interesting issue. I think it best to add screenshots rather than a live link, as the live link might not work soon. One suggestion I have is to change some interpolation settings? If you can get the raster interpolating properly, it should work. You could also evaluate GeoServer, to see how it handles the same data.
    – Alex Leith
    Sep 10, 2017 at 11:07

1 Answer 1


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

Any pointers gratefully received

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

Oddly? this single request also works for me:,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


WMS 1.3.0 GetMap with aligned grid



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.



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.

  • Thanks for the suggestion, but I'm already requesting the two layers separately in OpenLayers (apologies, I realise that the example request was misleading in that regard)
    – Tom Butlin
    Sep 11, 2017 at 12:19
  • It certainly interesting that QGIS sends two separate requests and gets alignment, but OpenLayers sends two requests are you don't get alignment, from the same service.
    – nmtoken
    Sep 11, 2017 at 12:34
  • Confirming, that when I open the service in ArcMap as WMS 1.1.1 then I get the behaviour you describe when I pan the map (misaligned grid jumping around...), but when I open as WMS 1.3.0 then I get no issues. Toggling between the grid layers only (WMS 1.1.1 and WMS 1.3.0) there is no misalignment. Conversely toggling between the raster layers there is misalignment. Ergo... it is the raster layer of the WMS 1.1.1 service that has some issue.
    – nmtoken
    Sep 11, 2017 at 17:47
  • Wow, that's it! Thanks for your help. I've switched to WMS 1.3.0.
    – Tom Butlin
    Sep 11, 2017 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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