Handle VUCC grid lines and corners in Qrb mapping

This commit is contained in:
phl0 2023-08-23 14:22:20 +02:00
parent 23dc7005d9
commit 77edb72d2c
No known key found for this signature in database
GPG Key ID: 48EA1E640798CA9A
2 changed files with 31 additions and 19 deletions

View File

@ -23,12 +23,6 @@ class Qra {
// calculate the bearing between two squares // calculate the bearing between two squares
function bearing($tx, $rx, $unit = 'M') { function bearing($tx, $rx, $unit = 'M') {
if(strlen($tx) > 6) {
$tx = substr($tx, 0, 6);
}
if(strlen($rx) > 6) {
$rx = substr($rx, 0, 6);
}
$my = qra2latlong($tx); $my = qra2latlong($tx);
$stn = qra2latlong($rx); $stn = qra2latlong($rx);
@ -44,12 +38,6 @@ class Qra {
* *
*/ */
function distance($tx, $rx, $unit = 'M') { function distance($tx, $rx, $unit = 'M') {
if(strlen($tx) > 6) {
$tx = substr($tx, 0, 6);
}
if(strlen($rx) > 6) {
$rx = substr($rx, 0, 6);
}
// Calc LatLongs // Calc LatLongs
$my = qra2latlong($tx); $my = qra2latlong($tx);
$stn = qra2latlong($rx); $stn = qra2latlong($rx);
@ -176,9 +164,34 @@ function get_bearing($lat1, $lon1, $lat2, $lon2) {
} }
function qra2latlong($strQRA) { function qra2latlong($strQRA) {
if (strpos($strQRA, ',') !== false) { if (substr_count($strQRA, ',') == 3) {
$gridsquareArray = explode(',', $strQRA); // Handle grid corners
$strQRA = $gridsquareArray[0]; $grids = explode(',', $strQRA);
$coords = array(0, 0);
for($i=0; $i<4; $i++) {
$cornercoords[$i] = qra2latlong($grids[$i]);
$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) {
// Handle grid lines
$grids = explode(',', $strQRA);
$coords = array(0, 0);
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);
} 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);
} else {
$coords[1] = round($linecoords[0][1]);
}
return $coords;
} }
if ((strlen($strQRA) % 2 == 0) && (strlen($strQRA) <= 8)) { // Check if QRA is EVEN (the % 2 does that) and smaller/equal 8 if ((strlen($strQRA) % 2 == 0) && (strlen($strQRA) <= 8)) { // Check if QRA is EVEN (the % 2 does that) and smaller/equal 8
@ -200,7 +213,6 @@ function qra2latlong($strQRA) {
$g = ord($g) - ord('0'); $g = ord($g) - ord('0');
$h = ord($h) - ord('0'); $h = ord($h) - ord('0');
$nLong = ($a*20) + ($c*2) + (($e+0.5)/12) + (($g-5)/120) - 180; // the 4th pair is "in the middle", so we've to substract 5 $nLong = ($a*20) + ($c*2) + (($e+0.5)/12) + (($g-5)/120) - 180; // the 4th pair is "in the middle", so we've to substract 5
$nLat = ($b*10) + $d + (($f+0.5)/24) + (($h-5)/240) - 90; $nLat = ($b*10) + $d + (($f+0.5)/24) + (($h-5)/240) - 90;

View File

@ -345,13 +345,13 @@ function calculateQrb() {
data: {'locator1': locator1, data: {'locator1': locator1,
'locator2': locator2}, 'locator2': locator2},
success: function (html) { success: function (html) {
var result = "<h5>Negative latitudes are south of the equator, negative longitudes are west of Greenwich. <br/>"; var result = "<h5>Negative latitudes are south of the equator, negative longitudes are west of Greenwich. <br/>";
result += ' ' + locator1.toUpperCase() + ' Latitude = ' + html['latlng1'][0] + ' Longitude = ' + html['latlng1'][1] + '<br/>'; result += ' ' + locator1.toUpperCase() + ' Latitude = ' + html['latlng1'][0] + ' Longitude = ' + html['latlng1'][1] + '<br/>';
result += ' ' + locator2.toUpperCase() + ' Latitude = ' + html['latlng2'][0] + ' Longitude = ' + html['latlng2'][1] + '<br/>'; result += ' ' + locator2.toUpperCase() + ' Latitude = ' + html['latlng2'][0] + ' Longitude = ' + html['latlng2'][1] + '<br/>';
result += 'Distance between ' + locator1.toUpperCase() + ' and ' + locator2.toUpperCase() + ' is ' + html['distance'] + '.<br />'; result += 'Distance between ' + locator1.toUpperCase() + ' and ' + locator2.toUpperCase() + ' is ' + html['distance'] + '.<br />';
result += 'The bearing is ' + html['bearing'] + '.</h5>'; result += 'The bearing is ' + html['bearing'] + '.</h5>';
$(".qrbResult").html(result); $(".qrbResult").html(result);
newpath(html['latlng1'], html['latlng2'], locator1, locator2); newpath(html['latlng1'], html['latlng2'], locator1, locator2);
} }
@ -365,7 +365,7 @@ function validateLocator(locator) {
if(locator.length < 4 && !(/^[a-rA-R]{2}[0-9]{2}[a-xA-X]{0,2}[0-9]{0,2}[a-xA-X]{0,2}$/.test(locator))) { if(locator.length < 4 && !(/^[a-rA-R]{2}[0-9]{2}[a-xA-X]{0,2}[0-9]{0,2}[a-xA-X]{0,2}$/.test(locator))) {
return false; return false;
} }
return true; return true;
} }