-
Notifications
You must be signed in to change notification settings - Fork 2
PerlMapScriptExamples35ex11
#!perl
#!/usr/bin/perl
use mapscript;
sub show_syntax() {
print "Syntax: project.pl [from projection] [to projection] [in shapefile] [out shapefile]\n";
exit 0;
}
&show_syntax() unless $#ARGV == 3;
$in_shapefile = new shapefileObj($ARGV[2], -1) or die "Unable to open input shapefile.";
$out_shapefile = new shapefileObj($ARGV[3], $in_shapefile->{type}) or die "Unable to open output shapefile.";
system("cp ". $ARGV[2] .".dbf ". $ARGV[3] .".dbf");
$from_projection = new projectionObj($ARGV[0]) or die "Unable to initialize "from" projection.";
$to_projection = new projectionObj($ARGV[1]) or die "Unable to initialize "to" projection.";
$shape = new shapeObj($in_shapefile->{type});
for($i=0; $i<$in_shapefile->{numshapes}; $i++) {
$status = $in_shapefile->get($i, $shape);
die "Error reading shape $i." unless $status == $mapscript::MS_SUCCESS;
$shape->project($from_projection, $to_projection);
$out_shapefile->add($shape);
}
undef $out_shapefile;
exit;
----
back to PerlMapScrip