Tool for calibrate latitude & longitude for OZI map file


/ Published in: Perl
Save to your folder(s)

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


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.