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 1: Line 1:
<pre>
#
#
#  Pasted in from "perldoc Geo::Shapelib"
#  Pasted in from "perldoc Geo::Shapelib"
Line 34: Line 35:
   
   
  $shapefile->save();
  $shapefile->save();
</pre>

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();