File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # !/usr/bin/perl
2+ # Manipulate x,y coordinates in .map files. Example here for CPP proj to lon/lat
3+
4+ if (@ARGV !=4) {
5+ die " usage: $0 infile (.map) outfile(.map) CPP_lon CPP_lat\n " ;
6+ }
7+ $file = $ARGV [0];
8+ $outfile = $ARGV [1];
9+ $lam0 =$ARGV [2];
10+ $phi0 =$ARGV [3];
11+
12+ open (IN," <$file " ); @all =<IN>; close (IN);
13+ open (OUT," >$outfile " );
14+
15+ $linenum =0;
16+ while ($linenum <@all ) {
17+ @char =split (" " ,$all [$linenum ]);
18+ if ($char [0] =~ " XY" ) {
19+ @char2 [0..1]=projection($lam0 ,$phi0 ,$char [1],$char [2]);
20+ print OUT " XY @char2 0.0\n " ;
21+ }
22+ elsif ($char [0] =~ " ARCVERTICES" ) {
23+ $np =$char [1];
24+ print OUT $all [$linenum ];
25+ for ($i =1;$i <=$np ;$i ++) {
26+ @char =split (" " ,$all [$linenum +$i ]);
27+ @char2 [0..1]=projection($lam0 ,$phi0 ,$char [0],$char [1]);
28+ print OUT " @char2 0\n " ;
29+ } # for
30+ $linenum =$linenum +$np ;
31+ }
32+ else {
33+ print OUT $all [$linenum ];
34+ }# if
35+
36+ $linenum ++;
37+ } # while
38+ # =~ "ARCVERTICES" #followed by np \n x y 0 ....
39+ close (OUT);
40+
41+ # Modify this routine as you wish for reproj
42+ sub projection {
43+ ($lam00 ,$phi00 ,$x ,$y )=@_ ;
44+ $rearth =6378206.4;
45+ $pi =3.1415926;
46+
47+ $lam =$lam00 /180*$pi ;
48+ $phi =$phi00 /180*$pi ;
49+ # $lam0=-124.35/180*$pi; $phi0=43.36/180*$pi;
50+ $xl =$lam +$x /$rearth /cos ($phi );
51+ $yl =$y /$rearth ;
52+ $xout =$xl /$pi *180;
53+ $yout =$yl /$pi *180;
54+ # $lam0=-124.498333333/180*$pi; $phi0=42.73833333333/180*$pi;
55+ # $xout=$rearth*($xl-$lam0)*cos($phi0);
56+ # $yout=$yl*$rearth;
57+ return ($xout ,$yout );
58+ } # sub
You can’t perform that action at this time.
0 commit comments