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 |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
<pre> | |||
# | # | ||
# Pasted in from "perldoc Geo::Shapelib" | # Pasted in from "perldoc Geo::Shapelib" | ||
Line 18: | Line 19: | ||
}; | }; | ||
open(DATA, "<station") || die; | |||
while (<DATA>) { | |||
chomp; | chomp; | ||
Line 29: | 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 | |||
$shapefile->save(); | |||
</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();