WritePoint.pl: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
mNo edit summary
Brian Wilson (talk | contribs)
mNo edit summary
 
Line 19: Line 19:
   };
   };


open(DATA, "<station") || die;
open(DATA, "<station") || die;
 
while (<DATA>) {
while (<DATA>) {
     chomp;
     chomp;


Line 30: Line 30:
     push @{$shapefile->{Shapes}},{ Vertices => [[$x,$y,0,0]] };
     push @{$shapefile->{Shapes}},{ Vertices => [[$x,$y,0,0]] };
     push @{$shapefile->{ShapeRecords}}, [$station,$code,$founded];
     push @{$shapefile->{ShapeRecords}}, [$station,$code,$founded];
}
}
   
   
# Write shapefile to disk
# Write shapefile to disk
   
   
$shapefile->save();
$shapefile->save();
</pre>
</pre>

Latest revision as of 21:53, 11 April 2006

#
#  Pasted in from "perldoc Geo::Shapelib"
#
#  Reads an ASCII file delimited by '|' and generates a shapefile.
#
use strict;
use Geo::Shapelib qw/:all/;

chdir('/cygdrive/c/BRIANS_JUNK/PERL');

my $file = 'station';

my $shapefile = new Geo::Shapelib {
       Name       => $file,
       Shapetype  => POINT,
       FieldNames => ['Name', 'Code', 'Founded'],
       FieldTypes => ['String:50','String:10','Integer:8'],
   };

open(DATA, "<station") || die;

while (<DATA>) {
    chomp;

    # Parse the input from the ASCII file
    my ($station,$code,$founded,$x,$y) = split /\|/;

    # Stash it in the shapefile
    push @{$shapefile->{Shapes}},{ Vertices => [[$x,$y,0,0]] };
    push @{$shapefile->{ShapeRecords}}, [$station,$code,$founded];
}
 
# Write shapefile to disk
 
$shapefile->save();