[mapserver-users] Problems with non-square pixels

Frank Warmerdam warmerdam at pobox.com
Thu Jul 16 12:40:32 PDT 2009


Michael Pfeiffer wrote:
> Try this wms request
> 
> http://www.sogis1.so.ch/cgi-bin/sogis/sogis_print_test.wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image/jpeg&LAYERS=Orthofoto&STYLES=&TRANSPARENT=true&BBOX=605035.8790650383,224864.94050038885,609110.4623983715,230528.7877226111&WIDTH=6417&HEIGHT=8921&SRS=EPSG:21781
> A0 portrait 
> 
> This request needs over 1 minute.

Michael,

There seems to be a modest difference in the aspect ratio of the BBOX
and the SIZE in the given request. The logic in mapwms.c that tests whether
non-square mode needs to be used looks like this:

   /* Check whether requested BBOX and width/height result in non-square pixels
    */
   nonsquare_enabled = msTestConfigOption( map, "MS_NONSQUARE", MS_FALSE );
   if (!nonsquare_enabled)
   {
       double dx, dy, reqy;
       dx = MS_ABS(map->extent.maxx - map->extent.minx);
       dy = MS_ABS(map->extent.maxy - map->extent.miny);

       reqy = ((double)map->width) * dy / dx;

       /* Allow up to 1 pixel of error on the width/height ratios. */
       /* If more than 1 pixel then enable non-square pixels */
       if ( MS_ABS((reqy - (double)map->height)) > 1.0 )
       {
           if (map->debug)
               msDebug("msWMSLoadGetMapParams(): enabling non-square pixels.\n");
           msSetConfigOption(map, "MS_NONSQUARE", "YES");
           nonsquare_enabled = MS_TRUE;
       }
   }

I suspect the asymmetry is just enough to amount more than one pixel at
this size.  I didn't run all the numbers but I suspect at smaller paper
sizes (smaller SIZE values) the assymmetry amounts to less than one pixel.
I'm not sure why it would affect portrait and not landscape.  I only ran
the ratios on the case you mentioned was slow.

So there are a couple of possibilities here.

  1) It is possible the above computation is wrong.  I vaguely recall there
     is an issue with map->extent actually being from the center of edge
     pixel to the center of edge pixel, not the outer edges, in which case
     the calculation should perhaps be:
       reqy = MS_ABS(((map->width - 1) * dy / dx) + 1);
     which might or might not make a difference in this case.

  2) Perhaps you just need to generate your WMS requests with more precise
     BBOXes corresponding to the aspect ratio of the SIZE requested.

Well, I'm sure there could be other possibilities too.

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