[Mapserver-users] Drawing Lines - Perl

Manfred Meier m.meier at spiekermann.de
Mon Jun 14 08:51:23 PDT 2004


I added a "$layer->addFeature($shape);" and got a red triangle. Is that 
right??

Manfred


Sidnei de Souza schrieb:

> Dear all,
> 
> I'm having a problem drawing lines on-the-fly with Perl mapscript and 
> haven't found anything in the list archive that can help me.
> I'm attaching a perl script that I think should work, but a blank image 
> is produced.
> I'm trying this in a RedHat Linux, with mapserver 4.2.0
> If I change the layer and shape types to POLYGON instead of LINE, a 
> correct polygon is produced.
> Any help will be very welcome!
> Thanks
> sidnei
> 
> #!/usr/local/bin/perl
> 
> use mapscript;
> 
> $map = new mapscript::mapObj('') || die;
> $map->setProjection('proj=longlat');
> 
> 
>  $map->{width}  = 300;
>  $map->{height} = 250;
> 
>  $map->{extent}->{minx} = -53.11;
>  $map->{extent}->{maxx} = -44.16;
>  $map->{extent}->{miny} = -25.30;
>  $map->{extent}->{maxy} = -19.78;
> 
>  my $img = $map->prepareImage();
> 
>  my $point = new mapscript::pointObj();
>  my $line  = new mapscript::lineObj();
>  my $shape = new mapscript::shapeObj($mapscript::MS_SHAPE_LINE);
> 
>  my $layer = new mapscript::layerObj($map);
>  $layer->{'type'} = $mapscript::MS_LAYER_LINE;
>  $layer->{'name'} = 'myline';
>  $layer->{'status'} = 1;
> 
>  $layer->setProjection('proj=longlat');
> 
>  my $class = new mapscript::classObj($layer);
>  $class->{numstyles} = 1;
> 
>  $class->{name} = 'myclass';
>  $class->{styles}->{symbol} = 0;
>  $class->{styles}->{color}->{red} = -1;
>  $class->{styles}->{color}->{green} = -1;
>  $class->{styles}->{color}->{blue} = -1;
> 
>  $class->{styles}->{outlinecolor}->{red} = 255;
>  $class->{styles}->{outlinecolor}->{green} = 0;
>  $class->{styles}->{outlinecolor}->{blue} = 0;
> 
> 
>  $class->{styles}->{'minsize'} = 2;
>  $class->{styles}->{'maxsize'} = 20;
>  $class->{styles}->{'size'} = 5;
> 
>  $point->{x} = -47.0608;
>  $point->{y} = -22.9056;
>  $line->add($point);
> 
>  $point->{x} = -45.65;
>  $point->{y} = -24.55;
>  $line->add($point);
> 
>  $point->{x} = -46.65;
>  $point->{y} = -25.55;
>  $line->add($point);
> 
>  $point->{x} = -47.0608;
>  $point->{y} = -22.9056;
>  $line->add($point);
> 
>  $shape->add($line);
>  $shape->draw($map,$layer,$img);
>  $layer->draw($map,$img);
> 
>  $img->save('myimage.png');
> 
> 
> 




More information about the MapServer-users mailing list