forked from GlidingWeb/IGCWebView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetairspace.php
107 lines (103 loc) · 2.76 KB
/
getairspace.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
function getpolygons($whereclause) {
global $mysqli;
$polygons=array();
$polylist = $mysqli->query("SELECT base,AsText(outline) FROM geopoly WHERE $whereclause");
while($polygon=$polylist->fetch_row())
{
$reduced=str_replace(")","",str_replace("LINESTRING(","",str_replace(")LINESTRING(",",",$polygon[1])));
$pointlist=explode(",",$reduced);
unset($coordlist);
foreach($pointlist as $point) {
$splitpoint= explode(" ",$point);
$coords['lat']=$splitpoint[0];
$coords['lng']=$splitpoint[1];
$coordlist[]=$coords;
}
$polygons[]=( object)array("base"=>$polygon[0],"coords"=>$coordlist);
}
$polylist->close();
return $polygons;
}
function getcircles($whereclause) {
global $mysqli;
$circlelist = $mysqli->query("SELECT base,AsText(centre),radius FROM geocircle WHERE $whereclause");
$circles=array();
while($circle=$circlelist->fetch_row()) {
$reduced=str_replace(")","",str_replace("POINT(","",$circle[1]));
$splitpoint=explode(" ",$reduced);
$centre['lat']=$splitpoint[0];
$centre['lng']=$splitpoint[1];
$circles[]=( object)array("base"=>$circle[0],"centre"=>$centre,"radius"=>$circle[2]);
}
return $circles;
}
$countries=array(
'AUT'=>'at',
'AUS'=>'au',
'BEL'=>'be',
'BRA'=>'br',
'CAN'=>'ca',
'CHE'=>'ch',
'CZE'=>'cz',
'DEU'=>'de',
'EST'=>'ee',
'ESP'=>'es',
'FIN'=>'fi',
'FRA'=>'fr',
'HRV'=>'hr',
'HUN'=>'hu',
'IRL'=>'ie',
'ITA'=>'it',
'LTU'=>'lt',
'LVA'=>'lv',
'MKD'=>'mk',
'NLD'=>'nl',
'NOR'=>'no',
'NZL'=>'nz',
'POL'=>'pl',
'PRT'=>'pt',
'SWE'=>'se',
'SVN'=>'si',
'SVK'=>'sk',
'GBR'=>'uk',
'USA'=>'us',
'ZAF'=>'za',
);
$degdist = 111; // km- circumference of the earth divided by 360
require_once("../db_inc.php");
$mysqli=new mysqli($dbserver,$username,$password,$database);
//find box approx 555 Km from start pt each way
$north=$_POST['lat'] + 5;
if($north > 90) {
$north=90;
}
$south=$_POST['lat'] - 5;
if($south < -90) {
$south=-90;
}
$latcorr=cos(deg2rad($_POST['lat']));
if($latcorr > 0) { //in case file error gives takeoff at a pole
$east= $_POST['lng'] + 5/$latcorr;
if($east > 180) {
$east= 360-$east;
}
$west= $_POST['lng'] - 5/$latcorr;
if($west < -180) {
$west= 360 + $west;
}
}
else {
$east=180;
$west=-180;
}
$box="POLYGON(($north $west,$north $east,$south $east,$south $west,$north $west))";
$sql="SET @bbox=GeomFromText('".$box."')";
$mysqli->query($sql);
$wherepolygons="INTERSECTS(outline,@bbox)";
$wherecircles="INTERSECTS(mbr,@bbox)";
$retval['polygons']=getpolygons($wherepolygons);
$retval['circles']=getcircles($wherecircles);
echo json_encode($retval,JSON_NUMERIC_CHECK);
$mysqli->close();
?>