| 1 | = project.pl = |
| 2 | {{{ |
| 3 | #!perl |
| 4 | #!/usr/bin/perl |
| 5 | |
| 6 | # File: project.pl |
| 7 | # |
| 8 | # Purpose: This script takes a shapefile as input along with 2 Proj.4 |
| 9 | # projection descriptions. |
| 10 | # |
| 11 | # Syntax: project.pl [from projection] [to projection] [in shapefile] [out shapefile] |
| 12 | # |
| 13 | # Author: Stephen Lime (08/05/02) |
| 14 | |
| 15 | use mapscript; |
| 16 | |
| 17 | sub show_syntax() { |
| 18 | print "Syntax: project.pl [from projection] [to projection] [in shapefile] [out shapefile]\n"; |
| 19 | exit 0; |
| 20 | } |
| 21 | |
| 22 | &show_syntax() unless $#ARGV == 3; |
| 23 | |
| 24 | # |
| 25 | # open the shapefiles |
| 26 | # |
| 27 | $in_shapefile = new shapefileObj($ARGV[2], -1) or die "Unable to open input shapefile."; |
| 28 | $out_shapefile = new shapefileObj($ARGV[3], $in_shapefile->{type}) or die "Unable to open output shapefile."; |
| 29 | |
| 30 | # |
| 31 | # make a copy of the dBase file |
| 32 | # |
| 33 | system("cp ". $ARGV[2] .".dbf ". $ARGV[3] .".dbf"); |
| 34 | |
| 35 | # |
| 36 | # create a couple of projection objects |
| 37 | # |
| 38 | $from_projection = new projectionObj($ARGV[0]) or die "Unable to initialize \"from\" projection."; |
| 39 | $to_projection = new projectionObj($ARGV[1]) or die "Unable to initialize \"to\" projection."; |
| 40 | |
| 41 | # |
| 42 | # and finally loop through the shapefile |
| 43 | # |
| 44 | $shape = new shapeObj($in_shapefile->{type}); |
| 45 | for($i=0; $i<$in_shapefile->{numshapes}; $i++) { |
| 46 | $status = $in_shapefile->get($i, $shape); |
| 47 | die "Error reading shape $i." unless $status == $mapscript::MS_SUCCESS; |
| 48 | $shape->project($from_projection, $to_projection); |
| 49 | $out_shapefile->add($shape); |
| 50 | } |
| 51 | |
| 52 | undef $out_shapefile; |
| 53 | exit; |
| 54 | }}} |
| 55 | ---- |
| 56 | back to PerlMapScript |