Mapscript extent prediction

Tamas Szekeres szekerest at GMAIL.COM
Wed May 23 14:57:25 PDT 2007


Here's the code applied to the extent when drawing the map:

#define MS_CELLSIZE(min,max,d)    ((max - min)/(d-1))

double msAdjustExtent(rectObj *rect, int width, int height)
{
  double cellsize, ox, oy;

  cellsize = MS_MAX(MS_CELLSIZE(rect->minx, rect->maxx, width),
MS_CELLSIZE(rect->miny, rect->maxy, height));

  if(cellsize <= 0) /* avoid division by zero errors */
    return(0);

  ox = MS_MAX(((width-1) - (rect->maxx - rect->minx)/cellsize)/2,0);
/* these were width-1 and height-1 */
  oy = MS_MAX(((height-1) - (rect->maxy - rect->miny)/cellsize)/2,0);

  rect->minx = rect->minx - ox*cellsize;
  rect->miny = rect->miny - oy*cellsize;
  rect->maxx = rect->maxx + ox*cellsize;
  rect->maxy = rect->maxy + oy*cellsize;

  return(cellsize);
}

Having the width and height of the map the modified extent can easily
be calculated.

Best regards,

Tamas


2007/5/23, Johan Van de Wauw <johan.vandewauw at gmail.com>:
> Even though I found a workaround that works for my application (generating
> the image first and later the accompying html page), the original problem
> still persists.
>
> Just a short example of code (where the width and height are based on the
> extent, like in my application) and it's output. My hypothesis is that maybe
> the longitude/latitude values are the problem?
>
> dl('php_mapscript.so');
> $oMap = ms_newMapObj('/home/johan/rwanda/start-print.map');
> $mapExtent = $oMap->extent;
> $oMap->setExtent($aExtent[0],$aExtent[1],$aExtent[2],$aExtent[3]);
>  $tot = $oMap->numlayers;
> $pw = 600;
>  $gw =$aExtent[2] - $aExtent[0];
>  $gh = $aExtent[3] - $aExtent[1];
>  $ph = ceil($pw*$gh/$gw);
>  $oMap->set('width', $pw);
>  $oMap->set('height', $ph);
> $oMap->selectOutputFormat('PNG');
>
> var_dump($oMap->extent);
> $oImg = $oMap->draw();
> var_dump($oMap->extent);
> die;
>
> gives the following output:
> object(ms_rect_obj)#2 (5) {
>
>  ["_handle_"]=>
>  resource(3) of type (Unknown)
>  ["minx"]=>
>  float(29.7975484895)
>  ["miny"]=>
>  float(-1.93103563105)
>  ["maxx"]=>
>  float(29.9594623555
> )
>  ["maxy"]=>
>  float(-1.80965089289)
> }
> (and after the draw method is called:)
>
> object(ms_rect_obj)#2 (5) {
>  ["_handle_"]=>
>  resource(3) of type (Unknown)
>  ["minx"]=>
>
>  float(29.7596991183)
>  ["miny"]=>
>  float(-1.93103563105)
>  ["maxx"]=>
>  float(29.9973117267)
>  ["maxy"]=>
>  float(-1.80965089289)
> }
>
>
>
> >
> >
> >
> > 2007/5/23, Johan Van de Wauw <johan.vandewauw at gmail.com>:
> > > Hello everyone,
> > >
> > > When generating a map using mapscript, I notice that the extent changes
> > > (slightly) after calling the "draw" operation.
> > > I don't seem to be the only one with this problem as eg the ka-map wiki
> > > says:
> > >
> > > Print output is related to viewport but image extent correspondence in
> not
> > > yet perfect.
> > >
> > > Is there a way to make this correspondence better, or is there a way to
> > > get/predict the actual extent used in the image before (or without)
> calling
> > > the "draw" method?
> > >
> > > Johan
> > >
> >
>
>



More information about the MapServer-users mailing list