Posted By

vinocui on 07/15/09


Tagged

longitude latitude OZI


Versions (?)

Tool for calibrate latitude & longitude for OZI map file


 / Published in: Perl
 

OZIexplorer is hard to calibrate maps. And I need a tool to calibrate the .map files generated from TrekBuddyAtlasCreator_v1.1. So I wrote it.

  1. #!/path/to/perl
  2. # [email protected]
  3. # 2009/7/15
  4. # tool for calibrate latitude & longitude in *.map files generated
  5. # by TrekBuddy_Atlas_Creator_v1.1
  6.  
  7. my $line;
  8. my $argc = @ARGV;
  9.  
  10. # Actual: N39°4'21.9" E117°15'49.6"
  11. # Google Map: N39°4'26.3" E117°16'13.6"
  12.  
  13. my $version = "090715";
  14. print "cb: calibrate .map file the TrekBuddy_Atlas_Creator_v1.1 generated.\n";
  15. my $bar = "VERSION: $version, vinocui\@gmail.com, twitter.com/vinocui\n";
  16. if ($argc != 5){
  17. print $bar, "\n";
  18. print "Usage:\n";
  19. print " " . __FILE__ . " ActualN ActualE MapN MapE xxx.map\n";
  20. print " " . __FILE__ . " 39D4M21.9 117D15M49.6 39D4M26.3 117D16M13.6 xxx.map\n";
  21. print "39D4M21.9 means 39°4\'21.9\"\n";
  22. print "\nDescriptions:
  23. ActualN: Actual North latitude
  24. ActualE: East longitude
  25. MapN: the North latitude of the right point in your Trekbuddy
  26. MapE: the East latitude of the right point in your Trekbbuddy.\n";
  27.  
  28. exit 1;
  29. }
  30.  
  31. $mapfile = $ARGV[4];
  32. # A: Actual, M: Map. n:North, e: East
  33. # 0,1,2,3 --> AN, AE, MN, ME.
  34. my @D = ();
  35. my @M = ();
  36. my @S = ();
  37.  
  38. for($i = 0; $i < 4; $i++){
  39. my ($d, $a) = split(/D/, $ARGV[$i]);
  40. $D[$i] = $d;
  41. my ($m, $s) = split(/M/, $a);
  42. $M[$i] = $m;
  43. $S[$i] = $s;
  44. print $D[$i] . "°" . $M[$i] . '\'' . $S[$i] . '"'. "\n";
  45. }
  46.  
  47. # A: Actual, M: Map. n:North, e: East
  48. # 0,1,2,3 --> AN, AE, MN, ME.
  49. my $nMcb = ($S[0]/60.0 + $M[0]) - ($S[2]/60.0 + $M[2]);
  50. my $eMcb = ($S[1]/60.0 + $M[1]) - ($S[3]/60.0 + $M[3]);
  51. my $nDcb = ($S[0]/60.0 + $M[0])/60.0 - ($S[2]/60.0 + $M[2])/60.0;
  52. my $eDcb = ($S[1]/60.0 + $M[1])/60.0 - ($S[3]/60.0 + $M[3])/60.0;
  53. print "N: ", $nMcb, "\'\n";
  54. print "E: ", $eMcb, "\'\n";
  55. print "N: ", $nDcb, \n";
  56. print "E: ", $eDcb, \n";
  57.  
  58. open (INFILE, $mapfile ) or die "Could not open file";
  59. open (BACKUPFILE, ">$mapfile.bak" ) or die "Could not open file";
  60. select(BACKUPFILE);
  61. while (my $line = <INFILE>){
  62. print $line;
  63. }
  64. close (BACKUPFILE);
  65. close (INFILE);
  66.  
  67. open (INFILE, "$mapfile.bak" ) or die "Could not open file";
  68. open (OUTFILE, ">$mapfile");
  69. while (my $line = <INFILE>) {
  70. if($line =~ /Point01|Point02|Point03|Point04/g){
  71. my @segs = split(/\,/, $line);
  72. print $segs[7] . "N, " . $segs[10]. "E\n";
  73.  
  74. for(my $i; $i<@segs; $i++){
  75. my $v = 0.0;
  76. if($i == 7){
  77. $segs[$i] = sprintf("%.6f", $segs[$i] + $nMcb);
  78. }elsif($i == 10 ){
  79. $segs[$i] = sprintf("%.6f", $segs[$i] + $eMcb);
  80. }
  81. print OUTFILE $segs[$i];
  82. if($i != (@segs - 1))
  83. {
  84. print OUTFILE ",";
  85. }
  86. }
  87. next;
  88. }
  89.  
  90. if($line =~ /MMPLL/g){
  91. my @segs = split(/\,/, $line);
  92. chomp($segs[3]);
  93. print $segs[2], "E, " . $segs[3] . "N\n";
  94. for(my $i = 0; $i < @segs; $i++){
  95. if ($i == 2){
  96. $segs[$i] = sprintf("%.6f", $segs[$i] + $eDcb);
  97. }elsif($i == 3){
  98. $segs[$i] = sprintf("%.6f", $segs[$i] + $nDcb);
  99. }
  100. print OUTFILE $segs[$i];
  101. if($i != (@segs - 1))
  102. {
  103. print OUTFILE ",";
  104. }else{
  105. print OUTFILE "\n";
  106. }
  107. }
  108. next;
  109. }
  110. print OUTFILE $line;
  111. }
  112. close (INFILE);
  113. close (OUTFILE);

Report this snippet  

You need to login to post a comment.