From 0eb2b6043e5e40ec1f7626dcdfd1dc8db3f6b25b Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 4 Apr 2022 15:15:24 +0100 Subject: [PATCH] [Mapping] calculate midpoint of multi grids for markers --- application/controllers/Dashboard.php | 36 +++++++++++++++++++++++ application/controllers/Logbook.php | 37 +++++++++++++++++++++++ application/libraries/Qra.php | 42 +++++++++++++++++++++++++++ application/views/view_log/qso.php | 28 ++++++++++++++++++ 4 files changed, 143 insertions(+) diff --git a/application/controllers/Dashboard.php b/application/controllers/Dashboard.php index 1c9de36a..09faebd9 100644 --- a/application/controllers/Dashboard.php +++ b/application/controllers/Dashboard.php @@ -121,7 +121,43 @@ class Dashboard extends CI_Controller { } $count++; + }elseif($row->COL_VUCC_GRIDS != null) { + $grids = explode(",", $row->COL_VUCC_GRIDS); + if (count($grids) == 2) { + $grid1 = $this->qra->qra2latlong(trim($grids[0])); + $grid2 = $this->qra->qra2latlong(trim($grids[1])); + + $coords[]=array('lat' => $grid1[0],'lng'=> $grid1[1]); + $coords[]=array('lat' => $grid2[0],'lng'=> $grid2[1]); + + $stn_loc = $this->qra->get_midpoint($coords); + } + if (count($grids) == 4) { + $grid1 = $this->qra->qra2latlong(trim($grids[0])); + $grid2 = $this->qra->qra2latlong(trim($grids[1])); + $grid3 = $this->qra->qra2latlong(trim($grids[2])); + $grid4 = $this->qra->qra2latlong(trim($grids[3])); + + $coords[]=array('lat' => $grid1[0],'lng'=> $grid1[1]); + $coords[]=array('lat' => $grid2[0],'lng'=> $grid2[1]); + $coords[]=array('lat' => $grid3[0],'lng'=> $grid3[1]); + $coords[]=array('lat' => $grid4[0],'lng'=> $grid4[1]); + + $stn_loc = $this->qra->get_midpoint($coords); + } + + if($count != 1) { + echo ","; + } + + if($row->COL_SAT_NAME != null) { + echo "{\"lat\":\"".$stn_loc[0]."\",\"lng\":\"".$stn_loc[1]."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
SAT: ".$row->COL_SAT_NAME."
Mode: ".$row->COL_MODE."\",\"label\":\"".$row->COL_CALL."\"}"; + } else { + echo "{\"lat\":\"".$stn_loc[0]."\",\"lng\":\"".$stn_loc[1]."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
Band: ".$row->COL_BAND."
Mode: ".$row->COL_MODE."\",\"label\":\"".$row->COL_CALL."\"}"; + } + + $count++; } else { $query = $this->db->query(' SELECT * diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 59a6a86e..083c662d 100755 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -375,7 +375,44 @@ class Logbook extends CI_Controller { } $count++; + }elseif($row->COL_VUCC_GRIDS != null) { + $grids = explode(",", $row->COL_VUCC_GRIDS); + if (count($grids) == 2) { + $grid1 = $this->qra->qra2latlong(trim($grids[0])); + $grid2 = $this->qra->qra2latlong(trim($grids[1])); + + $coords[]=array('lat' => $grid1[0],'lng'=> $grid1[1]); + $coords[]=array('lat' => $grid2[0],'lng'=> $grid2[1]); + + $stn_loc = $this->qra->get_midpoint($coords); + } + if (count($grids) == 4) { + $grid1 = $this->qra->qra2latlong(trim($grids[0])); + $grid2 = $this->qra->qra2latlong(trim($grids[1])); + $grid3 = $this->qra->qra2latlong(trim($grids[2])); + $grid4 = $this->qra->qra2latlong(trim($grids[3])); + + $coords[]=array('lat' => $grid1[0],'lng'=> $grid1[1]); + $coords[]=array('lat' => $grid2[0],'lng'=> $grid2[1]); + $coords[]=array('lat' => $grid3[0],'lng'=> $grid3[1]); + $coords[]=array('lat' => $grid4[0],'lng'=> $grid4[1]); + + $stn_loc = $this->qra->get_midpoint($coords); + } + + if($count != 1) { + echo ","; + } + + if($row->COL_SAT_NAME != null) { + echo "{\"lat\":\"".$stn_loc[0]."\",\"lng\":\"".$stn_loc[1]."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
SAT: ".$row->COL_SAT_NAME."
Mode: ".$row->COL_MODE."\",\"label\":\"".$row->COL_CALL."\"}"; + } else { + echo "{\"lat\":\"".$stn_loc[0]."\",\"lng\":\"".$stn_loc[1]."\", \"html\":\"Callsign: ".$row->COL_CALL."
Date/Time: ".$row->COL_TIME_ON."
Band: ".$row->COL_BAND."
Mode: ".$row->COL_MODE."\",\"label\":\"".$row->COL_CALL."\"}"; + } + + $count++; + } else { $query = $this->db->query(' SELECT * diff --git a/application/libraries/Qra.php b/application/libraries/Qra.php index 4147e45c..66fc715c 100644 --- a/application/libraries/Qra.php +++ b/application/libraries/Qra.php @@ -70,6 +70,46 @@ class Qra { $stn = qra2latlong($rx); return get_bearing($my[0], $my[1], $stn[0], $stn[1]); } + + /* + Find the Midpoint between two gridsquares using lat / long + + Needs following passed + + $coords[]=array('lat' => '53.344104','lng'=>'-6.2674937'); + $coords[]=array('lat' => '51.5081289','lng'=>'-0.128005'); + +*/ + +function get_midpoint($coords) +{ + $count_coords = count($coords); + $xcos=0.0; + $ycos=0.0; + $zsin=0.0; + + foreach ($coords as $lnglat) + { + $lat = $lnglat['lat'] * pi() / 180; + $lon = $lnglat['lng'] * pi() / 180; + + $acos = cos($lat) * cos($lon); + $bcos = cos($lat) * sin($lon); + $csin = sin($lat); + $xcos += $acos; + $ycos += $bcos; + $zsin += $csin; + } + + $xcos /= $count_coords; + $ycos /= $count_coords; + $zsin /= $count_coords; + $lon = atan2($ycos, $xcos); + $sqrt = sqrt($xcos * $xcos + $ycos * $ycos); + $lat = atan2($zsin, $sqrt); + + return array($lat * 180 / pi(), $lon * 180 / pi()); +} } function distance($lat1, $lon1, $lat2, $lon2, $unit = 'M') { @@ -158,4 +198,6 @@ function qra2latlong($strQRA) { return array(0, 0); } } + + /* End of file Qra.php */ diff --git a/application/views/view_log/qso.php b/application/views/view_log/qso.php index 673d4fa1..4f923bbf 100644 --- a/application/views/view_log/qso.php +++ b/application/views/view_log/qso.php @@ -434,6 +434,34 @@ $lat = $stn_loc[0]; $lng = $stn_loc[1]; } + } elseif($row->COL_VUCC_GRIDS != null) { + $grids = explode(",", $row->COL_VUCC_GRIDS); + if (count($grids) == 2) { + $grid1 = $this->qra->qra2latlong(trim($grids[0])); + $grid2 = $this->qra->qra2latlong(trim($grids[1])); + + $coords[]=array('lat' => $grid1[0],'lng'=> $grid1[1]); + $coords[]=array('lat' => $grid2[0],'lng'=> $grid2[1]); + + $midpoint = $this->qra->get_midpoint($coords); + $lat = $midpoint[0]; + $lng = $midpoint[1]; + } + if (count($grids) == 4) { + $grid1 = $this->qra->qra2latlong(trim($grids[0])); + $grid2 = $this->qra->qra2latlong(trim($grids[1])); + $grid3 = $this->qra->qra2latlong(trim($grids[2])); + $grid4 = $this->qra->qra2latlong(trim($grids[3])); + + $coords[]=array('lat' => $grid1[0],'lng'=> $grid1[1]); + $coords[]=array('lat' => $grid2[0],'lng'=> $grid2[1]); + $coords[]=array('lat' => $grid3[0],'lng'=> $grid3[1]); + $coords[]=array('lat' => $grid4[0],'lng'=> $grid4[1]); + + $midpoint = $this->qra->get_midpoint($coords); + $lat = $midpoint[0]; + $lng = $midpoint[1]; + } } else { $CI =& get_instance();