[Mapserver-users] How is the scale calculated??

Steve Lime steve.lime at dnr.state.mn.us
Thu Jun 17 23:30:18 PDT 2004


The code is in mapscale.c, note that typically MapServer adjusts the
requested extent to "perfectly" fit the requested image size before
computing scale. This fitting gives you cellsizex = cellsizey. It's
pretty straight forward from there.

Steve

>>> "Murilo Lacerda Yoshida" <murilo.yoshida at agx.com.br> 06/17/04 7:07
PM >>>
  Hi all,
  I am trying to dynamically change the scalebar units, from meters to
kilometers, when needed. Because if I don't the scale gets too crowded,
on value gets over another, and it becomes a mess.
  I did a script to calculate the values in the scale, apparently it is
right, but the values are not equal, although they are close.
  
 
See if it is ok
 
$minX = $map->extent->minx;
$maxX = $map->extent->maxx;
 
$minY = $map->extent->miny;
$maxY = $map->extent->maxy;
 
$minPto = calcularUtm($minY, $minX);
$maxPto = calcularUtm($maxY, $maxX);
 
$deltaX = abs($maxPto->x - $minPto->x);
echo "deltaX = " . $deltaX . "<br>\n";
$deltaY = abs($maxPto->y - $minPto->y);
echo "deltaY = " . $deltaY . "<br>\n";
 
$diagonal = sqrt( ($deltaX * $deltaX) + ($deltaY * $deltaY) );
echo "diagonal = " . $diagonal . "<br>\n";
 
$deltaEscala = $map->scalebar->width;
echo "deltaEscala = " . $deltaEscala . "<br>\n";
$intEscala = $map->scalebar->intervals;
echo "intEscala = " . $intEscala . "<br>\n";
$pixelMapaX = $map->width;
echo "pixelMapaX = " . $pixelMapaX . "<br>\n";
$pixelMapaY = $map->height;
echo "pixelMapaY = " . $pixelMapaY . "<br>\n";
 
$diagonalPixel = sqrt( ($pixelMapaX * $pixelMapaX) + ($pixelMapaY *
$pixelMapaY) );
echo "diagonalPixel = " . $diagonalPixel . "<br>\n";
 
$escalaX = ($deltaEscala * $deltaX) / $pixelMapaX;
echo "escalaX = " . $escalaX . "<br>\n";
$escalaY = ($deltaEscala * $deltaY) / $pixelMapaY;
echo "escalaY = " . $escalaY . "<br>\n";
$escalaD = ($deltaEscala * $diagonal) / $diagonalPixel;
echo "escalaD = " . $escalaD . "<br>\n";
 
echo "cada intervalo em x igual a : " . ($escalaX / $intEscala) .
"<br>\n";
echo "cada intervalo em y igual a : " . ($escalaY / $intEscala) .
"<br>\n";
echo "cada intervalo em diagonal igual a : " . ($escalaD / $intEscala) .
"<br>\n";
 
  The scale bar gives me 2 intervals of 220 meters.
  With this method I get 2 intervals of 250 meters in the x axis, 2
intervals of 277 meters in the y axis and 2 intervals of 260 meters in
the diagonal.
 
  Does anyone know how the mapserver calculates the scale values?
  Thanks,
     Murilo
 




More information about the MapServer-users mailing list