PERL - Geo::Shapelib help
    JFD 
    jdutton at AWS.COM
       
    Tue Mar  8 12:16:29 PST 2005
    
    
  
Hello,
I'm trying to create a polygon shapefile using the PERL module
Geo::Shapelib and find I can't quite get it.
At this stage, I'm just trying to create a square polygon to get the hang
of it, before moving on to bigger and better things.    Unfortunately, the
script bombs on me despite many consultations of the man page and the ESRI
shapefile whitepaper.   My best attemp to accomplish this task is below.
Any guidance on what I'm doing wrong would be greatly appreciated.
Thanks,
JFD
------------------------------------------------------------------
#!/usr/bin/perl
#
#  an attempt to create a polygon shapefile
#
use strict ;
use Geo::Shapelib ;
# points of the polygon
my @lat = (45.0,   45.0,  55.0,  55.0,  45.0)  ;
my @lon = (-75.0, -85.0, -85.0, -75.0, -75.0)  ;
my @verts = (
        [$lat[0], $lon[0]],
        [$lat[1], $lon[1]],
        [$lat[2], $lon[2]],
        [$lat[3], $lon[3]],
        [$lat[4], $lon[4]]
        )  ;
#print "@verts\n" ;
my $shape = new Geo::Shapelib;
$shape->{Shapetype} = 5;
$shape->{MinBounds} = [20,-100] ;
$shape->{MaxBounds} = [80,-10] ;
$shape->{FieldNames} = ['ID',     'SPD','DIR'];
$shape->{FieldTypes} = ['Integer','Integer','Integer'];
        push @{$shape->{Shapes}}, {
        SHPType=>5,
        ShapeId=>1,
        Nparts=>0,
        NShapes=>0,
        NVertices=>5,
        Vertices=>[\@lat, \@lon]
        };
        push @{$shape->{ShapeRecords}}, [1,13,250];
        #i++;
        $shape->dump();
$shape->save('/mydir/test');
    
    
More information about the MapServer-users
mailing list