[mapserver-users] Raster alignment problem

Frank Warmerdam warmerdam at pobox.com
Thu Oct 9 11:19:49 EDT 2008


Graham Carlyle wrote:
> Hi
> 
> I'm trying to render some maps using Mapserver that contain both vector 
> and raster data. However the raster data doesn't consistently align with 
> the vector data at different zoom levels.
> 
> I've looked at the combination of raster and vector in qgis 11.0 and it 
> displays fine.
> 
> When rendering with Mapserver 5.2.0 the raster image positions 
> differently at different zoom levels. I've also recreated the problem 
> using a simple test raster of alternating values which I created 
> programmatically with libgdal.
> 
> Does anyone have any suggestions as to what I might be doing wrong or 
> how I might debug my problem further? I'm very doubtful that its a bug 
> in mapserver as surely other people would have encountered this.

Graham,

A couple screen shots to show the problem you see would be helpful.

I will note that the default rendering algorithm for raster data is
insensitive to subpixel positioning of rasters which gives noticably
alignment problems when zoomed far in such that one source raster pixel
ends up being several pixels wide on screen.

The issue is that we select the map region into which we need to put the
raster data, and a corresponding region of the source raster and then just
do a simple copy.  Both the map and source region are represented using
integer pixel coordinates, not subregions of a pixel.

So, in an extreme case, if you were zoomed in so far that your map should
be one pixel plus a bit of the next pixel (and the pixel below) we would
compute the source region to be a 2x2 pixel area, and the destination
region to be the whole map view and you would end up with a 2x2 pixel
display with equal area for each pixel rather than it being proportional
as it ought to be.  (Hopefully that makes sense)

The quick workaround is to force rendering to go through the generic
resampling method by adding:

   PROCESSING "RESAMPLE=NEAREST"

in your raster layer.  But this is done at a significant cost in
rendering speed for the raster layer, so I would discourage folks
from doing it by default, unless they are quite concerned about this
sub-pixel accuracy issue.

I have contemplated having the renderer switch into this mode when
zoomed very far in to a raster layer but I'm a bit nervous about
unexpected side effects and doing this right would take a bit of
time.  (well, perhaps the same amount of time as explaining this
problem four or five times!)

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the mapserver-users mailing list