class fix {
public $fix;
public $name;
public $lat;
public $lon;
public function __construct($fixstr,$fh = null){
$this->fix = strtoupper(trim($fixstr));
$returnData = $this->getFromCifp($this->fix,$fh);
$this->lat = $returnData[0];
$this->lon = $returnData[1];
$this->name = $returnData[2];
// 93:123
}
public function lonLatJsArrayString(){
$lat = $this->lat;
$lon = $this->lon;
return "[$lon , $lat ]";
}
public function lonLatNoComma(){
return $this->lon . " " . $this->lat;
}
public function latLonNoComma(){
return $this->lat . " " . $this->lon;
}
public function lonLatArray(){
return array($this->lon,$this->lat);
}
public function returnAssocArray(){
return array("fix"=>$this->fix,
"lat"=>$this->lat,
"lon"=>$this->lon,
"name"=>$this->name);
}
public function getFromCifp($name,$fh){
if(is_null($fh)) $fh = fopen('./cifp','r');
fseek($fh,0);
return $this->masterGetFixAirport($fh,$name);
}
public function masterGetFixAirport($fh,$fix){
fseek($fh,0);
$a = $this->getAirportLatLon($fh,$fix);
if(!$a){
fseek($fh,0);
$a = $this->getFixLatLon($fh,$fix);
// return $a;
}
// echo "fixdebug >> $fix --is-- $a";
$name = $a[1];
$a = $this->parseLatLonToDec($a[0]);
$a[2] = $name;
return $a;
}
public function parseLatLonToDec($str){
$lat = parseMinSecToDec(substr($str,0,9));
$lon = parseMinSecToDec(substr($str,9));
return [$lat,$lon];
}
public function parseMinSecToDec($str){
$direction = $str[0];
if($direction == "E" || $direction == "W") $deg = (float) substr($str,1,3);
else $deg = (float) substr($str,1,2);
$min = (float) substr($str,-6,2);
$sec = ( (float) substr($str,-4,4)) * .01;
$secdec = $sec / 3600;
$mindec = $min / 60;
$degdec = $deg + $mindec + $secdec;
if($direction == "S" || $direction == "W") return $degdec * -1;
else return $degdec;
}
function getAirportLatLon($fh,$ap){
$apshort = $ap;
if($apshort[0]== 'K' && strlen($apshort) == 4){
$apshort = substr($apshort,1);
}
elseif($apshort[0] != 'K' && strlen($apshort) == 4){
$apshort = "";
}
while( ($line = fgets($fh)) != null ){
if(trim(substr($line,6,4)) == $ap && trim(substr($line,13,3)) == $apshort ){
return [trim(substr($line,32,19)),trim(substr($line,93,30))];
}
}
return null;
}
function getFixLatLon($fh,$fix){
// reset($fh);
// echo "hi";
while( ($line = fgets($fh)) != null ){
if(trim(substr($line,13,5)) == $fix){
$fixname = "";
if(strlen($fix) == 3) {
$fixname = trim(substr($line,93,30));
$fixtype = substr($line,27,2);
if($fixtype == "VT") $fixname .= " VORTAC";
elseif($fixtype == "VD") $fixname .= " VOR-DME";
elseif($fixtype == "V ") $fixname .= " VOR";
}
return [trim(substr($line,32,19)),$fixname];
} else{
// echo trim(substr($line,13,5)) . "
\n";
}
// echo "hi";
}
return "None";
}
} //fix class
class RouteString{
private $JsRouteArrayString;
private $sqlRouteString;
public function __construct($fixobjar){
$jsRouteStringArray = "[";
$mysqlRouteString = "";
$length = sizeof($fixobjar) - 1;
$counter = 0;
foreach($fixobjar as $fix){
$mysqlRouteString .= $fix->latLonNoComma();
$jsRouteStringArray .= $fix->lonLatJsArrayString();
if($length != $counter) {
$mysqlRouteString .= " , ";
$jsRouteStringArray .= " , ";
}
$counter++;
}
$this->jsRouteArrayString = $jsRouteStringArray . "]";
$this->sqlRouteString = $mysqlRouteString;
}
public function getRouteString(){
return $this->jsRouteArrayString;
}
public function getSqlRouteString(){
return $this->sqlRouteString;
}
}
$routeLineString = "";
$htmlFixSection = "";
if(isset($_GET['route']) && $_GET['route'] != ""){
$thisroute = preg_replace('/\s\s+/', ' ', $_GET['route']);
$fixobjar = array();
$routesplit = explode(' ',trim($thisroute));
foreach($routesplit as $a){
$thisfix = new fix($a);
if($thisfix != null) $fixobjar[] = $thisfix;
}
$routeStringObj = new RouteString($fixobjar);
$routeLineString = $routeStringObj->getRouteString();
$sqlRouteString = $routeStringObj->getSqlRouteString();
$where = "where ST_intersects(Geomfromtext('LINESTRING($sqlRouteString)',4326), airspace.areapoly )";
// echo "** $sqlRouteString **
\n";
$sql = "select * from airspace $where";
$starttime = microtime(true);
$stmt = $dbh->query($sql);
$endtime = microtime(true);
$totaltime = $endtime - $starttime;
$totaltime = $totaltime * 1000;
echo "
";
reset($fixobjar);
foreach($fixobjar as $fix){
$flat = $fix->lat;
$flon = $fix->lon;
$ffix = $fix->fix;
$fname = $fix->name;
echo "
| $ffix |
$fname |
$flat $flon |
";
}
// echo "
// | $fix1 |
// $fix2 |
//
//
// | $fix1lat $fix1lon |
// $fix2lat $fix2lon |
//
";
echo "
\n";
// echo "\n
$fix1 -> $fix2
$fix1lat $fix1lon -> $fix2lat $fix2lon
";
echo "
row count: " . $stmt->rowCount() . " --- took $totaltime ms
";
echo "
\n";
foreach($stmt as $a){
$facid = $a['facilityid'];
$secid = $a['sectionid'];
$altbtm = $a['altitudebottom'];
$alttop = $a['altitudetop'];
$rowid = $a['id'];
// echo "\n
$facid > $secid >>> $altbtm - $alttop";
echo "| $facid | $secid | $altbtm - $alttop |
";
}
echo "\n
";
// $fixobjarray = new fix(trim())
}
if(isset($_GET['fix1']) && $_GET['route'] == ""){
$fh = fopen('./cifp','r');
// $route = strtoupper($_GET['route']);
// $route = str_split(' ',$route);
$fix1 = strtoupper($_GET['fix1']);
$fix2 = strtoupper($_GET['fix2']);
$fix1a = masterGetFixAirport($fh,$fix1);
$fix2a = masterGetFixAirport($fh,$fix2);
// echo "lat: " . $fixa[0] . " --- lon: " . $fixa[1] . "
\n";
$fix1lat = (string)$fix1a[0];
$fix1lon = (string)$fix1a[1];
$fix2lat = (string)$fix2a[0];
$fix2lon = (string)$fix2a[1];
$linestring = "$fix1lat $fix1lon , $fix2lat $fix2lon";
// echo "** $linestring **
\n";
$where = "where ST_intersects(Geomfromtext('LINESTRING($linestring)',4326), airspace.areapoly )";
$sql = "select * from airspace $where";
// Geomfromtext('LINESTRING(40.2395555556 -75.5567222222 , 40.1931916667 -76.7626194444)',4326) )
$starttime = microtime(true);
$stmt = $dbh->query($sql);
$endtime = microtime(true);
$totaltime = $endtime - $starttime;
$totaltime = $totaltime * 1000;
echo "
| $fix1 |
$fix2 |
| $fix1lat $fix1lon |
$fix2lat $fix2lon |
\n";
// echo "\n
$fix1 -> $fix2
$fix1lat $fix1lon -> $fix2lat $fix2lon
";
echo "
row count: " . $stmt->rowCount() . " --- took $totaltime ms
";
echo "
| Facility | Section | Altitudes |
\n";
foreach($stmt as $a){
$facid = $a['facilityid'];
$secid = $a['sectionid'];
$altbtm = $a['altitudebottom'];
$alttop = $a['altitudetop'];
// echo "\n
$facid > $secid >>> $altbtm - $alttop";
echo "| $facid | $secid | $altbtm - $alttop |
";
}
echo "\n
";
}
$airportListToDisplayText = explode(' ', $airportListToDisplayText);
foreach($airportListToDisplayText as $ap){
$fix = new fix($ap);
$airportListToDisplayArray[] = $fix->returnAssocArray();
}
?>