[Mapserver-users] Drawing Lines - Perl
Sean Gillies
sgillies at frii.com
Mon Jun 14 09:10:31 PDT 2004
On Jun 14, 2004, at 9:28 AM, Sidnei de Souza wrote:
> 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
>
Sidnei,
I am going to weave a few comments and corrections into your script.
> #!/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;
>
best practice for changing extents is to use setExtent()
$map->setExtebt(-53.11, -25.30, -44.16, -19.78);
this is because the map's scaling needs to be recalculated
after a change of extent.
> 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;
Access to styles has been changed in version 4.2. The recommended
usage is now
$class->getStyle(0)->{symbol} = 0;
> $class->{styles}->{color}->{red} = -1;
> $class->{styles}->{color}->{green} = -1;
> $class->{styles}->{color}->{blue} = -1;
>
Above you will need to define real color values because a LINE type
layer is rendered using COLOR and ignores OUTLINECOLOR. Also, as with
extents, you should use the setRGB() method
$style = $class->getStyle(0);
$style->setRGB(255, 0, 0);
because there is a hidden pen parameter that needs to be set.
> $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');
>
>
>
> --
> Sidnei de Souza
> Diretor de Informática, CRIA
>
> "Feliz aquele que transfere o que sabe e aprende o que ensina." [Cora
> Coralina]
>
cheers,
Sean
--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies
More information about the MapServer-users
mailing list