function XPlane() { Waypoint::truncate(); $handle = fopen($this->option('xplane') . '/earth_fix.dat', 'r'); $skip = 0; $chunksOrig = 250; $total = 0; $chunks = $chunksOrig; $list = array(); while ($line = fgets($handle)) { if ($skip < 3) { $skip++; continue; } $line = explode(' ', trim(preg_replace('/\\s+/', ' ', $line))); if (count($line) < 3) { continue; } list($lat, $lon, $name) = $line; $name = trim($name); $list[] = array('ident' => $name, 'lat' => $lat, 'lon' => $lon, 'type' => 'F'); if ($total == $chunks) { Waypoint::insert($list); $this->line('Inserted batch (' . $chunks . ')'); $list = array(); $chunks += $chunksOrig; } $total++; } Waypoint::insert($list); $this->line('Inserted batch (' . $chunks . ')'); $this->line('Loaded fixes: ' . $total); fclose($handle); $handle = fopen($this->option('xplane') . '/earth_nav.dat', 'r'); $skip = 0; $chunksOrig = 250; $total = 0; $chunks = $chunksOrig; $list = array(); while ($line = fgets($handle)) { if ($skip < 3) { $skip++; continue; } $line = explode(' ', trim(preg_replace('/\\s+/', ' ', $line))); if (count($line) < 3) { continue; } list($type, $lat, $lon, , $freq, , , $ident) = $line; $name = ucwords(strtolower(implode(' ', array_slice($line, 8, -1)))); if (!in_array($type, [2, 3])) { continue; } $this->navs[$ident][] = $new[] = array('ident' => $ident, 'name' => $name, 'lat' => $lat, 'lon' => $lon, 'freq' => $freq, 'type' => $type == 2 ? 'N' : 'V'); if ($total == $chunks) { Waypoint::insert($list); $this->line('Inserted batch (' . $chunks . ')'); $list = array(); $chunks += $chunksOrig; } $total++; } Waypoint::insert($list); $this->line('Inserted batch (' . $chunks . ')'); $this->line('Loaded VOR and NDB: ' . $total); fclose($handle); }
protected function getNavDetails($navpoints) { if (is_array($navpoints) && count($navpoints) > 0) { $in_clause = array(); foreach ($navpoints as $point) { if (is_array($point) || is_object($point)) { continue; } $in_clause[] = $point; } } else { $in_clause = explode(' ', $navpoints); } return Waypoint::whereIn('ident', $in_clause)->get()->groupBy('ident'); if (!$results) { return array(); } $return_results = array(); foreach ($results as $key => $point) { if (empty($point->name)) { $point->name = $point->ident; } $return_results[$point->ident][] = $point; } return $return_results; }