trim gridlocator before parsing it. Some Exports consist of trailing whitespaces at gridlocator :(
这个提交包含在:
父节点
1d8a040a0b
当前提交
e9af164c8a
共有 1 个文件被更改,包括 68 次插入 和 67 次删除
|
|
@ -173,78 +173,79 @@ function get_bearing($lat1, $lon1, $lat2, $lon2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function qra2latlong($strQRA) {
|
function qra2latlong($strQRA) {
|
||||||
if (substr_count($strQRA, ',') > 0) {
|
$strQRA=trim($strQRA);
|
||||||
if (substr_count($strQRA, ',') == 3) {
|
if (substr_count($strQRA, ',') > 0) {
|
||||||
// Handle grid corners
|
if (substr_count($strQRA, ',') == 3) {
|
||||||
$grids = explode(',', $strQRA);
|
// Handle grid corners
|
||||||
$gridlengths = array(strlen($grids[0]), strlen($grids[1]), strlen($grids[2]), strlen($grids[3]));
|
$grids = explode(',', $strQRA);
|
||||||
$same = array_count_values($gridlengths);
|
$gridlengths = array(strlen($grids[0]), strlen($grids[1]), strlen($grids[2]), strlen($grids[3]));
|
||||||
if (count($same) != 1) {
|
$same = array_count_values($gridlengths);
|
||||||
return false;
|
if (count($same) != 1) {
|
||||||
}
|
return false;
|
||||||
$coords = array(0, 0);
|
}
|
||||||
for($i=0; $i<4; $i++) {
|
$coords = array(0, 0);
|
||||||
$cornercoords[$i] = qra2latlong($grids[$i]);
|
for($i=0; $i<4; $i++) {
|
||||||
$coords[0] += $cornercoords[$i][0];
|
$cornercoords[$i] = qra2latlong($grids[$i]);
|
||||||
$coords[1] += $cornercoords[$i][1];
|
$coords[0] += $cornercoords[$i][0];
|
||||||
}
|
$coords[1] += $cornercoords[$i][1];
|
||||||
return array (round($coords[0]/4), round($coords[1]/4));
|
}
|
||||||
} else if (substr_count($strQRA, ',') == 1) {
|
return array (round($coords[0]/4), round($coords[1]/4));
|
||||||
// Handle grid lines
|
} else if (substr_count($strQRA, ',') == 1) {
|
||||||
$grids = explode(',', $strQRA);
|
// Handle grid lines
|
||||||
if (strlen($grids[0]) != strlen($grids[1])) {
|
$grids = explode(',', $strQRA);
|
||||||
return false;
|
if (strlen($grids[0]) != strlen($grids[1])) {
|
||||||
}
|
return false;
|
||||||
$coords = array(0, 0);
|
}
|
||||||
for($i=0; $i<2; $i++) {
|
$coords = array(0, 0);
|
||||||
$linecoords[$i] = qra2latlong($grids[$i]);
|
for($i=0; $i<2; $i++) {
|
||||||
}
|
$linecoords[$i] = qra2latlong($grids[$i]);
|
||||||
if ($linecoords[0][0] != $linecoords[1][0]) {
|
}
|
||||||
$coords[0] = round((($linecoords[0][0] + $linecoords[1][0]) / 2),1);
|
if ($linecoords[0][0] != $linecoords[1][0]) {
|
||||||
} else {
|
$coords[0] = round((($linecoords[0][0] + $linecoords[1][0]) / 2),1);
|
||||||
$coords[0] = round($linecoords[0][0],1);
|
} else {
|
||||||
}
|
$coords[0] = round($linecoords[0][0],1);
|
||||||
if ($linecoords[0][1] != $linecoords[1][1]) {
|
}
|
||||||
$coords[1] = round(($linecoords[0][1] + $linecoords[1][1]) / 2);
|
if ($linecoords[0][1] != $linecoords[1][1]) {
|
||||||
} else {
|
$coords[1] = round(($linecoords[0][1] + $linecoords[1][1]) / 2);
|
||||||
$coords[1] = round($linecoords[0][1]);
|
} else {
|
||||||
}
|
$coords[1] = round($linecoords[0][1]);
|
||||||
return $coords;
|
}
|
||||||
} else {
|
return $coords;
|
||||||
return false;
|
} else {
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((strlen($strQRA) % 2 == 0) && (strlen($strQRA) <= 10)) { // Check if QRA is EVEN (the % 2 does that) and smaller/equal 8
|
if ((strlen($strQRA) % 2 == 0) && (strlen($strQRA) <= 10)) { // Check if QRA is EVEN (the % 2 does that) and smaller/equal 8
|
||||||
$strQRA = strtoupper($strQRA);
|
$strQRA = strtoupper($strQRA);
|
||||||
if (strlen($strQRA) == 4) $strQRA .= "LL"; // Only 4 Chars? Fill with center "LL" as only A-R allowed
|
if (strlen($strQRA) == 4) $strQRA .= "LL"; // Only 4 Chars? Fill with center "LL" as only A-R allowed
|
||||||
if (strlen($strQRA) == 6) $strQRA .= "55"; // Only 6 Chars? Fill with center "55"
|
if (strlen($strQRA) == 6) $strQRA .= "55"; // Only 6 Chars? Fill with center "55"
|
||||||
if (strlen($strQRA) == 8) $strQRA .= "LL"; // Only 8 Chars? Fill with center "LL" as only A-R allowed
|
if (strlen($strQRA) == 8) $strQRA .= "LL"; // Only 8 Chars? Fill with center "LL" as only A-R allowed
|
||||||
|
|
||||||
if (!preg_match('/^[A-R]{2}[0-9]{2}[A-X]{2}[0-9]{2}[A-X]{2}$/', $strQRA)) {
|
if (!preg_match('/^[A-R]{2}[0-9]{2}[A-X]{2}[0-9]{2}[A-X]{2}$/', $strQRA)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
list($a, $b, $c, $d, $e, $f, $g, $h, $i, $j) = str_split($strQRA, 1); // Maidenhead is always alternating. e.g. "AA00AA00AA00" - doesn't matter how deep. 2 chars, 2 numbers, etc.
|
list($a, $b, $c, $d, $e, $f, $g, $h, $i, $j) = str_split($strQRA, 1); // Maidenhead is always alternating. e.g. "AA00AA00AA00" - doesn't matter how deep. 2 chars, 2 numbers, etc.
|
||||||
$a = ord($a) - ord('A');
|
$a = ord($a) - ord('A');
|
||||||
$b = ord($b) - ord('A');
|
$b = ord($b) - ord('A');
|
||||||
$c = ord($c) - ord('0');
|
$c = ord($c) - ord('0');
|
||||||
$d = ord($d) - ord('0');
|
$d = ord($d) - ord('0');
|
||||||
$e = ord($e) - ord('A');
|
$e = ord($e) - ord('A');
|
||||||
$f = ord($f) - ord('A');
|
$f = ord($f) - ord('A');
|
||||||
$g = ord($g) - ord('0');
|
$g = ord($g) - ord('0');
|
||||||
$h = ord($h) - ord('0');
|
$h = ord($h) - ord('0');
|
||||||
$i = ord($i) - ord('A');
|
$i = ord($i) - ord('A');
|
||||||
$j = ord($j) - ord('A');
|
$j = ord($j) - ord('A');
|
||||||
|
|
||||||
$nLong = ($a*20) + ($c*2) + ($e/12) + ($g/120) + ($i/2880) - 180;
|
$nLong = ($a*20) + ($c*2) + ($e/12) + ($g/120) + ($i/2880) - 180;
|
||||||
$nLat = ($b*10) + $d + ($f/24) + ($h/240) + ($j/5760) - 90;
|
$nLat = ($b*10) + $d + ($f/24) + ($h/240) + ($j/5760) - 90;
|
||||||
|
|
||||||
$arLatLong = array($nLat, $nLong);
|
$arLatLong = array($nLat, $nLong);
|
||||||
return $arLatLong;
|
return $arLatLong;
|
||||||
} else {
|
} else {
|
||||||
return array(0, 0);
|
return array(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
正在加载…
在新工单中引用