WritePoint.pl

From Wildsong
Revision as of 21:52, 11 April 2006 by Brian Wilson (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
  1. Pasted in from "perldoc Geo::Shapelib"
  2. 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 () {
   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();