[Mapserver-users] Re: Draw Circle via PHP/MS

pkishor_98 <pkishor at geoanalytics.com> pkishor at geoanalytics.com
Mon Jan 20 12:55:48 EST 2003


--- In mapserver-users at yahoogroups.com, "YC Nyon" <ycnyon at p...> wrote:
> I'm trying to draw a circle using the code below. However it gave an
error
> on the last line.

first, what is the error? it is always helpful for others to know what
the error is.

2nd... you can simplify your code a little bit like so (if you so
desire) --

//$p=ms_newPointObj(); // not needed
$circle=ms_newShapeObj(2);
$line=ms_newlineObj();
$clayer = $map->getLayerByName('Circle');
$class = $clayer->getClass(0);

$pi = pi();
$radius = 10;
$inc = 0;
// assuming $x0 and $y0 are the origin of the circle in geog coords
// and $r is the radius
while ($inc <= 360) {  // changed
 $x = $x0 + ($r * cos(($inc * $pi / 180)));
 $y = $y0 - ($r * cos(($inc * $pi / 180)));
 $line->addXY($x, $y);
 $inc += 10;
}
$clayer->set("status", 1);
$circle->add($line);


> I'm modify it from a snippet I found in the archieves. The map file
contains
> a 'circle' layer.
> 
> // DRAW CIRCLE
>   $p=ms_newPointObj();
>      $circle=ms_newShapeObj(MS_SHAPE_LINE);
>      $line=ms_newlineObj();
>      $clayer = $map->getLayerByName('Circle');
>      $class = $clayer->getClass(0);
> 
>      $pi=3.141592654;
>   $radius = 10;
>      for($i=0;$i<2.1*$pi;$i=$i+$pi/100)
>        {
>           $p->{x} = $real_geo_width + $radius * cos($i);
>           $p->{y} = $real_geo_height + $radius * sin($i);
>           $p->setXY(($real_geo_width + $radius *
cos($i)),($real_geo_height
> + $radius * sin($i)));
>            $line->add($p);
>        }
>      $circle->add($line);
>      $circle->draw($map,$clayer,$image,0,"");
> 
> 
> Regards
> Nyon





More information about the mapserver-users mailing list