Completed
Push — master ( e17801...597a61 )
by Yannick
25:55
created
require/libs/geoPHP/lib/geometry/LineString.class.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -19,173 +19,173 @@
 block discarded – undo
19 19
       throw new Exception("Cannot construct a LineString with a single point");
20 20
     }
21 21
 */
22
-    // Call the Collection constructor to build the LineString
23
-    parent::__construct($points);
22
+	// Call the Collection constructor to build the LineString
23
+	parent::__construct($points);
24 24
   }
25 25
 
26 26
   // The boundary of a linestring is itself
27 27
   public function boundary() {
28
-    return $this;
28
+	return $this;
29 29
   }
30 30
 
31 31
   public function startPoint() {
32
-    return $this->pointN(1);
32
+	return $this->pointN(1);
33 33
   }
34 34
 
35 35
   public function endPoint() {
36
-    $last_n = $this->numPoints();
37
-    return $this->pointN($last_n);
36
+	$last_n = $this->numPoints();
37
+	return $this->pointN($last_n);
38 38
   }
39 39
 
40 40
   public function isClosed() {
41
-    return ($this->startPoint()->equals($this->endPoint()));
41
+	return ($this->startPoint()->equals($this->endPoint()));
42 42
   }
43 43
 
44 44
   public function isRing() {
45
-    return ($this->isClosed() && $this->isSimple());
45
+	return ($this->isClosed() && $this->isSimple());
46 46
   }
47 47
 
48 48
   public function numPoints() {
49
-    return $this->numGeometries();
49
+	return $this->numGeometries();
50 50
   }
51 51
 
52 52
   public function pointN($n) {
53
-    return $this->geometryN($n);
53
+	return $this->geometryN($n);
54 54
   }
55 55
 
56 56
   public function dimension() {
57
-    if ($this->isEmpty()) return 0;
58
-    return 1;
57
+	if ($this->isEmpty()) return 0;
58
+	return 1;
59 59
   }
60 60
 
61 61
   public function area() {
62
-    return 0;
62
+	return 0;
63 63
   }
64 64
 
65 65
   public function length() {
66
-    if ($this->geos()) {
67
-      return $this->geos()->length();
68
-    }
69
-    $length = 0;
70
-    foreach ($this->getPoints() as $delta => $point) {
71
-      $previous_point = $this->geometryN($delta);
72
-      if ($previous_point) {
73
-        $length += sqrt(pow(($previous_point->getX() - $point->getX()), 2) + pow(($previous_point->getY()- $point->getY()), 2));
74
-      }
75
-    }
76
-    return $length;
66
+	if ($this->geos()) {
67
+	  return $this->geos()->length();
68
+	}
69
+	$length = 0;
70
+	foreach ($this->getPoints() as $delta => $point) {
71
+	  $previous_point = $this->geometryN($delta);
72
+	  if ($previous_point) {
73
+		$length += sqrt(pow(($previous_point->getX() - $point->getX()), 2) + pow(($previous_point->getY()- $point->getY()), 2));
74
+	  }
75
+	}
76
+	return $length;
77 77
   }
78 78
 
79 79
   public function greatCircleLength($radius = 6378137) {
80
-    $length = 0;
81
-    $points = $this->getPoints();
82
-    for($i=0; $i<$this->numPoints()-1; $i++) {
83
-      $point = $points[$i];
84
-      $next_point = $points[$i+1];
85
-      if (!is_object($next_point)) {continue;}
86
-      // Great circle method
87
-      $lat1 = deg2rad($point->getY());
88
-      $lat2 = deg2rad($next_point->getY());
89
-      $lon1 = deg2rad($point->getX());
90
-      $lon2 = deg2rad($next_point->getX());
91
-      $dlon = $lon2 - $lon1;
92
-      $length +=
93
-        $radius *
94
-          atan2(
95
-            sqrt(
96
-              pow(cos($lat2) * sin($dlon), 2) +
97
-                pow(cos($lat1) * sin($lat2) - sin($lat1) * cos($lat2) * cos($dlon), 2)
98
-            )
99
-            ,
100
-            sin($lat1) * sin($lat2) +
101
-              cos($lat1) * cos($lat2) * cos($dlon)
102
-          );
103
-    }
104
-    // Returns length in meters.
105
-    return $length;
80
+	$length = 0;
81
+	$points = $this->getPoints();
82
+	for($i=0; $i<$this->numPoints()-1; $i++) {
83
+	  $point = $points[$i];
84
+	  $next_point = $points[$i+1];
85
+	  if (!is_object($next_point)) {continue;}
86
+	  // Great circle method
87
+	  $lat1 = deg2rad($point->getY());
88
+	  $lat2 = deg2rad($next_point->getY());
89
+	  $lon1 = deg2rad($point->getX());
90
+	  $lon2 = deg2rad($next_point->getX());
91
+	  $dlon = $lon2 - $lon1;
92
+	  $length +=
93
+		$radius *
94
+		  atan2(
95
+			sqrt(
96
+			  pow(cos($lat2) * sin($dlon), 2) +
97
+				pow(cos($lat1) * sin($lat2) - sin($lat1) * cos($lat2) * cos($dlon), 2)
98
+			)
99
+			,
100
+			sin($lat1) * sin($lat2) +
101
+			  cos($lat1) * cos($lat2) * cos($dlon)
102
+		  );
103
+	}
104
+	// Returns length in meters.
105
+	return $length;
106 106
   }
107 107
 
108 108
   public function haversineLength() {
109
-    $degrees = 0;
110
-    $points = $this->getPoints();
111
-    for($i=0; $i<$this->numPoints()-1; $i++) {
112
-      $point = $points[$i];
113
-      $next_point = $points[$i+1];
114
-      if (!is_object($next_point)) {continue;}
115
-      $degree = rad2deg(
116
-        acos(
117
-          sin(deg2rad($point->getY())) * sin(deg2rad($next_point->getY())) +
118
-            cos(deg2rad($point->getY())) * cos(deg2rad($next_point->getY())) *
119
-              cos(deg2rad(abs($point->getX() - $next_point->getX())))
120
-        )
121
-      );
122
-      $degrees += $degree;
123
-    }
124
-    // Returns degrees
125
-    return $degrees;
109
+	$degrees = 0;
110
+	$points = $this->getPoints();
111
+	for($i=0; $i<$this->numPoints()-1; $i++) {
112
+	  $point = $points[$i];
113
+	  $next_point = $points[$i+1];
114
+	  if (!is_object($next_point)) {continue;}
115
+	  $degree = rad2deg(
116
+		acos(
117
+		  sin(deg2rad($point->getY())) * sin(deg2rad($next_point->getY())) +
118
+			cos(deg2rad($point->getY())) * cos(deg2rad($next_point->getY())) *
119
+			  cos(deg2rad(abs($point->getX() - $next_point->getX())))
120
+		)
121
+	  );
122
+	  $degrees += $degree;
123
+	}
124
+	// Returns degrees
125
+	return $degrees;
126 126
   }
127 127
 
128 128
   public function explode() {
129
-    $parts = array();
130
-    $points = $this->getPoints();
129
+	$parts = array();
130
+	$points = $this->getPoints();
131 131
 
132
-    foreach ($points as $i => $point) {
133
-      if (isset($points[$i+1])) {
134
-        $parts[] = new LineString(array($point, $points[$i+1]));
135
-      }
136
-    }
137
-    return $parts;
132
+	foreach ($points as $i => $point) {
133
+	  if (isset($points[$i+1])) {
134
+		$parts[] = new LineString(array($point, $points[$i+1]));
135
+	  }
136
+	}
137
+	return $parts;
138 138
   }
139 139
 
140 140
   public function isSimple() {
141
-    if ($this->geos()) {
142
-      return $this->geos()->isSimple();
143
-    }
141
+	if ($this->geos()) {
142
+	  return $this->geos()->isSimple();
143
+	}
144 144
 
145
-    $segments = $this->explode();
145
+	$segments = $this->explode();
146 146
 
147
-    foreach ($segments as $i => $segment) {
148
-      foreach ($segments as $j => $check_segment) {
149
-        if ($i != $j) {
150
-          if ($segment->lineSegmentIntersect($check_segment)) {
151
-            return FALSE;
152
-          }
153
-        }
154
-      }
155
-    }
156
-    return TRUE;
147
+	foreach ($segments as $i => $segment) {
148
+	  foreach ($segments as $j => $check_segment) {
149
+		if ($i != $j) {
150
+		  if ($segment->lineSegmentIntersect($check_segment)) {
151
+			return FALSE;
152
+		  }
153
+		}
154
+	  }
155
+	}
156
+	return TRUE;
157 157
   }
158 158
 
159 159
   // Utility function to check if any line sigments intersect
160 160
   // Derived from http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
161 161
   public function lineSegmentIntersect($segment) {
162
-    $p0_x = $this->startPoint()->x();
163
-    $p0_y = $this->startPoint()->y();
164
-    $p1_x = $this->endPoint()->x();
165
-    $p1_y = $this->endPoint()->y();
166
-    $p2_x = $segment->startPoint()->x();
167
-    $p2_y = $segment->startPoint()->y();
168
-    $p3_x = $segment->endPoint()->x();
169
-    $p3_y = $segment->endPoint()->y();
170
-
171
-    $s1_x = $p1_x - $p0_x;     $s1_y = $p1_y - $p0_y;
172
-    $s2_x = $p3_x - $p2_x;     $s2_y = $p3_y - $p2_y;
173
-
174
-    $fps = (-$s2_x * $s1_y) + ($s1_x * $s2_y);
175
-    $fpt = (-$s2_x * $s1_y) + ($s1_x * $s2_y);
176
-
177
-    if ($fps == 0 || $fpt == 0) {
178
-      return FALSE;
179
-    }
180
-
181
-    $s = (-$s1_y * ($p0_x - $p2_x) + $s1_x * ($p0_y - $p2_y)) / $fps;
182
-    $t = ( $s2_x * ($p0_y - $p2_y) - $s2_y * ($p0_x - $p2_x)) / $fpt;
183
-
184
-    if ($s > 0 && $s < 1 && $t > 0 && $t < 1) {
185
-      // Collision detected
186
-      return TRUE;
187
-    }
188
-    return FALSE;
162
+	$p0_x = $this->startPoint()->x();
163
+	$p0_y = $this->startPoint()->y();
164
+	$p1_x = $this->endPoint()->x();
165
+	$p1_y = $this->endPoint()->y();
166
+	$p2_x = $segment->startPoint()->x();
167
+	$p2_y = $segment->startPoint()->y();
168
+	$p3_x = $segment->endPoint()->x();
169
+	$p3_y = $segment->endPoint()->y();
170
+
171
+	$s1_x = $p1_x - $p0_x;     $s1_y = $p1_y - $p0_y;
172
+	$s2_x = $p3_x - $p2_x;     $s2_y = $p3_y - $p2_y;
173
+
174
+	$fps = (-$s2_x * $s1_y) + ($s1_x * $s2_y);
175
+	$fpt = (-$s2_x * $s1_y) + ($s1_x * $s2_y);
176
+
177
+	if ($fps == 0 || $fpt == 0) {
178
+	  return FALSE;
179
+	}
180
+
181
+	$s = (-$s1_y * ($p0_x - $p2_x) + $s1_x * ($p0_y - $p2_y)) / $fps;
182
+	$t = ( $s2_x * ($p0_y - $p2_y) - $s2_y * ($p0_x - $p2_x)) / $fpt;
183
+
184
+	if ($s > 0 && $s < 1 && $t > 0 && $t < 1) {
185
+	  // Collision detected
186
+	  return TRUE;
187
+	}
188
+	return FALSE;
189 189
   }
190 190
 }
191 191
 
Please login to merge, or discard this patch.
require/libs/geoPHP/lib/geometry/Geometry.class.php 1 patch
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -46,38 +46,38 @@  discard block
 block discarded – undo
46 46
   // Public: Standard -- Common to all geometries
47 47
   // --------------------------------------------
48 48
   public function SRID() {
49
-    return $this->srid;
49
+	return $this->srid;
50 50
   }
51 51
 
52 52
   public function setSRID($srid) {
53
-    if ($this->geos()) {
54
-      $this->geos()->setSRID($srid);
55
-    }
56
-    $this->srid = $srid;
53
+	if ($this->geos()) {
54
+	  $this->geos()->setSRID($srid);
55
+	}
56
+	$this->srid = $srid;
57 57
   }
58 58
 
59 59
   public function envelope() {
60
-    if ($this->isEmpty()) return new Polygon();
60
+	if ($this->isEmpty()) return new Polygon();
61 61
 
62
-    if ($this->geos()) {
63
-      return geoPHP::geosToGeometry($this->geos()->envelope());
64
-    }
62
+	if ($this->geos()) {
63
+	  return geoPHP::geosToGeometry($this->geos()->envelope());
64
+	}
65 65
 
66
-    $bbox = $this->getBBox();
67
-    $points = array (
68
-      new Point($bbox['maxx'],$bbox['miny']),
69
-      new Point($bbox['maxx'],$bbox['maxy']),
70
-      new Point($bbox['minx'],$bbox['maxy']),
71
-      new Point($bbox['minx'],$bbox['miny']),
72
-      new Point($bbox['maxx'],$bbox['miny']),
73
-    );
66
+	$bbox = $this->getBBox();
67
+	$points = array (
68
+	  new Point($bbox['maxx'],$bbox['miny']),
69
+	  new Point($bbox['maxx'],$bbox['maxy']),
70
+	  new Point($bbox['minx'],$bbox['maxy']),
71
+	  new Point($bbox['minx'],$bbox['miny']),
72
+	  new Point($bbox['maxx'],$bbox['miny']),
73
+	);
74 74
 
75
-    $outer_boundary = new LineString($points);
76
-    return new Polygon(array($outer_boundary));
75
+	$outer_boundary = new LineString($points);
76
+	return new Polygon(array($outer_boundary));
77 77
   }
78 78
 
79 79
   public function geometryType() {
80
-    return $this->geom_type;
80
+	return $this->geom_type;
81 81
   }
82 82
 
83 83
   // Public: Non-Standard -- Common to all geometries
@@ -85,263 +85,263 @@  discard block
 block discarded – undo
85 85
 
86 86
   // $this->out($format, $other_args);
87 87
   public function out() {
88
-    $args = func_get_args();
88
+	$args = func_get_args();
89 89
 
90
-    $format = array_shift($args);
91
-    $type_map = geoPHP::getAdapterMap();
92
-    $processor_type = $type_map[$format];
93
-    $processor = new $processor_type();
90
+	$format = array_shift($args);
91
+	$type_map = geoPHP::getAdapterMap();
92
+	$processor_type = $type_map[$format];
93
+	$processor = new $processor_type();
94 94
 
95
-    array_unshift($args, $this);
96
-    $result = call_user_func_array(array($processor, 'write'), $args);
95
+	array_unshift($args, $this);
96
+	$result = call_user_func_array(array($processor, 'write'), $args);
97 97
 
98
-    return $result;
98
+	return $result;
99 99
   }
100 100
 
101 101
 
102 102
   // Public: Aliases
103 103
   // ---------------
104 104
   public function getCentroid() {
105
-    return $this->centroid();
105
+	return $this->centroid();
106 106
   }
107 107
 
108 108
   public function getArea() {
109
-    return $this->area();
109
+	return $this->area();
110 110
   }
111 111
 
112 112
   public function getX() {
113
-    return $this->x();
113
+	return $this->x();
114 114
   }
115 115
 
116 116
   public function getY() {
117
-    return $this->y();
117
+	return $this->y();
118 118
   }
119 119
 
120 120
   public function getGeos() {
121
-    return $this->geos();
121
+	return $this->geos();
122 122
   }
123 123
 
124 124
   public function getGeomType() {
125
-    return $this->geometryType();
125
+	return $this->geometryType();
126 126
   }
127 127
 
128 128
   public function getSRID() {
129
-    return $this->SRID();
129
+	return $this->SRID();
130 130
   }
131 131
 
132 132
   public function asText() {
133
-    return $this->out('wkt');
133
+	return $this->out('wkt');
134 134
   }
135 135
 
136 136
   public function asBinary() {
137
-    return $this->out('wkb');
137
+	return $this->out('wkb');
138 138
   }
139 139
 
140 140
   // Public: GEOS Only Functions
141 141
   // ---------------------------
142 142
   public function geos() {
143
-    // If it's already been set, just return it
144
-    if ($this->geos && geoPHP::geosInstalled()) {
145
-      return $this->geos;
146
-    }
147
-    // It hasn't been set yet, generate it
148
-    if (geoPHP::geosInstalled()) {
149
-      $reader = new GEOSWKBReader();
150
-      $this->geos = $reader->readHEX($this->out('wkb',TRUE));
151
-    }
152
-    else {
153
-      $this->geos = FALSE;
154
-    }
155
-    return $this->geos;
143
+	// If it's already been set, just return it
144
+	if ($this->geos && geoPHP::geosInstalled()) {
145
+	  return $this->geos;
146
+	}
147
+	// It hasn't been set yet, generate it
148
+	if (geoPHP::geosInstalled()) {
149
+	  $reader = new GEOSWKBReader();
150
+	  $this->geos = $reader->readHEX($this->out('wkb',TRUE));
151
+	}
152
+	else {
153
+	  $this->geos = FALSE;
154
+	}
155
+	return $this->geos;
156 156
   }
157 157
 
158 158
   public function setGeos($geos) {
159
-    $this->geos = $geos;
159
+	$this->geos = $geos;
160 160
   }
161 161
 
162 162
   public function pointOnSurface() {
163
-    if ($this->geos()) {
164
-      return geoPHP::geosToGeometry($this->geos()->pointOnSurface());
165
-    }
163
+	if ($this->geos()) {
164
+	  return geoPHP::geosToGeometry($this->geos()->pointOnSurface());
165
+	}
166 166
   }
167 167
 
168 168
   public function equalsExact(Geometry $geometry) {
169
-    if ($this->geos()) {
170
-      return $this->geos()->equalsExact($geometry->geos());
171
-    }
169
+	if ($this->geos()) {
170
+	  return $this->geos()->equalsExact($geometry->geos());
171
+	}
172 172
   }
173 173
 
174 174
   public function relate(Geometry $geometry, $pattern = NULL) {
175
-    if ($this->geos()) {
176
-      if ($pattern) {
177
-        return $this->geos()->relate($geometry->geos(), $pattern);
178
-      }
179
-      else {
180
-        return $this->geos()->relate($geometry->geos());
181
-      }
182
-    }
175
+	if ($this->geos()) {
176
+	  if ($pattern) {
177
+		return $this->geos()->relate($geometry->geos(), $pattern);
178
+	  }
179
+	  else {
180
+		return $this->geos()->relate($geometry->geos());
181
+	  }
182
+	}
183 183
   }
184 184
 
185 185
   public function checkValidity() {
186
-    if ($this->geos()) {
187
-      return $this->geos()->checkValidity();
188
-    }
186
+	if ($this->geos()) {
187
+	  return $this->geos()->checkValidity();
188
+	}
189 189
   }
190 190
 
191 191
   public function buffer($distance) {
192
-    if ($this->geos()) {
193
-      return geoPHP::geosToGeometry($this->geos()->buffer($distance));
194
-    }
192
+	if ($this->geos()) {
193
+	  return geoPHP::geosToGeometry($this->geos()->buffer($distance));
194
+	}
195 195
   }
196 196
 
197 197
   public function intersection(Geometry $geometry) {
198
-    if ($this->geos()) {
199
-      return geoPHP::geosToGeometry($this->geos()->intersection($geometry->geos()));
200
-    }
198
+	if ($this->geos()) {
199
+	  return geoPHP::geosToGeometry($this->geos()->intersection($geometry->geos()));
200
+	}
201 201
   }
202 202
 
203 203
   public function convexHull() {
204
-    if ($this->geos()) {
205
-      return geoPHP::geosToGeometry($this->geos()->convexHull());
206
-    }
204
+	if ($this->geos()) {
205
+	  return geoPHP::geosToGeometry($this->geos()->convexHull());
206
+	}
207 207
   }
208 208
 
209 209
   public function difference(Geometry $geometry) {
210
-    if ($this->geos()) {
211
-      return geoPHP::geosToGeometry($this->geos()->difference($geometry->geos()));
212
-    }
210
+	if ($this->geos()) {
211
+	  return geoPHP::geosToGeometry($this->geos()->difference($geometry->geos()));
212
+	}
213 213
   }
214 214
 
215 215
   public function symDifference(Geometry $geometry) {
216
-    if ($this->geos()) {
217
-      return geoPHP::geosToGeometry($this->geos()->symDifference($geometry->geos()));
218
-    }
216
+	if ($this->geos()) {
217
+	  return geoPHP::geosToGeometry($this->geos()->symDifference($geometry->geos()));
218
+	}
219 219
   }
220 220
 
221 221
   // Can pass in a geometry or an array of geometries
222 222
   public function union(Geometry $geometry) {
223
-    if ($this->geos()) {
224
-      if (is_array($geometry)) {
225
-        $geom = $this->geos();
226
-        foreach ($geometry as $item) {
227
-          $geom = $geom->union($item->geos());
228
-        }
229
-        return geoPHP::geosToGeometry($geom);
230
-      }
231
-      else {
232
-        return geoPHP::geosToGeometry($this->geos()->union($geometry->geos()));
233
-      }
234
-    }
223
+	if ($this->geos()) {
224
+	  if (is_array($geometry)) {
225
+		$geom = $this->geos();
226
+		foreach ($geometry as $item) {
227
+		  $geom = $geom->union($item->geos());
228
+		}
229
+		return geoPHP::geosToGeometry($geom);
230
+	  }
231
+	  else {
232
+		return geoPHP::geosToGeometry($this->geos()->union($geometry->geos()));
233
+	  }
234
+	}
235 235
   }
236 236
 
237 237
   public function simplify($tolerance, $preserveTopology = FALSE) {
238
-    if ($this->geos()) {
239
-      return geoPHP::geosToGeometry($this->geos()->simplify($tolerance, $preserveTopology));
240
-    }
238
+	if ($this->geos()) {
239
+	  return geoPHP::geosToGeometry($this->geos()->simplify($tolerance, $preserveTopology));
240
+	}
241 241
   }
242 242
 
243 243
   public function disjoint(Geometry $geometry) {
244
-    if ($this->geos()) {
245
-      return $this->geos()->disjoint($geometry->geos());
246
-    }
244
+	if ($this->geos()) {
245
+	  return $this->geos()->disjoint($geometry->geos());
246
+	}
247 247
   }
248 248
 
249 249
   public function touches(Geometry $geometry) {
250
-    if ($this->geos()) {
251
-      return $this->geos()->touches($geometry->geos());
252
-    }
250
+	if ($this->geos()) {
251
+	  return $this->geos()->touches($geometry->geos());
252
+	}
253 253
   }
254 254
 
255 255
   public function intersects(Geometry $geometry) {
256
-    if ($this->geos()) {
257
-      return $this->geos()->intersects($geometry->geos());
258
-    }
256
+	if ($this->geos()) {
257
+	  return $this->geos()->intersects($geometry->geos());
258
+	}
259 259
   }
260 260
 
261 261
   public function crosses(Geometry $geometry) {
262
-    if ($this->geos()) {
263
-      return $this->geos()->crosses($geometry->geos());
264
-    }
262
+	if ($this->geos()) {
263
+	  return $this->geos()->crosses($geometry->geos());
264
+	}
265 265
   }
266 266
 
267 267
   public function within(Geometry $geometry) {
268
-    if ($this->geos()) {
269
-      return $this->geos()->within($geometry->geos());
270
-    }
268
+	if ($this->geos()) {
269
+	  return $this->geos()->within($geometry->geos());
270
+	}
271 271
   }
272 272
 
273 273
   public function contains(Geometry $geometry) {
274
-    if ($this->geos()) {
275
-      return $this->geos()->contains($geometry->geos());
276
-    }
274
+	if ($this->geos()) {
275
+	  return $this->geos()->contains($geometry->geos());
276
+	}
277 277
   }
278 278
 
279 279
   public function overlaps(Geometry $geometry) {
280
-    if ($this->geos()) {
281
-      return $this->geos()->overlaps($geometry->geos());
282
-    }
280
+	if ($this->geos()) {
281
+	  return $this->geos()->overlaps($geometry->geos());
282
+	}
283 283
   }
284 284
 
285 285
   public function covers(Geometry $geometry) {
286
-    if ($this->geos()) {
287
-      return $this->geos()->covers($geometry->geos());
288
-    }
286
+	if ($this->geos()) {
287
+	  return $this->geos()->covers($geometry->geos());
288
+	}
289 289
   }
290 290
 
291 291
   public function coveredBy(Geometry $geometry) {
292
-    if ($this->geos()) {
293
-      return $this->geos()->coveredBy($geometry->geos());
294
-    }
292
+	if ($this->geos()) {
293
+	  return $this->geos()->coveredBy($geometry->geos());
294
+	}
295 295
   }
296 296
 
297 297
   public function distance(Geometry $geometry) {
298
-    if ($this->geos()) {
299
-      return $this->geos()->distance($geometry->geos());
300
-    }
298
+	if ($this->geos()) {
299
+	  return $this->geos()->distance($geometry->geos());
300
+	}
301 301
   }
302 302
 
303 303
   public function hausdorffDistance(Geometry $geometry) {
304
-    if ($this->geos()) {
305
-      return $this->geos()->hausdorffDistance($geometry->geos());
306
-    }
304
+	if ($this->geos()) {
305
+	  return $this->geos()->hausdorffDistance($geometry->geos());
306
+	}
307 307
   }
308 308
 
309 309
   public function project(Geometry $point, $normalized = NULL) {
310
-    if ($this->geos()) {
311
-      return $this->geos()->project($point->geos(), $normalized);
312
-    }
310
+	if ($this->geos()) {
311
+	  return $this->geos()->project($point->geos(), $normalized);
312
+	}
313 313
   }
314 314
 
315 315
   // Public - Placeholders
316 316
   // ---------------------
317 317
   public function hasZ() {
318
-    // geoPHP does not support Z values at the moment
319
-    return FALSE;
318
+	// geoPHP does not support Z values at the moment
319
+	return FALSE;
320 320
   }
321 321
 
322 322
   public function is3D() {
323
-    // geoPHP does not support 3D geometries at the moment
324
-    return FALSE;
323
+	// geoPHP does not support 3D geometries at the moment
324
+	return FALSE;
325 325
   }
326 326
 
327 327
   public function isMeasured() {
328
-    // geoPHP does not yet support M values
329
-    return FALSE;
328
+	// geoPHP does not yet support M values
329
+	return FALSE;
330 330
   }
331 331
 
332 332
   public function coordinateDimension() {
333
-    // geoPHP only supports 2-dimentional space
334
-    return 2;
333
+	// geoPHP only supports 2-dimentional space
334
+	return 2;
335 335
   }
336 336
 
337 337
   public function z() {
338
-    // geoPHP only supports 2-dimentional space
339
-    return NULL;
338
+	// geoPHP only supports 2-dimentional space
339
+	return NULL;
340 340
   }
341 341
 
342 342
   public function m() {
343
-    // geoPHP only supports 2-dimentional space
344
-    return NULL;
343
+	// geoPHP only supports 2-dimentional space
344
+	return NULL;
345 345
   }
346 346
 
347 347
 }
Please login to merge, or discard this patch.
require/libs/geoPHP/geoPHP.inc 1 patch
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -35,110 +35,110 @@  discard block
 block discarded – undo
35 35
 {
36 36
 
37 37
   static function version() {
38
-    return '1.1';
38
+	return '1.1';
39 39
   }
40 40
 
41 41
   // geoPHP::load($data, $type, $other_args);
42 42
   // if $data is an array, all passed in values will be combined into a single geometry
43 43
   static function load() {
44
-    $args = func_get_args();
44
+	$args = func_get_args();
45 45
 
46
-    $data = array_shift($args);
47
-    $type = array_shift($args);
46
+	$data = array_shift($args);
47
+	$type = array_shift($args);
48 48
 
49
-    $type_map = geoPHP::getAdapterMap();
49
+	$type_map = geoPHP::getAdapterMap();
50 50
 
51
-    // Auto-detect type if needed
52
-    if (!$type) {
53
-      // If the user is trying to load a Geometry from a Geometry... Just pass it back
54
-      if (is_object($data)) {
55
-        if ($data instanceOf Geometry) return $data;
56
-      }
51
+	// Auto-detect type if needed
52
+	if (!$type) {
53
+	  // If the user is trying to load a Geometry from a Geometry... Just pass it back
54
+	  if (is_object($data)) {
55
+		if ($data instanceOf Geometry) return $data;
56
+	  }
57 57
       
58
-      $detected = geoPHP::detectFormat($data);
59
-      if (!$detected) {
60
-        return FALSE;
61
-      }
58
+	  $detected = geoPHP::detectFormat($data);
59
+	  if (!$detected) {
60
+		return FALSE;
61
+	  }
62 62
       
63
-      $format = explode(':', $detected);
64
-      $type = array_shift($format);
65
-      $args = $format;
66
-    }
67
-
68
-    $processor_type = $type_map[$type];
69
-
70
-    if (!$processor_type) {
71
-      throw new exception('geoPHP could not find an adapter of type '.htmlentities($type));
72
-      exit;
73
-    }
74
-
75
-    $processor = new $processor_type();
76
-
77
-    // Data is not an array, just pass it normally
78
-    if (!is_array($data)) {
79
-      $result = call_user_func_array(array($processor, "read"), array_merge(array($data), $args));
80
-    }
81
-    // Data is an array, combine all passed in items into a single geomtetry
82
-    else {
83
-      $geoms = array();
84
-      foreach ($data as $item) {
85
-        $geoms[] = call_user_func_array(array($processor, "read"), array_merge(array($item), $args));
86
-      }
87
-      $result = geoPHP::geometryReduce($geoms);
88
-    }
89
-
90
-    return $result;
63
+	  $format = explode(':', $detected);
64
+	  $type = array_shift($format);
65
+	  $args = $format;
66
+	}
67
+
68
+	$processor_type = $type_map[$type];
69
+
70
+	if (!$processor_type) {
71
+	  throw new exception('geoPHP could not find an adapter of type '.htmlentities($type));
72
+	  exit;
73
+	}
74
+
75
+	$processor = new $processor_type();
76
+
77
+	// Data is not an array, just pass it normally
78
+	if (!is_array($data)) {
79
+	  $result = call_user_func_array(array($processor, "read"), array_merge(array($data), $args));
80
+	}
81
+	// Data is an array, combine all passed in items into a single geomtetry
82
+	else {
83
+	  $geoms = array();
84
+	  foreach ($data as $item) {
85
+		$geoms[] = call_user_func_array(array($processor, "read"), array_merge(array($item), $args));
86
+	  }
87
+	  $result = geoPHP::geometryReduce($geoms);
88
+	}
89
+
90
+	return $result;
91 91
   }
92 92
 
93 93
   static function getAdapterMap() {
94
-    return array (
95
-      'wkt' =>  'WKT',
96
-      'ewkt' => 'EWKT',
97
-      'wkb' =>  'WKB',
98
-      'ewkb' => 'EWKB',
99
-      'json' => 'GeoJSON',
100
-      'geojson' => 'GeoJSON',
101
-      'kml' =>  'KML',
102
-      'gpx' =>  'GPX',
103
-      'georss' => 'GeoRSS',
104
-      'google_geocode' => 'GoogleGeocode',
105
-      'geohash' => 'GeoHash',
106
-    );
94
+	return array (
95
+	  'wkt' =>  'WKT',
96
+	  'ewkt' => 'EWKT',
97
+	  'wkb' =>  'WKB',
98
+	  'ewkb' => 'EWKB',
99
+	  'json' => 'GeoJSON',
100
+	  'geojson' => 'GeoJSON',
101
+	  'kml' =>  'KML',
102
+	  'gpx' =>  'GPX',
103
+	  'georss' => 'GeoRSS',
104
+	  'google_geocode' => 'GoogleGeocode',
105
+	  'geohash' => 'GeoHash',
106
+	);
107 107
   }
108 108
 
109 109
   static function geometryList() {
110
-    return array(
111
-      'point' => 'Point',
112
-      'linestring' => 'LineString',
113
-      'polygon' => 'Polygon',
114
-      'multipoint' => 'MultiPoint',
115
-      'multilinestring' => 'MultiLineString',
116
-      'multipolygon' => 'MultiPolygon',
117
-      'geometrycollection' => 'GeometryCollection',
118
-    );
110
+	return array(
111
+	  'point' => 'Point',
112
+	  'linestring' => 'LineString',
113
+	  'polygon' => 'Polygon',
114
+	  'multipoint' => 'MultiPoint',
115
+	  'multilinestring' => 'MultiLineString',
116
+	  'multipolygon' => 'MultiPolygon',
117
+	  'geometrycollection' => 'GeometryCollection',
118
+	);
119 119
   }
120 120
 
121 121
   static function geosInstalled($force = NULL) {
122
-    static $geos_installed = NULL;
123
-    if ($force !== NULL) $geos_installed = $force;
124
-    if ($geos_installed !== NULL) {
125
-      return $geos_installed;
126
-    }
127
-    $geos_installed = class_exists('GEOSGeometry');
128
-    return $geos_installed;
122
+	static $geos_installed = NULL;
123
+	if ($force !== NULL) $geos_installed = $force;
124
+	if ($geos_installed !== NULL) {
125
+	  return $geos_installed;
126
+	}
127
+	$geos_installed = class_exists('GEOSGeometry');
128
+	return $geos_installed;
129 129
   }
130 130
 
131 131
   static function geosToGeometry($geos) {
132
-    if (!geoPHP::geosInstalled()) {
133
-      return NULL;
134
-    }
135
-    $wkb_writer = new GEOSWKBWriter();
136
-    $wkb = $wkb_writer->writeHEX($geos);
137
-    $geometry = geoPHP::load($wkb, 'wkb', TRUE);
138
-    if ($geometry) {
139
-      $geometry->setGeos($geos);
140
-      return $geometry;
141
-    }
132
+	if (!geoPHP::geosInstalled()) {
133
+	  return NULL;
134
+	}
135
+	$wkb_writer = new GEOSWKBWriter();
136
+	$wkb = $wkb_writer->writeHEX($geos);
137
+	$geometry = geoPHP::load($wkb, 'wkb', TRUE);
138
+	if ($geometry) {
139
+	  $geometry->setGeos($geos);
140
+	  return $geometry;
141
+	}
142 142
   }
143 143
 
144 144
   // Reduce a geometry, or an array of geometries, into their 'lowest' available common geometry.
@@ -146,155 +146,155 @@  discard block
 block discarded – undo
146 146
   // A multi-point containing a single point will return a point.
147 147
   // An array of geometries can be passed and they will be compiled into a single geometry
148 148
   static function geometryReduce($geometry) {
149
-    // If it's an array of one, then just parse the one
150
-    if (is_array($geometry)) {
151
-      if (empty($geometry)) return FALSE;
152
-      if (count($geometry) == 1) return geoPHP::geometryReduce(array_shift($geometry));
153
-    }
154
-
155
-    // If the geometry cannot even theoretically be reduced more, then pass it back
156
-    if (gettype($geometry) == 'object') {
157
-      $passbacks = array('Point','LineString','Polygon');
158
-      if (in_array($geometry->geometryType(),$passbacks)) {
159
-        return $geometry;
160
-      }
161
-    }
162
-
163
-    // If it is a mutlti-geometry, check to see if it just has one member
164
-    // If it does, then pass the member, if not, then just pass back the geometry
165
-    if (gettype($geometry) == 'object') {
166
-      $simple_collections = array('MultiPoint','MultiLineString','MultiPolygon');
167
-      if (in_array(get_class($geometry),$passbacks)) {
168
-        $components = $geometry->getComponents();
169
-        if (count($components) == 1) {
170
-          return $components[0];
171
-        }
172
-        else {
173
-          return $geometry;
174
-        }
175
-      }
176
-    }
177
-
178
-    // So now we either have an array of geometries, a GeometryCollection, or an array of GeometryCollections
179
-    if (!is_array($geometry)) {
180
-      $geometry = array($geometry);
181
-    }
182
-
183
-    $geometries = array();
184
-    $geom_types = array();
185
-
186
-    $collections = array('MultiPoint','MultiLineString','MultiPolygon','GeometryCollection');
187
-
188
-    foreach ($geometry as $item) {
189
-      if ($item) {
190
-        if (in_array(get_class($item), $collections)) {
191
-          foreach ($item->getComponents() as $component) {
192
-            $geometries[] = $component;
193
-            $geom_types[] = $component->geometryType();
194
-          }
195
-        }
196
-        else {
197
-          $geometries[] = $item;
198
-          $geom_types[] = $item->geometryType();
199
-        }
200
-      }
201
-    }
202
-
203
-    $geom_types = array_unique($geom_types);
149
+	// If it's an array of one, then just parse the one
150
+	if (is_array($geometry)) {
151
+	  if (empty($geometry)) return FALSE;
152
+	  if (count($geometry) == 1) return geoPHP::geometryReduce(array_shift($geometry));
153
+	}
154
+
155
+	// If the geometry cannot even theoretically be reduced more, then pass it back
156
+	if (gettype($geometry) == 'object') {
157
+	  $passbacks = array('Point','LineString','Polygon');
158
+	  if (in_array($geometry->geometryType(),$passbacks)) {
159
+		return $geometry;
160
+	  }
161
+	}
162
+
163
+	// If it is a mutlti-geometry, check to see if it just has one member
164
+	// If it does, then pass the member, if not, then just pass back the geometry
165
+	if (gettype($geometry) == 'object') {
166
+	  $simple_collections = array('MultiPoint','MultiLineString','MultiPolygon');
167
+	  if (in_array(get_class($geometry),$passbacks)) {
168
+		$components = $geometry->getComponents();
169
+		if (count($components) == 1) {
170
+		  return $components[0];
171
+		}
172
+		else {
173
+		  return $geometry;
174
+		}
175
+	  }
176
+	}
177
+
178
+	// So now we either have an array of geometries, a GeometryCollection, or an array of GeometryCollections
179
+	if (!is_array($geometry)) {
180
+	  $geometry = array($geometry);
181
+	}
182
+
183
+	$geometries = array();
184
+	$geom_types = array();
185
+
186
+	$collections = array('MultiPoint','MultiLineString','MultiPolygon','GeometryCollection');
187
+
188
+	foreach ($geometry as $item) {
189
+	  if ($item) {
190
+		if (in_array(get_class($item), $collections)) {
191
+		  foreach ($item->getComponents() as $component) {
192
+			$geometries[] = $component;
193
+			$geom_types[] = $component->geometryType();
194
+		  }
195
+		}
196
+		else {
197
+		  $geometries[] = $item;
198
+		  $geom_types[] = $item->geometryType();
199
+		}
200
+	  }
201
+	}
202
+
203
+	$geom_types = array_unique($geom_types);
204 204
     
205
-    if (empty($geom_types)) {
206
-      return FALSE;
207
-    }
208
-
209
-    if (count($geom_types) == 1) {
210
-      if (count($geometries) == 1) {
211
-        return $geometries[0];
212
-      }
213
-      else {
214
-        $class = 'Multi'.$geom_types[0];
215
-        return new $class($geometries);
216
-      }
217
-    }
218
-    else {
219
-      return new GeometryCollection($geometries);
220
-    }
205
+	if (empty($geom_types)) {
206
+	  return FALSE;
207
+	}
208
+
209
+	if (count($geom_types) == 1) {
210
+	  if (count($geometries) == 1) {
211
+		return $geometries[0];
212
+	  }
213
+	  else {
214
+		$class = 'Multi'.$geom_types[0];
215
+		return new $class($geometries);
216
+	  }
217
+	}
218
+	else {
219
+	  return new GeometryCollection($geometries);
220
+	}
221 221
   }
222 222
 
223 223
   // Detect a format given a value. This function is meant to be SPEEDY.
224 224
   // It could make a mistake in XML detection if you are mixing or using namespaces in weird ways (ie, KML inside an RSS feed)
225 225
   static function detectFormat(&$input) {
226
-    $mem = fopen('php://memory', 'r+');
227
-    fwrite($mem, $input, 11); // Write 11 bytes - we can detect the vast majority of formats in the first 11 bytes
228
-    fseek($mem, 0);
229
-
230
-    $bytes = unpack("c*", fread($mem, 11));
231
-
232
-    // If bytes is empty, then we were passed empty input
233
-    if (empty($bytes)) return FALSE;
234
-
235
-    // First char is a tab, space or carriage-return. trim it and try again
236
-    if ($bytes[1] == 9 || $bytes[1] == 10 || $bytes[1] == 32) {
237
-      return geoPHP::detectFormat(ltrim($input));
238
-    }
239
-
240
-    // Detect WKB or EWKB -- first byte is 1 (little endian indicator)
241
-    if ($bytes[1] == 1) {
242
-      // If SRID byte is TRUE (1), it's EWKB
243
-      if ($bytes[5]) return 'ewkb';
244
-      else return 'wkb';
245
-    }
246
-
247
-    // Detect HEX encoded WKB or EWKB (PostGIS format) -- first byte is 48, second byte is 49 (hex '01' => first-byte = 1)
248
-    if ($bytes[1] == 48 && $bytes[2] == 49) {
249
-      // The shortest possible WKB string (LINESTRING EMPTY) is 18 hex-chars (9 encoded bytes) long
250
-      // This differentiates it from a geohash, which is always shorter than 18 characters.
251
-      if (strlen($input) >= 18) {
252
-        //@@TODO: Differentiate between EWKB and WKB -- check hex-char 10 or 11 (SRID bool indicator at encoded byte 5)
253
-        return 'ewkb:1';
254
-      }
255
-    }
256
-
257
-    // Detect GeoJSON - first char starts with {
258
-    if ($bytes[1] == 123) {
259
-      return 'json';
260
-    }
261
-
262
-    // Detect EWKT - first char is S
263
-    if ($bytes[1] == 83) {
264
-      return 'ewkt';
265
-    }
266
-
267
-    // Detect WKT - first char starts with P (80), L (76), M (77), or G (71)
268
-    $wkt_chars = array(80, 76, 77, 71);
269
-    if (in_array($bytes[1], $wkt_chars)) {
270
-      return 'wkt';
271
-    }
272
-
273
-    // Detect XML -- first char is <
274
-    if ($bytes[1] == 60) {
275
-      // grab the first 256 characters
276
-      $string = substr($input, 0, 256);
277
-      if (strpos($string, '<kml') !== FALSE)        return 'kml';
278
-      if (strpos($string, '<coordinate') !== FALSE) return 'kml';
279
-      if (strpos($string, '<gpx') !== FALSE)        return 'gpx';
280
-      if (strpos($string, '<georss') !== FALSE)     return 'georss';
281
-      if (strpos($string, '<rss') !== FALSE)        return 'georss';
282
-      if (strpos($string, '<feed') !== FALSE)       return 'georss';
283
-    }
284
-
285
-    // We need an 8 byte string for geohash and unpacked WKB / WKT
286
-    fseek($mem, 0);
287
-    $string = trim(fread($mem, 8));
288
-
289
-    // Detect geohash - geohash ONLY contains lowercase chars and numerics
290
-    preg_match('/[a-z0-9]+/', $string, $matches);
291
-    if ($matches[0] == $string) {
292
-      return 'geohash';
293
-    }
294
-
295
-    // What do you get when you cross an elephant with a rhino?
296
-    // http://youtu.be/RCBn5J83Poc
297
-    return FALSE;
226
+	$mem = fopen('php://memory', 'r+');
227
+	fwrite($mem, $input, 11); // Write 11 bytes - we can detect the vast majority of formats in the first 11 bytes
228
+	fseek($mem, 0);
229
+
230
+	$bytes = unpack("c*", fread($mem, 11));
231
+
232
+	// If bytes is empty, then we were passed empty input
233
+	if (empty($bytes)) return FALSE;
234
+
235
+	// First char is a tab, space or carriage-return. trim it and try again
236
+	if ($bytes[1] == 9 || $bytes[1] == 10 || $bytes[1] == 32) {
237
+	  return geoPHP::detectFormat(ltrim($input));
238
+	}
239
+
240
+	// Detect WKB or EWKB -- first byte is 1 (little endian indicator)
241
+	if ($bytes[1] == 1) {
242
+	  // If SRID byte is TRUE (1), it's EWKB
243
+	  if ($bytes[5]) return 'ewkb';
244
+	  else return 'wkb';
245
+	}
246
+
247
+	// Detect HEX encoded WKB or EWKB (PostGIS format) -- first byte is 48, second byte is 49 (hex '01' => first-byte = 1)
248
+	if ($bytes[1] == 48 && $bytes[2] == 49) {
249
+	  // The shortest possible WKB string (LINESTRING EMPTY) is 18 hex-chars (9 encoded bytes) long
250
+	  // This differentiates it from a geohash, which is always shorter than 18 characters.
251
+	  if (strlen($input) >= 18) {
252
+		//@@TODO: Differentiate between EWKB and WKB -- check hex-char 10 or 11 (SRID bool indicator at encoded byte 5)
253
+		return 'ewkb:1';
254
+	  }
255
+	}
256
+
257
+	// Detect GeoJSON - first char starts with {
258
+	if ($bytes[1] == 123) {
259
+	  return 'json';
260
+	}
261
+
262
+	// Detect EWKT - first char is S
263
+	if ($bytes[1] == 83) {
264
+	  return 'ewkt';
265
+	}
266
+
267
+	// Detect WKT - first char starts with P (80), L (76), M (77), or G (71)
268
+	$wkt_chars = array(80, 76, 77, 71);
269
+	if (in_array($bytes[1], $wkt_chars)) {
270
+	  return 'wkt';
271
+	}
272
+
273
+	// Detect XML -- first char is <
274
+	if ($bytes[1] == 60) {
275
+	  // grab the first 256 characters
276
+	  $string = substr($input, 0, 256);
277
+	  if (strpos($string, '<kml') !== FALSE)        return 'kml';
278
+	  if (strpos($string, '<coordinate') !== FALSE) return 'kml';
279
+	  if (strpos($string, '<gpx') !== FALSE)        return 'gpx';
280
+	  if (strpos($string, '<georss') !== FALSE)     return 'georss';
281
+	  if (strpos($string, '<rss') !== FALSE)        return 'georss';
282
+	  if (strpos($string, '<feed') !== FALSE)       return 'georss';
283
+	}
284
+
285
+	// We need an 8 byte string for geohash and unpacked WKB / WKT
286
+	fseek($mem, 0);
287
+	$string = trim(fread($mem, 8));
288
+
289
+	// Detect geohash - geohash ONLY contains lowercase chars and numerics
290
+	preg_match('/[a-z0-9]+/', $string, $matches);
291
+	if ($matches[0] == $string) {
292
+	  return 'geohash';
293
+	}
294
+
295
+	// What do you get when you cross an elephant with a rhino?
296
+	// http://youtu.be/RCBn5J83Poc
297
+	return FALSE;
298 298
   }
299 299
 
300 300
 }
Please login to merge, or discard this patch.
scripts/cron.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@
 block discarded – undo
11 11
 //checks to see if FlightAware import is set
12 12
 if ($globalFlightAware == TRUE)
13 13
 {
14
-    $SpotterLive = new SpotterLive();
15
-    $Spotter = new Spotter();
16
-    //deletes the spotter LIVE data
17
-    $SpotterLive->deleteLiveSpotterData();
14
+	$SpotterLive = new SpotterLive();
15
+	$Spotter = new Spotter();
16
+	//deletes the spotter LIVE data
17
+	$SpotterLive->deleteLiveSpotterData();
18 18
     
19
-    //imports the new data from FlightAware
20
-    $Spotter->importFromFlightAware();
19
+	//imports the new data from FlightAware
20
+	$Spotter->importFromFlightAware();
21 21
 }
22 22
 ?>
23 23
\ No newline at end of file
Please login to merge, or discard this patch.
scripts/check_data.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@
 block discarded – undo
5 5
 */
6 6
 require_once(dirname(__FILE__).'/../require/settings.php');
7 7
 if ($globalInstalled) {
8
-    echo '$globalInstalled must be set to FALSE in require/settings.php';
9
-    exit;
8
+	echo '$globalInstalled must be set to FALSE in require/settings.php';
9
+	exit;
10 10
 }
11 11
 
12 12
 require_once('../require/class.Connection.php');
Please login to merge, or discard this patch.
scripts/daemon-acars.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
12 12
 $schema = new Connection();
13 13
 if ($schema->latest() === false) {
14
-    echo "You MUST update to latest schema. Run install/index.php";
15
-    exit();
14
+	echo "You MUST update to latest schema. Run install/index.php";
15
+	exit();
16 16
 }
17 17
 
18 18
 $debug = true;
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
 date_default_timezone_set('UTC');
22 22
 // signal handler - playing nice with sockets and dump1090
23 23
 pcntl_signal(SIGINT,  function($signo) {
24
-    global $sock;
25
-    echo "\n\nctrl-c or kill signal received. Tidying up ... ";
26
-    socket_shutdown($sock, 0);
27
-    socket_close($sock);
28
-    die("Bye!\n");
24
+	global $sock;
25
+	echo "\n\nctrl-c or kill signal received. Tidying up ... ";
26
+	socket_shutdown($sock, 0);
27
+	socket_close($sock);
28
+	die("Bye!\n");
29 29
 });
30 30
 pcntl_signal_dispatch();
31 31
 
@@ -38,24 +38,24 @@  discard block
 block discarded – undo
38 38
 // Bind the source address
39 39
 if( !socket_bind($sock, $globalACARSHost , $globalACARSPort) )
40 40
 {
41
-    $errorcode = socket_last_error();
42
-    $errormsg = socket_strerror($errorcode);
41
+	$errorcode = socket_last_error();
42
+	$errormsg = socket_strerror($errorcode);
43 43
      
44
-    die("Could not bind socket : [$errorcode] $errormsg \n");
44
+	die("Could not bind socket : [$errorcode] $errormsg \n");
45 45
 }
46 46
 
47 47
 echo "LISTEN UDP MODE \n\n";
48 48
 while(1) {
49
-    $r = socket_recvfrom($sock, $buffer, 512, 0, $remote_ip, $remote_port);
50
-
51
-    // lets play nice and handle signals such as ctrl-c/kill properly
52
-    pcntl_signal_dispatch();
53
-    $dataFound = false;
54
-    //  (null) 2 23/02/2015 14:46:06 0 -16 X .D-AIPW ! 1L 7 M82A LH077P 010952342854:VP-MIBI+W+0)-V+(),GB1
55
-    echo $buffer."\n";
56
-    $ACARS->add(trim($buffer));
57
-    socket_sendto($sock, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
58
-    $ACARS->deleteLiveAcarsData();
49
+	$r = socket_recvfrom($sock, $buffer, 512, 0, $remote_ip, $remote_port);
50
+
51
+	// lets play nice and handle signals such as ctrl-c/kill properly
52
+	pcntl_signal_dispatch();
53
+	$dataFound = false;
54
+	//  (null) 2 23/02/2015 14:46:06 0 -16 X .D-AIPW ! 1L 7 M82A LH077P 010952342854:VP-MIBI+W+0)-V+(),GB1
55
+	echo $buffer."\n";
56
+	$ACARS->add(trim($buffer));
57
+	socket_sendto($sock, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
58
+	$ACARS->deleteLiveAcarsData();
59 59
 }
60 60
 pcntl_exec($_,$argv);
61 61
 ?>
Please login to merge, or discard this patch.
ident-statistics-registration.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@
 block discarded – undo
3 3
 require_once('require/class.Spotter.php');
4 4
 require_once('require/class.Language.php');
5 5
 if (!isset($_GET['ident'])) {
6
-        header('Location: '.$globalURL.'/ident');
7
-        die();
6
+		header('Location: '.$globalURL.'/ident');
7
+		die();
8 8
 }
9 9
 $Spotter = new Spotter();
10 10
 $ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING);
Please login to merge, or discard this patch.
sitemap.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@  discard block
 block discarded – undo
15 15
 		foreach($spotter_array as $spotter_item)
16 16
 		{
17 17
 			$output .= '<url>';
18
-			    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/flightid/'.$spotter_item['spotter_id'].'</loc>';
19
-			    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
20
-			    $output .= '<changefreq>weekly</changefreq>';
18
+				$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/flightid/'.$spotter_item['spotter_id'].'</loc>';
19
+				$output .= '<lastmod>'.date("c", time()).'</lastmod>';
20
+				$output .= '<changefreq>weekly</changefreq>';
21 21
 			$output .= '</url>';
22 22
 		}
23 23
 	$output .= '</urlset>';
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 		foreach($aircraft_types as $aircraft_item)
33 33
 		{
34 34
 			$output .= '<url>';
35
-			    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/aircraft/'.$aircraft_item['aircraft_icao'].'</loc>';
36
-			    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
37
-			    $output .= '<changefreq>daily</changefreq>';
35
+				$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/aircraft/'.$aircraft_item['aircraft_icao'].'</loc>';
36
+				$output .= '<lastmod>'.date("c", time()).'</lastmod>';
37
+				$output .= '<changefreq>daily</changefreq>';
38 38
 			$output .= '</url>';
39 39
 		}
40 40
 	$output .= '</urlset>';
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 		foreach($aircraft_registrations as $aircraft_item)
50 50
 		{
51 51
 			$output .= '<url>';
52
-			    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/registration/'.$aircraft_item['registration'].'</loc>';
53
-			    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
54
-			    $output .= '<changefreq>daily</changefreq>';
52
+				$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/registration/'.$aircraft_item['registration'].'</loc>';
53
+				$output .= '<lastmod>'.date("c", time()).'</lastmod>';
54
+				$output .= '<changefreq>daily</changefreq>';
55 55
 			$output .= '</url>';
56 56
 		}
57 57
 	$output .= '</urlset>';
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
 		foreach($airline_names as $airline_item)
66 66
 		{
67 67
 			$output .= '<url>';
68
-			    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/airline/'.$airline_item['airline_icao'].'</loc>';
69
-			    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
70
-			    $output .= '<changefreq>daily</changefreq>';
68
+				$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/airline/'.$airline_item['airline_icao'].'</loc>';
69
+				$output .= '<lastmod>'.date("c", time()).'</lastmod>';
70
+				$output .= '<changefreq>daily</changefreq>';
71 71
 			$output .= '</url>';
72 72
 		}
73 73
 	$output .= '</urlset>';
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
 		foreach($airport_names as $airport_item)
82 82
 		{
83 83
 			$output .= '<url>';
84
-			    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/airport/'.$airport_item['airport_icao'].'</loc>';
85
-			    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
86
-			    $output .= '<changefreq>daily</changefreq>';
84
+				$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/airport/'.$airport_item['airport_icao'].'</loc>';
85
+				$output .= '<lastmod>'.date("c", time()).'</lastmod>';
86
+				$output .= '<changefreq>daily</changefreq>';
87 87
 			$output .= '</url>';
88 88
 		}
89 89
 	$output .= '</urlset>';
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
 		foreach($manufacturer_names as $manufacturer_item)
98 98
 		{
99 99
 			$output .= '<url>';
100
-			    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/manufacturer/'.strtolower(str_replace(" ", "-", $manufacturer_item['aircraft_manufacturer'])).'</loc>';
101
-			    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
102
-			    $output .= '<changefreq>daily</changefreq>';
100
+				$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/manufacturer/'.strtolower(str_replace(" ", "-", $manufacturer_item['aircraft_manufacturer'])).'</loc>';
101
+				$output .= '<lastmod>'.date("c", time()).'</lastmod>';
102
+				$output .= '<changefreq>daily</changefreq>';
103 103
 			$output .= '</url>';
104 104
 		}
105 105
 	$output .= '</urlset>';
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
 		foreach($country_names as $country_item)
114 114
 		{
115 115
 			$output .= '<url>';
116
-			    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/country/'.strtolower(str_replace(" ", "-", $country_item['country'])).'</loc>';
117
-			    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
118
-			    $output .= '<changefreq>daily</changefreq>';
116
+				$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/country/'.strtolower(str_replace(" ", "-", $country_item['country'])).'</loc>';
117
+				$output .= '<lastmod>'.date("c", time()).'</lastmod>';
118
+				$output .= '<changefreq>daily</changefreq>';
119 119
 			$output .= '</url>';
120 120
 		}
121 121
 	$output .= '</urlset>';
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
 		{
131 131
 			if (ctype_alnum($ident_item['ident'])) {
132 132
 				$output .= '<url>';
133
-				    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/ident/'.$ident_item['ident'].'</loc>';
134
-				    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
135
-				    $output .= '<changefreq>daily</changefreq>';
133
+					$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/ident/'.$ident_item['ident'].'</loc>';
134
+					$output .= '<lastmod>'.date("c", time()).'</lastmod>';
135
+					$output .= '<changefreq>daily</changefreq>';
136 136
 				$output .= '</url>';
137 137
 			}
138 138
 		}
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
 		foreach($date_names as $date_item)
148 148
 		{
149 149
 			$output .= '<url>';
150
-			    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/date/'.date("Y-m-d", strtotime($date_item['date'])).'</loc>';
151
-			    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
152
-			    $output .= '<changefreq>daily</changefreq>';
150
+				$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/date/'.date("Y-m-d", strtotime($date_item['date'])).'</loc>';
151
+				$output .= '<lastmod>'.date("c", time()).'</lastmod>';
152
+				$output .= '<changefreq>daily</changefreq>';
153 153
 			$output .= '</url>';
154 154
 		}
155 155
 	$output .= '</urlset>';
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
 		foreach($route_names as $route_item)
164 164
 		{
165 165
 			$output .= '<url>';
166
-			    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/route/'.$route_item['airport_departure_icao'].'/'.$route_item['airport_arrival_icao'].'</loc>';
167
-			    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
168
-			    $output .= '<changefreq>daily</changefreq>';
166
+				$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/route/'.$route_item['airport_departure_icao'].'/'.$route_item['airport_arrival_icao'].'</loc>';
167
+				$output .= '<lastmod>'.date("c", time()).'</lastmod>';
168
+				$output .= '<changefreq>daily</changefreq>';
169 169
 			$output .= '</url>';
170 170
 		}
171 171
 	$output .= '</urlset>';
@@ -177,117 +177,117 @@  discard block
 block discarded – undo
177 177
 		
178 178
 		/* STATIC PAGES */
179 179
 		$output .= '<url>';
180
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/</loc>';
181
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
182
-		    $output .= '<changefreq>daily</changefreq>';
180
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/</loc>';
181
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
182
+			$output .= '<changefreq>daily</changefreq>';
183 183
 		$output .= '</url>';
184 184
 		$output .= '<url>';
185
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/latest</loc>';
186
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
187
-		    $output .= '<changefreq>daily</changefreq>';
185
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/latest</loc>';
186
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
187
+			$output .= '<changefreq>daily</changefreq>';
188 188
 		$output .= '</url>';
189 189
 		$output .= '<url>';
190
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/highlights</loc>';
191
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
192
-		    $output .= '<changefreq>daily</changefreq>';
190
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/highlights</loc>';
191
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
192
+			$output .= '<changefreq>daily</changefreq>';
193 193
 		$output .= '</url>';
194 194
 		$output .= '<url>';
195
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/aircraft</loc>';
196
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
197
-		    $output .= '<changefreq>daily</changefreq>';
195
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/aircraft</loc>';
196
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
197
+			$output .= '<changefreq>daily</changefreq>';
198 198
 		$output .= '</url>';
199 199
 		$output .= '<url>';
200
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/airline</loc>';
201
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
202
-		    $output .= '<changefreq>daily</changefreq>';
200
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/airline</loc>';
201
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
202
+			$output .= '<changefreq>daily</changefreq>';
203 203
 		$output .= '</url>';
204 204
 		$output .= '<url>';
205
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/airport</loc>';
206
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
207
-		    $output .= '<changefreq>daily</changefreq>';
205
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/airport</loc>';
206
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
207
+			$output .= '<changefreq>daily</changefreq>';
208 208
 		$output .= '</url>';
209 209
 		$output .= '<url>';
210
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/search</loc>';
211
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
212
-		    $output .= '<changefreq>daily</changefreq>';
210
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/search</loc>';
211
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
212
+			$output .= '<changefreq>daily</changefreq>';
213 213
 		$output .= '</url>';
214 214
 		$output .= '<url>';
215
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/about</loc>';
216
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
217
-		    $output .= '<changefreq>weekly</changefreq>';
215
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/about</loc>';
216
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
217
+			$output .= '<changefreq>weekly</changefreq>';
218 218
 		$output .= '</url>';
219 219
 		
220 220
 		
221 221
 		/* STATISTIC PAGES */
222 222
 		$output .= '<url>';
223
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/aircraft</loc>';
224
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
225
-		    $output .= '<changefreq>daily</changefreq>';
223
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/aircraft</loc>';
224
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
225
+			$output .= '<changefreq>daily</changefreq>';
226 226
 		$output .= '</url>';
227 227
 		$output .= '<url>';
228
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/registration</loc>';
229
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
230
-		    $output .= '<changefreq>daily</changefreq>';
228
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/registration</loc>';
229
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
230
+			$output .= '<changefreq>daily</changefreq>';
231 231
 		$output .= '</url>';
232 232
 		$output .= '<url>';
233
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/manufacturer</loc>';
234
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
235
-		    $output .= '<changefreq>daily</changefreq>';
233
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/manufacturer</loc>';
234
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
235
+			$output .= '<changefreq>daily</changefreq>';
236 236
 		$output .= '</url>';
237 237
 		$output .= '<url>';
238
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airline</loc>';
239
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
240
-		    $output .= '<changefreq>daily</changefreq>';
238
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airline</loc>';
239
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
240
+			$output .= '<changefreq>daily</changefreq>';
241 241
 		$output .= '</url>';
242 242
 		$output .= '<url>';
243
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airline-country</loc>';
244
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
245
-		    $output .= '<changefreq>daily</changefreq>';
243
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airline-country</loc>';
244
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
245
+			$output .= '<changefreq>daily</changefreq>';
246 246
 		$output .= '</url>';
247 247
 		$output .= '<url>';
248
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airport-departure</loc>';
249
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
250
-		    $output .= '<changefreq>daily</changefreq>';
248
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airport-departure</loc>';
249
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
250
+			$output .= '<changefreq>daily</changefreq>';
251 251
 		$output .= '</url>';
252 252
 		$output .= '<url>';
253
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airport-departure-country</loc>';
254
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
255
-		    $output .= '<changefreq>daily</changefreq>';
253
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airport-departure-country</loc>';
254
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
255
+			$output .= '<changefreq>daily</changefreq>';
256 256
 		$output .= '</url>';
257 257
 		$output .= '<url>';
258
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airport-arrival</loc>';
259
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
260
-		    $output .= '<changefreq>daily</changefreq>';
258
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airport-arrival</loc>';
259
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
260
+			$output .= '<changefreq>daily</changefreq>';
261 261
 		$output .= '</url>';
262 262
 		$output .= '<url>';
263
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airport-arrival-country</loc>';
264
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
265
-		    $output .= '<changefreq>daily</changefreq>';
263
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/airport-arrival-country</loc>';
264
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
265
+			$output .= '<changefreq>daily</changefreq>';
266 266
 		$output .= '</url>';
267 267
 		$output .= '<url>';
268
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/route-airport</loc>';
269
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
270
-		    $output .= '<changefreq>daily</changefreq>';
268
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/route-airport</loc>';
269
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
270
+			$output .= '<changefreq>daily</changefreq>';
271 271
 		$output .= '</url>';
272 272
 		$output .= '<url>';
273
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/route-waypoint</loc>';
274
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
275
-		    $output .= '<changefreq>daily</changefreq>';
273
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/route-waypoint</loc>';
274
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
275
+			$output .= '<changefreq>daily</changefreq>';
276 276
 		$output .= '</url>';
277 277
 		$output .= '<url>';
278
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/callsign</loc>';
279
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
280
-		    $output .= '<changefreq>daily</changefreq>';
278
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/callsign</loc>';
279
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
280
+			$output .= '<changefreq>daily</changefreq>';
281 281
 		$output .= '</url>';
282 282
 		$output .= '<url>';
283
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/date</loc>';
284
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
285
-		    $output .= '<changefreq>daily</changefreq>';
283
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/date</loc>';
284
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
285
+			$output .= '<changefreq>daily</changefreq>';
286 286
 		$output .= '</url>';
287 287
 		$output .= '<url>';
288
-		    $output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/time</loc>';
289
-		    $output .= '<lastmod>'.date("c", time()).'</lastmod>';
290
-		    $output .= '<changefreq>daily</changefreq>';
288
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/statistics/time</loc>';
289
+			$output .= '<lastmod>'.date("c", time()).'</lastmod>';
290
+			$output .= '<changefreq>daily</changefreq>';
291 291
 		$output .= '</url>';
292 292
 	$output .= '</urlset>';
293 293
 	
@@ -297,37 +297,37 @@  discard block
 block discarded – undo
297 297
 	$output .= '<?xml version="1.0" encoding="UTF-8"?>';
298 298
 	$output .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
299 299
 		$output .= '<sitemap>';
300
-	    	$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/static</loc>';
300
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/static</loc>';
301 301
 		$output .= '</sitemap>';
302 302
 		$output .= '<sitemap>';
303
-	    	$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/flight</loc>';
303
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/flight</loc>';
304 304
 		$output .= '</sitemap>';
305 305
 		$output .= '<sitemap>';
306
-	    	$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/aircraft</loc>';
306
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/aircraft</loc>';
307 307
 		$output .= '</sitemap>';
308 308
 		$output .= '<sitemap>';
309
-	    	$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/registration</loc>';
309
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/registration</loc>';
310 310
 		$output .= '</sitemap>';
311 311
 		$output .= '<sitemap>';
312
-	    	$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/airline</loc>';
312
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/airline</loc>';
313 313
 		$output .= '</sitemap>';
314 314
 		$output .= '<sitemap>';
315
-	    	$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/airport</loc>';
315
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/airport</loc>';
316 316
 		$output .= '</sitemap>';
317 317
 		$output .= '<sitemap>';
318
-	    	$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/manufacturer</loc>';
318
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/manufacturer</loc>';
319 319
 		$output .= '</sitemap>';
320 320
 		$output .= '<sitemap>';
321
-	    	$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/country</loc>';
321
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/country</loc>';
322 322
 		$output .= '</sitemap>';
323 323
 		$output .= '<sitemap>';
324
-	    	$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/ident</loc>';
324
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/ident</loc>';
325 325
 		$output .= '</sitemap>';
326 326
 		$output .= '<sitemap>';
327
-	    	$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/date</loc>';
327
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/date</loc>';
328 328
 		$output .= '</sitemap>';
329 329
 		$output .= '<sitemap>';
330
-	    	$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/route</loc>';
330
+			$output .= '<loc>'.'http://'.$_SERVER['HTTP_HOST'].$globalURL.'/sitemap/route</loc>';
331 331
 		$output .= '</sitemap>';
332 332
 	$output .= '</sitemapindex>';
333 333
 	
Please login to merge, or discard this patch.
require/libs/Predict/Predict.php 1 patch
Indentation   +791 added lines, -791 removed lines patch added patch discarded remove patch
@@ -52,824 +52,824 @@
 block discarded – undo
52 52
  */
53 53
 class Predict
54 54
 {
55
-    const de2ra    =  1.74532925E-2;   /* Degrees to Radians */
56
-    const pi       =  3.1415926535898; /* Pi */
57
-    const pio2     =  1.5707963267949; /* Pi/2 */
58
-    const x3pio2   =  4.71238898;      /* 3*Pi/2 */
59
-    const twopi    =  6.2831853071796; /* 2*Pi  */
60
-    const e6a      =  1.0E-6;
61
-    const tothrd   =  6.6666667E-1;    /* 2/3 */
62
-    const xj2      =  1.0826158E-3;    /* J2 Harmonic */
63
-    const xj3      = -2.53881E-6;      /* J3 Harmonic */
64
-    const xj4      = -1.65597E-6;      /* J4 Harmonic */
65
-    const xke      =  7.43669161E-2;
66
-    const xkmper   =  6.378135E3;      /* Earth radius km */
67
-    const xmnpda   =  1.44E3;          /* Minutes per day */
68
-    const km2mi    =  0.621371;        /* Kilometers per Mile */
69
-    const ae       =  1.0;
70
-    const ck2      =  5.413079E-4;
71
-    const ck4      =  6.209887E-7;
72
-    const __f      =  3.352779E-3;
73
-    const ge       =  3.986008E5;
74
-    const __s__    =  1.012229;
75
-    const qoms2t   =  1.880279E-09;
76
-    const secday   =  8.6400E4;        /* Seconds per day */
77
-    const omega_E  =  1.0027379;
78
-    const omega_ER =  6.3003879;
79
-    const zns      =  1.19459E-5;
80
-    const c1ss     =  2.9864797E-6;
81
-    const zes      =  1.675E-2;
82
-    const znl      =  1.5835218E-4;
83
-    const c1l      =  4.7968065E-7;
84
-    const zel      =  5.490E-2;
85
-    const zcosis   =  9.1744867E-1;
86
-    const zsinis   =  3.9785416E-1;
87
-    const zsings   = -9.8088458E-1;
88
-    const zcosgs   =  1.945905E-1;
89
-    const zcoshs   =  1;
90
-    const zsinhs   =  0;
91
-    const q22      =  1.7891679E-6;
92
-    const q31      =  2.1460748E-6;
93
-    const q33      =  2.2123015E-7;
94
-    const g22      =  5.7686396;
95
-    const g32      =  9.5240898E-1;
96
-    const g44      =  1.8014998;
97
-    const g52      =  1.0508330;
98
-    const g54      =  4.4108898;
99
-    const root22   =  1.7891679E-6;
100
-    const root32   =  3.7393792E-7;
101
-    const root44   =  7.3636953E-9;
102
-    const root52   =  1.1428639E-7;
103
-    const root54   =  2.1765803E-9;
104
-    const thdt     =  4.3752691E-3;
105
-    const rho      =  1.5696615E-1;
106
-    const mfactor  =  7.292115E-5;
107
-    const __sr__   =  6.96000E5;      /*Solar radius - kilometers (IAU 76)*/
108
-    const AU       =  1.49597870E8;   /*Astronomical unit - kilometers (IAU 76)*/
109
-
110
-    /* visibility constants */
111
-    const SAT_VIS_NONE     = 0;
112
-    const SAT_VIS_VISIBLE  = 1;
113
-    const SAT_VIS_DAYLIGHT = 2;
114
-    const SAT_VIS_ECLIPSED = 3;
115
-
116
-    /* preferences */
117
-    public $minEle     = 10; // Minimum elevation
118
-    public $timeRes    = 10; // Pass details: time resolution
119
-    public $numEntries = 20; // Pass details: number of entries
120
-    public $threshold  = -6; // Twilight threshold
121
-
122
-    /**
123
-     *  Predict the next pass.
124
-     *
125
-     * This function simply wraps the get_pass function using the current time
126
-     * as parameter.
127
-     *
128
-     * Note: the data in sat will be corrupt (future) and must be refreshed
129
-     *       by the caller, if the caller will need it later on (eg. if the caller
130
-     *       is GtkSatList).
131
-     *
132
-     * @param Predict_Sat $sat   The satellite data.
133
-     * @param Predict_QTH $qth   The observer data.
134
-     * @param int         $maxdt The maximum number of days to look ahead.
135
-     *
136
-     * @return Predict_Pass Pointer instance or NULL if no pass can be
137
-     *         found.
138
-     */
139
-    public function get_next_pass(Predict_Sat $sat, Predict_QTH $qth, $maxdt)
140
-    {
141
-        /* get the current time and call the get_pass function */
142
-        $now = Predict_Time::get_current_daynum();
143
-
144
-        return $this->get_pass($sat, $qth, $now, $maxdt);
145
-    }
146
-
147
-    /** Predict first pass after a certain time.
148
-     *
149
-     *  @param Predict_Sat $sat   The satellite data.
150
-     *  @param Predict_QTH $qth   The observer's location data.
151
-     *  @param float       $start Starting time.
152
-     *  @param int         $maxdt The maximum number of days to look ahead (0 for no limit).
153
-     *
154
-     *  @return Predict_Pass or NULL if there was an error.
155
-     *
156
-     * This function will find the first upcoming pass with AOS no earlier than
157
-     * t = start and no later than t = (start+maxdt).
158
-     *
159
-     *  note For no time limit use maxdt = 0.0
160
-     *
161
-     *  note the data in sat will be corrupt (future) and must be refreshed
162
-     *       by the caller, if the caller will need it later on
163
-     */
164
-    public function get_pass(Predict_Sat $sat_in, Predict_QTH $qth, $start, $maxdt)
165
-    {
166
-        $aos = 0.0;    /* time of AOS */
167
-        $tca = 0.0;    /* time of TCA */
168
-        $los = 0.0;    /* time of LOS */
169
-        $dt = 0.0;     /* time diff */
170
-        $step = 0.0;   /* time step */
171
-        $t0 = $start;
172
-        $tres = 0.0;   /* required time resolution */
173
-        $max_el = 0.0; /* maximum elevation */
174
-        $pass = null;
175
-        $detail = null;
176
-        $done = false;
177
-        $iter = 0;      /* number of iterations */
178
-        /* FIXME: watchdog */
179
-
180
-        /*copy sat_in to a working structure*/
181
-        $sat         = clone $sat_in;
182
-        $sat_working = clone $sat_in;
183
-
184
-        /* get time resolution; sat-cfg stores it in seconds */
185
-        $tres = $this->timeRes / 86400.0;
186
-
187
-        /* loop until we find a pass with elevation > SAT_CFG_INT_PRED_MIN_EL
55
+	const de2ra    =  1.74532925E-2;   /* Degrees to Radians */
56
+	const pi       =  3.1415926535898; /* Pi */
57
+	const pio2     =  1.5707963267949; /* Pi/2 */
58
+	const x3pio2   =  4.71238898;      /* 3*Pi/2 */
59
+	const twopi    =  6.2831853071796; /* 2*Pi  */
60
+	const e6a      =  1.0E-6;
61
+	const tothrd   =  6.6666667E-1;    /* 2/3 */
62
+	const xj2      =  1.0826158E-3;    /* J2 Harmonic */
63
+	const xj3      = -2.53881E-6;      /* J3 Harmonic */
64
+	const xj4      = -1.65597E-6;      /* J4 Harmonic */
65
+	const xke      =  7.43669161E-2;
66
+	const xkmper   =  6.378135E3;      /* Earth radius km */
67
+	const xmnpda   =  1.44E3;          /* Minutes per day */
68
+	const km2mi    =  0.621371;        /* Kilometers per Mile */
69
+	const ae       =  1.0;
70
+	const ck2      =  5.413079E-4;
71
+	const ck4      =  6.209887E-7;
72
+	const __f      =  3.352779E-3;
73
+	const ge       =  3.986008E5;
74
+	const __s__    =  1.012229;
75
+	const qoms2t   =  1.880279E-09;
76
+	const secday   =  8.6400E4;        /* Seconds per day */
77
+	const omega_E  =  1.0027379;
78
+	const omega_ER =  6.3003879;
79
+	const zns      =  1.19459E-5;
80
+	const c1ss     =  2.9864797E-6;
81
+	const zes      =  1.675E-2;
82
+	const znl      =  1.5835218E-4;
83
+	const c1l      =  4.7968065E-7;
84
+	const zel      =  5.490E-2;
85
+	const zcosis   =  9.1744867E-1;
86
+	const zsinis   =  3.9785416E-1;
87
+	const zsings   = -9.8088458E-1;
88
+	const zcosgs   =  1.945905E-1;
89
+	const zcoshs   =  1;
90
+	const zsinhs   =  0;
91
+	const q22      =  1.7891679E-6;
92
+	const q31      =  2.1460748E-6;
93
+	const q33      =  2.2123015E-7;
94
+	const g22      =  5.7686396;
95
+	const g32      =  9.5240898E-1;
96
+	const g44      =  1.8014998;
97
+	const g52      =  1.0508330;
98
+	const g54      =  4.4108898;
99
+	const root22   =  1.7891679E-6;
100
+	const root32   =  3.7393792E-7;
101
+	const root44   =  7.3636953E-9;
102
+	const root52   =  1.1428639E-7;
103
+	const root54   =  2.1765803E-9;
104
+	const thdt     =  4.3752691E-3;
105
+	const rho      =  1.5696615E-1;
106
+	const mfactor  =  7.292115E-5;
107
+	const __sr__   =  6.96000E5;      /*Solar radius - kilometers (IAU 76)*/
108
+	const AU       =  1.49597870E8;   /*Astronomical unit - kilometers (IAU 76)*/
109
+
110
+	/* visibility constants */
111
+	const SAT_VIS_NONE     = 0;
112
+	const SAT_VIS_VISIBLE  = 1;
113
+	const SAT_VIS_DAYLIGHT = 2;
114
+	const SAT_VIS_ECLIPSED = 3;
115
+
116
+	/* preferences */
117
+	public $minEle     = 10; // Minimum elevation
118
+	public $timeRes    = 10; // Pass details: time resolution
119
+	public $numEntries = 20; // Pass details: number of entries
120
+	public $threshold  = -6; // Twilight threshold
121
+
122
+	/**
123
+	 *  Predict the next pass.
124
+	 *
125
+	 * This function simply wraps the get_pass function using the current time
126
+	 * as parameter.
127
+	 *
128
+	 * Note: the data in sat will be corrupt (future) and must be refreshed
129
+	 *       by the caller, if the caller will need it later on (eg. if the caller
130
+	 *       is GtkSatList).
131
+	 *
132
+	 * @param Predict_Sat $sat   The satellite data.
133
+	 * @param Predict_QTH $qth   The observer data.
134
+	 * @param int         $maxdt The maximum number of days to look ahead.
135
+	 *
136
+	 * @return Predict_Pass Pointer instance or NULL if no pass can be
137
+	 *         found.
138
+	 */
139
+	public function get_next_pass(Predict_Sat $sat, Predict_QTH $qth, $maxdt)
140
+	{
141
+		/* get the current time and call the get_pass function */
142
+		$now = Predict_Time::get_current_daynum();
143
+
144
+		return $this->get_pass($sat, $qth, $now, $maxdt);
145
+	}
146
+
147
+	/** Predict first pass after a certain time.
148
+	 *
149
+	 *  @param Predict_Sat $sat   The satellite data.
150
+	 *  @param Predict_QTH $qth   The observer's location data.
151
+	 *  @param float       $start Starting time.
152
+	 *  @param int         $maxdt The maximum number of days to look ahead (0 for no limit).
153
+	 *
154
+	 *  @return Predict_Pass or NULL if there was an error.
155
+	 *
156
+	 * This function will find the first upcoming pass with AOS no earlier than
157
+	 * t = start and no later than t = (start+maxdt).
158
+	 *
159
+	 *  note For no time limit use maxdt = 0.0
160
+	 *
161
+	 *  note the data in sat will be corrupt (future) and must be refreshed
162
+	 *       by the caller, if the caller will need it later on
163
+	 */
164
+	public function get_pass(Predict_Sat $sat_in, Predict_QTH $qth, $start, $maxdt)
165
+	{
166
+		$aos = 0.0;    /* time of AOS */
167
+		$tca = 0.0;    /* time of TCA */
168
+		$los = 0.0;    /* time of LOS */
169
+		$dt = 0.0;     /* time diff */
170
+		$step = 0.0;   /* time step */
171
+		$t0 = $start;
172
+		$tres = 0.0;   /* required time resolution */
173
+		$max_el = 0.0; /* maximum elevation */
174
+		$pass = null;
175
+		$detail = null;
176
+		$done = false;
177
+		$iter = 0;      /* number of iterations */
178
+		/* FIXME: watchdog */
179
+
180
+		/*copy sat_in to a working structure*/
181
+		$sat         = clone $sat_in;
182
+		$sat_working = clone $sat_in;
183
+
184
+		/* get time resolution; sat-cfg stores it in seconds */
185
+		$tres = $this->timeRes / 86400.0;
186
+
187
+		/* loop until we find a pass with elevation > SAT_CFG_INT_PRED_MIN_EL
188 188
             or we run out of time
189 189
             FIXME: we should have a safety break
190 190
         */
191
-        while (!$done) {
192
-            /* Find los of next pass or of current pass */
193
-            $los = $this->find_los($sat, $qth, $t0, $maxdt); // See if a pass is ongoing
194
-            $aos = $this->find_aos($sat, $qth, $t0, $maxdt);
195
-            /* sat_log_log(SAT_LOG_LEVEL_MSG, "%s:%s:%d: found aos %f and los %f for t0=%f", */
196
-            /*          __FILE__,  */
197
-            /*          __FUNCTION__, */
198
-            /*          __LINE__, */
199
-            /*          aos, */
200
-            /*          los,  */
201
-            /*          t0); */
202
-            if ($aos > $los) {
203
-                // los is from an currently happening pass, find previous aos
204
-                $aos = $this->find_prev_aos($sat, $qth, $t0);
205
-            }
206
-
207
-            /* aos = 0.0 means no aos */
208
-            if ($aos == 0.0) {
209
-                $done = true;
210
-            } else if (($maxdt > 0.0) && ($aos > ($start + $maxdt)) ) {
211
-                /* check whether we are within time limits;
191
+		while (!$done) {
192
+			/* Find los of next pass or of current pass */
193
+			$los = $this->find_los($sat, $qth, $t0, $maxdt); // See if a pass is ongoing
194
+			$aos = $this->find_aos($sat, $qth, $t0, $maxdt);
195
+			/* sat_log_log(SAT_LOG_LEVEL_MSG, "%s:%s:%d: found aos %f and los %f for t0=%f", */
196
+			/*          __FILE__,  */
197
+			/*          __FUNCTION__, */
198
+			/*          __LINE__, */
199
+			/*          aos, */
200
+			/*          los,  */
201
+			/*          t0); */
202
+			if ($aos > $los) {
203
+				// los is from an currently happening pass, find previous aos
204
+				$aos = $this->find_prev_aos($sat, $qth, $t0);
205
+			}
206
+
207
+			/* aos = 0.0 means no aos */
208
+			if ($aos == 0.0) {
209
+				$done = true;
210
+			} else if (($maxdt > 0.0) && ($aos > ($start + $maxdt)) ) {
211
+				/* check whether we are within time limits;
212 212
                     maxdt = 0 mean no time limit.
213 213
                 */
214
-                $done = true;
215
-            } else {
216
-                //los = find_los (sat, qth, aos + 0.001, maxdt); // +1.5 min later
217
-                $dt = $los - $aos;
214
+				$done = true;
215
+			} else {
216
+				//los = find_los (sat, qth, aos + 0.001, maxdt); // +1.5 min later
217
+				$dt = $los - $aos;
218 218
 
219
-                /* get time step, which will give us the max number of entries */
220
-                $step = $dt / $this->numEntries;
219
+				/* get time step, which will give us the max number of entries */
220
+				$step = $dt / $this->numEntries;
221 221
 
222
-                /* but if this is smaller than the required resolution
222
+				/* but if this is smaller than the required resolution
223 223
                     we go with the resolution
224 224
                 */
225
-                if ($step < $tres) {
226
-                    $step = $tres;
227
-                }
228
-
229
-                /* create a pass_t entry; FIXME: g_try_new in 2.8 */
230
-                $pass = new Predict_Pass();
231
-
232
-                $pass->aos      = $aos;
233
-                $pass->los      = $los;
234
-                $pass->max_el   = 0.0;
235
-                $pass->aos_az   = 0.0;
236
-                $pass->los_az   = 0.0;
237
-                $pass->maxel_az = 0.0;
238
-                $pass->vis      = '---';
239
-                $pass->satname  = $sat->nickname;
240
-                $pass->details  = array();
241
-
242
-                /* iterate over each time step */
243
-                for ($t = $pass->aos; $t <= $pass->los; $t += $step) {
244
-
245
-                    /* calculate satellite data */
246
-                    $this->predict_calc($sat, $qth, $t);
247
-
248
-                    /* in the first iter we want to store
225
+				if ($step < $tres) {
226
+					$step = $tres;
227
+				}
228
+
229
+				/* create a pass_t entry; FIXME: g_try_new in 2.8 */
230
+				$pass = new Predict_Pass();
231
+
232
+				$pass->aos      = $aos;
233
+				$pass->los      = $los;
234
+				$pass->max_el   = 0.0;
235
+				$pass->aos_az   = 0.0;
236
+				$pass->los_az   = 0.0;
237
+				$pass->maxel_az = 0.0;
238
+				$pass->vis      = '---';
239
+				$pass->satname  = $sat->nickname;
240
+				$pass->details  = array();
241
+
242
+				/* iterate over each time step */
243
+				for ($t = $pass->aos; $t <= $pass->los; $t += $step) {
244
+
245
+					/* calculate satellite data */
246
+					$this->predict_calc($sat, $qth, $t);
247
+
248
+					/* in the first iter we want to store
249 249
                         pass->aos_az
250 250
                     */
251
-                    if ($t == $pass->aos) {
252
-                        $pass->aos_az = $sat->az;
253
-                        $pass->orbit  = $sat->orbit;
254
-                    }
255
-
256
-                    /* append details to sat->details */
257
-                    $detail             = new Predict_PassDetail();
258
-                    $detail->time       = $t;
259
-                    $detail->pos->x     = $sat->pos->x;
260
-                    $detail->pos->y     = $sat->pos->y;
261
-                    $detail->pos->z     = $sat->pos->z;
262
-                    $detail->pos->w     = $sat->pos->w;
263
-                    $detail->vel->x     = $sat->vel->x;
264
-                    $detail->vel->y     = $sat->vel->y;
265
-                    $detail->vel->z     = $sat->vel->z;
266
-                    $detail->vel->w     = $sat->vel->w;
267
-                    $detail->velo       = $sat->velo;
268
-                    $detail->az         = $sat->az;
269
-                    $detail->el         = $sat->el;
270
-                    $detail->range      = $sat->range;
271
-                    $detail->range_rate = $sat->range_rate;
272
-                    $detail->lat        = $sat->ssplat;
273
-                    $detail->lon        = $sat->ssplon;
274
-                    $detail->alt        = $sat->alt;
275
-                    $detail->ma         = $sat->ma;
276
-                    $detail->phase      = $sat->phase;
277
-                    $detail->footprint  = $sat->footprint;
278
-                    $detail->orbit      = $sat->orbit;
279
-                    $detail->vis        = $this->get_sat_vis($sat, $qth, $t);
280
-
281
-                    /* also store visibility "bit" */
282
-                    switch ($detail->vis) {
283
-                        case self::SAT_VIS_VISIBLE:
284
-                            $pass->vis[0] = 'V';
285
-                            break;
286
-                        case self::SAT_VIS_DAYLIGHT:
287
-                            $pass->vis[1] = 'D';
288
-                            break;
289
-                        case self::SAT_VIS_ECLIPSED:
290
-                            $pass->vis[2] = 'E';
291
-                            break;
292
-                        default:
293
-                            break;
294
-                    }
295
-
296
-                    // Using an array, no need to prepend and reverse the list
297
-                    // as gpredict does
298
-                    $pass->details[] = $detail;
299
-
300
-                    // Look up apparent magnitude if this is a visible pass
301
-                    if ($detail->vis === self::SAT_VIS_VISIBLE) {
302
-                        $apmag = $sat->calculateApparentMagnitude($t, $qth);
303
-                        if ($pass->max_apparent_magnitude === null || $apmag < $pass->max_apparent_magnitude) {
304
-                            $pass->max_apparent_magnitude = $apmag;
305
-                        }
306
-                    }
307
-
308
-                    /* store elevation if greater than the
251
+					if ($t == $pass->aos) {
252
+						$pass->aos_az = $sat->az;
253
+						$pass->orbit  = $sat->orbit;
254
+					}
255
+
256
+					/* append details to sat->details */
257
+					$detail             = new Predict_PassDetail();
258
+					$detail->time       = $t;
259
+					$detail->pos->x     = $sat->pos->x;
260
+					$detail->pos->y     = $sat->pos->y;
261
+					$detail->pos->z     = $sat->pos->z;
262
+					$detail->pos->w     = $sat->pos->w;
263
+					$detail->vel->x     = $sat->vel->x;
264
+					$detail->vel->y     = $sat->vel->y;
265
+					$detail->vel->z     = $sat->vel->z;
266
+					$detail->vel->w     = $sat->vel->w;
267
+					$detail->velo       = $sat->velo;
268
+					$detail->az         = $sat->az;
269
+					$detail->el         = $sat->el;
270
+					$detail->range      = $sat->range;
271
+					$detail->range_rate = $sat->range_rate;
272
+					$detail->lat        = $sat->ssplat;
273
+					$detail->lon        = $sat->ssplon;
274
+					$detail->alt        = $sat->alt;
275
+					$detail->ma         = $sat->ma;
276
+					$detail->phase      = $sat->phase;
277
+					$detail->footprint  = $sat->footprint;
278
+					$detail->orbit      = $sat->orbit;
279
+					$detail->vis        = $this->get_sat_vis($sat, $qth, $t);
280
+
281
+					/* also store visibility "bit" */
282
+					switch ($detail->vis) {
283
+						case self::SAT_VIS_VISIBLE:
284
+							$pass->vis[0] = 'V';
285
+							break;
286
+						case self::SAT_VIS_DAYLIGHT:
287
+							$pass->vis[1] = 'D';
288
+							break;
289
+						case self::SAT_VIS_ECLIPSED:
290
+							$pass->vis[2] = 'E';
291
+							break;
292
+						default:
293
+							break;
294
+					}
295
+
296
+					// Using an array, no need to prepend and reverse the list
297
+					// as gpredict does
298
+					$pass->details[] = $detail;
299
+
300
+					// Look up apparent magnitude if this is a visible pass
301
+					if ($detail->vis === self::SAT_VIS_VISIBLE) {
302
+						$apmag = $sat->calculateApparentMagnitude($t, $qth);
303
+						if ($pass->max_apparent_magnitude === null || $apmag < $pass->max_apparent_magnitude) {
304
+							$pass->max_apparent_magnitude = $apmag;
305
+						}
306
+					}
307
+
308
+					/* store elevation if greater than the
309 309
                         previously stored one
310 310
                     */
311
-                    if ($sat->el > $max_el) {
312
-                        $max_el         = $sat->el;
313
-                        $tca            = $t;
314
-                        $pass->maxel_az = $sat->az;
315
-                    }
316
-
317
-                    /*     g_print ("TIME: %f\tAZ: %f\tEL: %f (MAX: %f)\n", */
318
-                    /*           t, sat->az, sat->el, max_el); */
319
-                }
320
-
321
-                /* calculate satellite data */
322
-                $this->predict_calc($sat, $qth, $pass->los);
323
-                /* store los_az, max_el and tca */
324
-                $pass->los_az = $sat->az;
325
-                $pass->max_el = $max_el;
326
-                $pass->tca    = $tca;
327
-
328
-                /* check whether this pass is good */
329
-                if ($max_el >= $this->minEle) {
330
-                    $done = true;
331
-                } else {
332
-                    $done = false;
333
-                    $t0 = $los + 0.014; // +20 min
334
-                    $pass = null;
335
-                }
336
-
337
-                $iter++;
338
-            }
339
-        }
340
-
341
-        return $pass;
342
-    }
343
-
344
-    /**
345
-     * Calculate satellite visibility.
346
-     *
347
-     * @param Predict_Sat $sat     The satellite structure.
348
-     * @param Predict_QTH $qth     The QTH
349
-     * @param float       $jul_utc The time at which the visibility should be calculated.
350
-     *
351
-     * @return int The visiblity constant, 0, 1, 2, or 3 (see above)
352
-     */
353
-    public function get_sat_vis(Predict_Sat $sat, Predict_QTH $qth, $jul_utc)
354
-    {
355
-        /* gboolean sat_sun_status;
311
+					if ($sat->el > $max_el) {
312
+						$max_el         = $sat->el;
313
+						$tca            = $t;
314
+						$pass->maxel_az = $sat->az;
315
+					}
316
+
317
+					/*     g_print ("TIME: %f\tAZ: %f\tEL: %f (MAX: %f)\n", */
318
+					/*           t, sat->az, sat->el, max_el); */
319
+				}
320
+
321
+				/* calculate satellite data */
322
+				$this->predict_calc($sat, $qth, $pass->los);
323
+				/* store los_az, max_el and tca */
324
+				$pass->los_az = $sat->az;
325
+				$pass->max_el = $max_el;
326
+				$pass->tca    = $tca;
327
+
328
+				/* check whether this pass is good */
329
+				if ($max_el >= $this->minEle) {
330
+					$done = true;
331
+				} else {
332
+					$done = false;
333
+					$t0 = $los + 0.014; // +20 min
334
+					$pass = null;
335
+				}
336
+
337
+				$iter++;
338
+			}
339
+		}
340
+
341
+		return $pass;
342
+	}
343
+
344
+	/**
345
+	 * Calculate satellite visibility.
346
+	 *
347
+	 * @param Predict_Sat $sat     The satellite structure.
348
+	 * @param Predict_QTH $qth     The QTH
349
+	 * @param float       $jul_utc The time at which the visibility should be calculated.
350
+	 *
351
+	 * @return int The visiblity constant, 0, 1, 2, or 3 (see above)
352
+	 */
353
+	public function get_sat_vis(Predict_Sat $sat, Predict_QTH $qth, $jul_utc)
354
+	{
355
+		/* gboolean sat_sun_status;
356 356
         gdouble  sun_el;
357 357
         gdouble  threshold;
358 358
         gdouble  eclipse_depth;
359 359
         sat_vis_t vis = SAT_VIS_NONE; */
360 360
 
361
-        $eclipse_depth  = 0.0;
362
-        $zero_vector    = new Predict_Vector();
363
-        $obs_geodetic   = new Predict_Geodetic();
364
-
365
-        /* Solar ECI position vector  */
366
-        $solar_vector = new Predict_Vector();
367
-
368
-        /* Solar observed az and el vector  */
369
-        $solar_set = new Predict_ObsSet();
370
-
371
-        /* FIXME: could be passed as parameter */
372
-        $obs_geodetic->lon   = $qth->lon * self::de2ra;
373
-        $obs_geodetic->lat   = $qth->lat * self::de2ra;
374
-        $obs_geodetic->alt   = $qth->alt / 1000.0;
375
-        $obs_geodetic->theta = 0;
376
-
377
-        Predict_Solar::Calculate_Solar_Position($jul_utc, $solar_vector);
378
-        Predict_SGPObs::Calculate_Obs($jul_utc, $solar_vector, $zero_vector, $obs_geodetic, $solar_set);
379
-
380
-        if (Predict_Solar::Sat_Eclipsed($sat->pos, $solar_vector, $eclipse_depth)) {
381
-            /* satellite is eclipsed */
382
-            $sat_sun_status = false;
383
-        } else {
384
-            /* satellite in sunlight => may be visible */
385
-            $sat_sun_status = true;
386
-        }
387
-
388
-        if ($sat_sun_status) {
389
-            $sun_el = Predict_Math::Degrees($solar_set->el);
390
-
391
-            if ($sun_el <= $this->threshold && $sat->el >= 0.0) {
392
-                $vis = self::SAT_VIS_VISIBLE;
393
-            } else {
394
-                $vis = self::SAT_VIS_DAYLIGHT;
395
-            }
396
-        } else {
397
-            $vis = self::SAT_VIS_ECLIPSED;
398
-        }
399
-
400
-        return $vis;
401
-    }
402
-
403
-    /** Find the AOS time of the next pass.
404
-     *  @author Alexandru Csete, OZ9AEC
405
-     *  @author John A. Magliacane, KD2BD
406
-     *  @param Predict_Sat $sat   The satellite data.
407
-     *  @param Predict_QTH $qth   The observer's location (QTH) data.
408
-     *  @param float       $start The julian date where calculation should start.
409
-     *  @param int         $maxdt The upper time limit in days (0.0 = no limit)
410
-     *  @return The julain date of the next AOS or 0.0 if the satellite has no AOS.
411
-     *
412
-     * This function finds the time of AOS for the first coming pass taking place
413
-     * no earlier that start.
414
-     * If the satellite is currently within range, the function first calls
415
-     * find_los to get the next LOS time. Then the calculations are done using
416
-     * the new start time.
417
-     *
418
-     */
419
-    public function find_aos(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt)
420
-    {
421
-        $t = $start;
422
-        $aostime = 0.0;
423
-
424
-
425
-        /* make sure current sat values are
361
+		$eclipse_depth  = 0.0;
362
+		$zero_vector    = new Predict_Vector();
363
+		$obs_geodetic   = new Predict_Geodetic();
364
+
365
+		/* Solar ECI position vector  */
366
+		$solar_vector = new Predict_Vector();
367
+
368
+		/* Solar observed az and el vector  */
369
+		$solar_set = new Predict_ObsSet();
370
+
371
+		/* FIXME: could be passed as parameter */
372
+		$obs_geodetic->lon   = $qth->lon * self::de2ra;
373
+		$obs_geodetic->lat   = $qth->lat * self::de2ra;
374
+		$obs_geodetic->alt   = $qth->alt / 1000.0;
375
+		$obs_geodetic->theta = 0;
376
+
377
+		Predict_Solar::Calculate_Solar_Position($jul_utc, $solar_vector);
378
+		Predict_SGPObs::Calculate_Obs($jul_utc, $solar_vector, $zero_vector, $obs_geodetic, $solar_set);
379
+
380
+		if (Predict_Solar::Sat_Eclipsed($sat->pos, $solar_vector, $eclipse_depth)) {
381
+			/* satellite is eclipsed */
382
+			$sat_sun_status = false;
383
+		} else {
384
+			/* satellite in sunlight => may be visible */
385
+			$sat_sun_status = true;
386
+		}
387
+
388
+		if ($sat_sun_status) {
389
+			$sun_el = Predict_Math::Degrees($solar_set->el);
390
+
391
+			if ($sun_el <= $this->threshold && $sat->el >= 0.0) {
392
+				$vis = self::SAT_VIS_VISIBLE;
393
+			} else {
394
+				$vis = self::SAT_VIS_DAYLIGHT;
395
+			}
396
+		} else {
397
+			$vis = self::SAT_VIS_ECLIPSED;
398
+		}
399
+
400
+		return $vis;
401
+	}
402
+
403
+	/** Find the AOS time of the next pass.
404
+	 *  @author Alexandru Csete, OZ9AEC
405
+	 *  @author John A. Magliacane, KD2BD
406
+	 *  @param Predict_Sat $sat   The satellite data.
407
+	 *  @param Predict_QTH $qth   The observer's location (QTH) data.
408
+	 *  @param float       $start The julian date where calculation should start.
409
+	 *  @param int         $maxdt The upper time limit in days (0.0 = no limit)
410
+	 *  @return The julain date of the next AOS or 0.0 if the satellite has no AOS.
411
+	 *
412
+	 * This function finds the time of AOS for the first coming pass taking place
413
+	 * no earlier that start.
414
+	 * If the satellite is currently within range, the function first calls
415
+	 * find_los to get the next LOS time. Then the calculations are done using
416
+	 * the new start time.
417
+	 *
418
+	 */
419
+	public function find_aos(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt)
420
+	{
421
+		$t = $start;
422
+		$aostime = 0.0;
423
+
424
+
425
+		/* make sure current sat values are
426 426
             in sync with the time
427 427
         */
428
-        $this->predict_calc($sat, $qth, $start);
429
-
430
-        /* check whether satellite has aos */
431
-        if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
432
-            ($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
433
-            !$this->has_aos($sat, $qth)) {
434
-
435
-            return 0.0;
436
-        }
437
-
438
-        if ($sat->el > 0.0) {
439
-            $t = $this->find_los($sat, $qth, $start, $maxdt) + 0.014; // +20 min
440
-        }
441
-
442
-        /* invalid time (potentially returned by find_los) */
443
-        if ($t < 0.1) {
444
-            return 0.0;
445
-        }
446
-
447
-        /* update satellite data */
448
-        $this->predict_calc($sat, $qth, $t);
449
-
450
-        /* use upper time limit */
451
-        if ($maxdt > 0.0) {
452
-
453
-            /* coarse time steps */
454
-            while (($sat->el < -1.0) && ($t <= ($start + $maxdt))) {
455
-                $t -= 0.00035 * ($sat->el * (($sat->alt / 8400.0) + 0.46) - 2.0);
456
-                $this->predict_calc($sat, $qth, $t);
457
-            }
458
-
459
-            /* fine steps */
460
-            while (($aostime == 0.0) && ($t <= ($start + $maxdt))) {
461
-
462
-                if (abs($sat->el) < 0.005) {
463
-                    $aostime = $t;
464
-                } else {
465
-                    $t -= $sat->el * sqrt($sat->alt) / 530000.0;
466
-                    $this->predict_calc($sat, $qth, $t);
467
-                }
468
-            }
469
-        } else {
470
-            /* don't use upper time limit */
471
-
472
-            /* coarse time steps */
473
-            while ($sat->el < -1.0) {
474
-
475
-                $t -= 0.00035 * ($sat->el * (($sat->alt / 8400.0) + 0.46) - 2.0);
476
-                $this->predict_calc($sat, $qth, $t);
477
-            }
478
-
479
-            /* fine steps */
480
-            while ($aostime == 0.0) {
481
-
482
-                if (abs($sat->el) < 0.005) {
483
-                    $aostime = $t;
484
-                } else {
485
-                    $t -= $sat->el * sqrt($sat->alt) / 530000.0;
486
-                    $this->predict_calc($sat, $qth, $t);
487
-                }
488
-
489
-            }
490
-        }
491
-
492
-        return $aostime;
493
-    }
494
-
495
-    /** SGP4SDP4 driver for doing AOS/LOS calculations.
496
-     *  @param Predict_Sat $sat The satellite data.
497
-     *  @param Predict_QTH $qth The QTH observer location data.
498
-     *  @param float       $t   The time for calculation (Julian Date)
499
-     *
500
-     */
501
-    public function predict_calc(Predict_Sat $sat, Predict_QTH $qth, $t)
502
-    {
503
-        $obs_set      = new Predict_ObsSet();
504
-        $sat_geodetic = new Predict_Geodetic();
505
-        $obs_geodetic = new Predict_Geodetic();
506
-
507
-        $obs_geodetic->lon   = $qth->lon * self::de2ra;
508
-        $obs_geodetic->lat   = $qth->lat * self::de2ra;
509
-        $obs_geodetic->alt   = $qth->alt / 1000.0;
510
-        $obs_geodetic->theta = 0;
511
-
512
-        $sat->jul_utc = $t;
513
-        $sat->tsince = ($sat->jul_utc - $sat->jul_epoch) * self::xmnpda;
514
-
515
-        /* call the norad routines according to the deep-space flag */
516
-        $sgpsdp = Predict_SGPSDP::getInstance($sat);
517
-        if ($sat->flags & Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG) {
518
-            $sgpsdp->SDP4($sat, $sat->tsince);
519
-        } else {
520
-            $sgpsdp->SGP4($sat, $sat->tsince);
521
-        }
522
-
523
-        Predict_Math::Convert_Sat_State($sat->pos, $sat->vel);
524
-
525
-        /* get the velocity of the satellite */
526
-        $sat->vel->w = sqrt($sat->vel->x * $sat->vel->x + $sat->vel->y * $sat->vel->y + $sat->vel->z * $sat->vel->z);
527
-        $sat->velo = $sat->vel->w;
528
-        Predict_SGPObs::Calculate_Obs($sat->jul_utc, $sat->pos, $sat->vel, $obs_geodetic, $obs_set);
529
-        Predict_SGPObs::Calculate_LatLonAlt($sat->jul_utc, $sat->pos, $sat_geodetic);
530
-
531
-        while ($sat_geodetic->lon < -self::pi) {
532
-            $sat_geodetic->lon += self::twopi;
533
-        }
534
-
535
-        while ($sat_geodetic->lon > (self::pi)) {
536
-            $sat_geodetic->lon -= self::twopi;
537
-        }
538
-
539
-        $sat->az = Predict_Math::Degrees($obs_set->az);
540
-        $sat->el = Predict_Math::Degrees($obs_set->el);
541
-        $sat->range = $obs_set->range;
542
-        $sat->range_rate = $obs_set->range_rate;
543
-        $sat->ssplat = Predict_Math::Degrees($sat_geodetic->lat);
544
-        $sat->ssplon = Predict_Math::Degrees($sat_geodetic->lon);
545
-        $sat->alt = $sat_geodetic->alt;
546
-        $sat->ma = Predict_Math::Degrees($sat->phase);
547
-        $sat->ma *= 256.0 / 360.0;
548
-        $sat->phase = Predict_Math::Degrees($sat->phase);
549
-
550
-        /* same formulas, but the one from predict is nicer */
551
-        //sat->footprint = 2.0 * xkmper * acos (xkmper/sat->pos.w);
552
-        $sat->footprint = 12756.33 * acos(self::xkmper / (self::xkmper + $sat->alt));
553
-        $age = $sat->jul_utc - $sat->jul_epoch;
554
-        $sat->orbit = floor(($sat->tle->xno * self::xmnpda / self::twopi +
555
-                        $age * $sat->tle->bstar * self::ae) * $age +
556
-                        $sat->tle->xmo / self::twopi) + $sat->tle->revnum - 1;
557
-    }
558
-
559
-    /** Find the LOS time of the next pass.
560
-     *  @author Alexandru Csete, OZ9AEC
561
-     *  @author John A. Magliacane, KD2BD
562
-     *  @param Predict_Sat $sat The satellite data.
563
-     *  @param Predict_QTH $qth The QTH observer location data.
564
-     *  @param float       $start The time where calculation should start. (Julian Date)
565
-     *  @param int         $maxdt The upper time limit in days (0.0 = no limit)
566
-     *  @return The time (julian date) of the next LOS or 0.0 if the satellite has no LOS.
567
-     *
568
-     * This function finds the time of LOS for the first coming pass taking place
569
-     * no earlier that start.
570
-     * If the satellite is currently out of range, the function first calls
571
-     * find_aos to get the next AOS time. Then the calculations are done using
572
-     * the new start time.
573
-     * The function has a built-in watchdog to ensure that we don't end up in
574
-     * lengthy loops.
575
-     *
576
-     */
577
-    public function find_los(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt)
578
-    {
579
-        $t = $start;
580
-        $lostime = 0.0;
581
-
582
-
583
-        $this->predict_calc($sat, $qth, $start);
584
-
585
-        /* check whether satellite has aos */
586
-        if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
587
-            ($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
588
-            !$this->has_aos ($sat, $qth)) {
589
-
590
-            return 0.0;
591
-        }
592
-
593
-        if ($sat->el < 0.0) {
594
-            $t = $this->find_aos($sat, $qth, $start, $maxdt) + 0.001; // +1.5 min
595
-        }
596
-
597
-        /* invalid time (potentially returned by find_aos) */
598
-        if ($t < 0.01) {
599
-            return 0.0;
600
-        }
601
-
602
-        /* update satellite data */
603
-        $this->predict_calc($sat, $qth, $t);
604
-
605
-        /* use upper time limit */
606
-        if ($maxdt > 0.0) {
607
-
608
-            /* coarse steps */
609
-            while (($sat->el >= 1.0) && ($t <= ($start + $maxdt))) {
610
-                $t += cos(($sat->el - 1.0) * self::de2ra) * sqrt($sat->alt) / 25000.0;
611
-                $this->predict_calc($sat, $qth, $t);
612
-            }
613
-
614
-            /* fine steps */
615
-            while (($lostime == 0.0) && ($t <= ($start + $maxdt)))  {
616
-
617
-                $t += $sat->el * sqrt($sat->alt) / 502500.0;
618
-                $this->predict_calc($sat, $qth, $t);
619
-
620
-                if (abs($sat->el) < 0.005) {
621
-                    $lostime = $t;
622
-                }
623
-            }
624
-        } else {
625
-        /* don't use upper limit */
626
-
627
-            /* coarse steps */
628
-            while ($sat->el >= 1.0) {
629
-                $t += cos(($sat->el - 1.0) * self::de2ra) * sqrt($sat->alt) / 25000.0;
630
-                $this->predict_calc($sat, $qth, $t);
631
-            }
632
-
633
-            /* fine steps */
634
-            while ($lostime == 0.0) {
635
-
636
-                $t += $sat->el * sqrt($sat->alt) / 502500.0;
637
-                $this->predict_calc($sat, $qth, $t);
638
-
639
-                if (abs($sat->el) < 0.005)
640
-                    $lostime = $t;
641
-            }
642
-        }
643
-
644
-        return $lostime;
645
-    }
646
-
647
-    /** Find AOS time of current pass.
648
-     *  @param Predict_Sat $sat   The satellite to find AOS for.
649
-     *  @param Predict_QTH $qth   The ground station.
650
-     *  @param float       $start Start time, prefereably now.
651
-     *  @return The time of the previous AOS or 0.0 if the satellite has no AOS.
652
-     *
653
-     * This function can be used to find the AOS time in the past of the
654
-     * current pass.
655
-     */
656
-    public function find_prev_aos(Predict_Sat $sat, Predict_QTH $qth, $start)
657
-    {
658
-        $aostime = $start;
659
-
660
-        /* make sure current sat values are
428
+		$this->predict_calc($sat, $qth, $start);
429
+
430
+		/* check whether satellite has aos */
431
+		if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
432
+			($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
433
+			!$this->has_aos($sat, $qth)) {
434
+
435
+			return 0.0;
436
+		}
437
+
438
+		if ($sat->el > 0.0) {
439
+			$t = $this->find_los($sat, $qth, $start, $maxdt) + 0.014; // +20 min
440
+		}
441
+
442
+		/* invalid time (potentially returned by find_los) */
443
+		if ($t < 0.1) {
444
+			return 0.0;
445
+		}
446
+
447
+		/* update satellite data */
448
+		$this->predict_calc($sat, $qth, $t);
449
+
450
+		/* use upper time limit */
451
+		if ($maxdt > 0.0) {
452
+
453
+			/* coarse time steps */
454
+			while (($sat->el < -1.0) && ($t <= ($start + $maxdt))) {
455
+				$t -= 0.00035 * ($sat->el * (($sat->alt / 8400.0) + 0.46) - 2.0);
456
+				$this->predict_calc($sat, $qth, $t);
457
+			}
458
+
459
+			/* fine steps */
460
+			while (($aostime == 0.0) && ($t <= ($start + $maxdt))) {
461
+
462
+				if (abs($sat->el) < 0.005) {
463
+					$aostime = $t;
464
+				} else {
465
+					$t -= $sat->el * sqrt($sat->alt) / 530000.0;
466
+					$this->predict_calc($sat, $qth, $t);
467
+				}
468
+			}
469
+		} else {
470
+			/* don't use upper time limit */
471
+
472
+			/* coarse time steps */
473
+			while ($sat->el < -1.0) {
474
+
475
+				$t -= 0.00035 * ($sat->el * (($sat->alt / 8400.0) + 0.46) - 2.0);
476
+				$this->predict_calc($sat, $qth, $t);
477
+			}
478
+
479
+			/* fine steps */
480
+			while ($aostime == 0.0) {
481
+
482
+				if (abs($sat->el) < 0.005) {
483
+					$aostime = $t;
484
+				} else {
485
+					$t -= $sat->el * sqrt($sat->alt) / 530000.0;
486
+					$this->predict_calc($sat, $qth, $t);
487
+				}
488
+
489
+			}
490
+		}
491
+
492
+		return $aostime;
493
+	}
494
+
495
+	/** SGP4SDP4 driver for doing AOS/LOS calculations.
496
+	 *  @param Predict_Sat $sat The satellite data.
497
+	 *  @param Predict_QTH $qth The QTH observer location data.
498
+	 *  @param float       $t   The time for calculation (Julian Date)
499
+	 *
500
+	 */
501
+	public function predict_calc(Predict_Sat $sat, Predict_QTH $qth, $t)
502
+	{
503
+		$obs_set      = new Predict_ObsSet();
504
+		$sat_geodetic = new Predict_Geodetic();
505
+		$obs_geodetic = new Predict_Geodetic();
506
+
507
+		$obs_geodetic->lon   = $qth->lon * self::de2ra;
508
+		$obs_geodetic->lat   = $qth->lat * self::de2ra;
509
+		$obs_geodetic->alt   = $qth->alt / 1000.0;
510
+		$obs_geodetic->theta = 0;
511
+
512
+		$sat->jul_utc = $t;
513
+		$sat->tsince = ($sat->jul_utc - $sat->jul_epoch) * self::xmnpda;
514
+
515
+		/* call the norad routines according to the deep-space flag */
516
+		$sgpsdp = Predict_SGPSDP::getInstance($sat);
517
+		if ($sat->flags & Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG) {
518
+			$sgpsdp->SDP4($sat, $sat->tsince);
519
+		} else {
520
+			$sgpsdp->SGP4($sat, $sat->tsince);
521
+		}
522
+
523
+		Predict_Math::Convert_Sat_State($sat->pos, $sat->vel);
524
+
525
+		/* get the velocity of the satellite */
526
+		$sat->vel->w = sqrt($sat->vel->x * $sat->vel->x + $sat->vel->y * $sat->vel->y + $sat->vel->z * $sat->vel->z);
527
+		$sat->velo = $sat->vel->w;
528
+		Predict_SGPObs::Calculate_Obs($sat->jul_utc, $sat->pos, $sat->vel, $obs_geodetic, $obs_set);
529
+		Predict_SGPObs::Calculate_LatLonAlt($sat->jul_utc, $sat->pos, $sat_geodetic);
530
+
531
+		while ($sat_geodetic->lon < -self::pi) {
532
+			$sat_geodetic->lon += self::twopi;
533
+		}
534
+
535
+		while ($sat_geodetic->lon > (self::pi)) {
536
+			$sat_geodetic->lon -= self::twopi;
537
+		}
538
+
539
+		$sat->az = Predict_Math::Degrees($obs_set->az);
540
+		$sat->el = Predict_Math::Degrees($obs_set->el);
541
+		$sat->range = $obs_set->range;
542
+		$sat->range_rate = $obs_set->range_rate;
543
+		$sat->ssplat = Predict_Math::Degrees($sat_geodetic->lat);
544
+		$sat->ssplon = Predict_Math::Degrees($sat_geodetic->lon);
545
+		$sat->alt = $sat_geodetic->alt;
546
+		$sat->ma = Predict_Math::Degrees($sat->phase);
547
+		$sat->ma *= 256.0 / 360.0;
548
+		$sat->phase = Predict_Math::Degrees($sat->phase);
549
+
550
+		/* same formulas, but the one from predict is nicer */
551
+		//sat->footprint = 2.0 * xkmper * acos (xkmper/sat->pos.w);
552
+		$sat->footprint = 12756.33 * acos(self::xkmper / (self::xkmper + $sat->alt));
553
+		$age = $sat->jul_utc - $sat->jul_epoch;
554
+		$sat->orbit = floor(($sat->tle->xno * self::xmnpda / self::twopi +
555
+						$age * $sat->tle->bstar * self::ae) * $age +
556
+						$sat->tle->xmo / self::twopi) + $sat->tle->revnum - 1;
557
+	}
558
+
559
+	/** Find the LOS time of the next pass.
560
+	 *  @author Alexandru Csete, OZ9AEC
561
+	 *  @author John A. Magliacane, KD2BD
562
+	 *  @param Predict_Sat $sat The satellite data.
563
+	 *  @param Predict_QTH $qth The QTH observer location data.
564
+	 *  @param float       $start The time where calculation should start. (Julian Date)
565
+	 *  @param int         $maxdt The upper time limit in days (0.0 = no limit)
566
+	 *  @return The time (julian date) of the next LOS or 0.0 if the satellite has no LOS.
567
+	 *
568
+	 * This function finds the time of LOS for the first coming pass taking place
569
+	 * no earlier that start.
570
+	 * If the satellite is currently out of range, the function first calls
571
+	 * find_aos to get the next AOS time. Then the calculations are done using
572
+	 * the new start time.
573
+	 * The function has a built-in watchdog to ensure that we don't end up in
574
+	 * lengthy loops.
575
+	 *
576
+	 */
577
+	public function find_los(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt)
578
+	{
579
+		$t = $start;
580
+		$lostime = 0.0;
581
+
582
+
583
+		$this->predict_calc($sat, $qth, $start);
584
+
585
+		/* check whether satellite has aos */
586
+		if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
587
+			($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
588
+			!$this->has_aos ($sat, $qth)) {
589
+
590
+			return 0.0;
591
+		}
592
+
593
+		if ($sat->el < 0.0) {
594
+			$t = $this->find_aos($sat, $qth, $start, $maxdt) + 0.001; // +1.5 min
595
+		}
596
+
597
+		/* invalid time (potentially returned by find_aos) */
598
+		if ($t < 0.01) {
599
+			return 0.0;
600
+		}
601
+
602
+		/* update satellite data */
603
+		$this->predict_calc($sat, $qth, $t);
604
+
605
+		/* use upper time limit */
606
+		if ($maxdt > 0.0) {
607
+
608
+			/* coarse steps */
609
+			while (($sat->el >= 1.0) && ($t <= ($start + $maxdt))) {
610
+				$t += cos(($sat->el - 1.0) * self::de2ra) * sqrt($sat->alt) / 25000.0;
611
+				$this->predict_calc($sat, $qth, $t);
612
+			}
613
+
614
+			/* fine steps */
615
+			while (($lostime == 0.0) && ($t <= ($start + $maxdt)))  {
616
+
617
+				$t += $sat->el * sqrt($sat->alt) / 502500.0;
618
+				$this->predict_calc($sat, $qth, $t);
619
+
620
+				if (abs($sat->el) < 0.005) {
621
+					$lostime = $t;
622
+				}
623
+			}
624
+		} else {
625
+		/* don't use upper limit */
626
+
627
+			/* coarse steps */
628
+			while ($sat->el >= 1.0) {
629
+				$t += cos(($sat->el - 1.0) * self::de2ra) * sqrt($sat->alt) / 25000.0;
630
+				$this->predict_calc($sat, $qth, $t);
631
+			}
632
+
633
+			/* fine steps */
634
+			while ($lostime == 0.0) {
635
+
636
+				$t += $sat->el * sqrt($sat->alt) / 502500.0;
637
+				$this->predict_calc($sat, $qth, $t);
638
+
639
+				if (abs($sat->el) < 0.005)
640
+					$lostime = $t;
641
+			}
642
+		}
643
+
644
+		return $lostime;
645
+	}
646
+
647
+	/** Find AOS time of current pass.
648
+	 *  @param Predict_Sat $sat   The satellite to find AOS for.
649
+	 *  @param Predict_QTH $qth   The ground station.
650
+	 *  @param float       $start Start time, prefereably now.
651
+	 *  @return The time of the previous AOS or 0.0 if the satellite has no AOS.
652
+	 *
653
+	 * This function can be used to find the AOS time in the past of the
654
+	 * current pass.
655
+	 */
656
+	public function find_prev_aos(Predict_Sat $sat, Predict_QTH $qth, $start)
657
+	{
658
+		$aostime = $start;
659
+
660
+		/* make sure current sat values are
661 661
             in sync with the time
662 662
         */
663
-        $this->predict_calc($sat, $qth, $start);
664
-
665
-        /* check whether satellite has aos */
666
-        if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
667
-            ($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
668
-            !$this->has_aos($sat, $qth)) {
669
-
670
-            return 0.0;
671
-        }
672
-
673
-        while ($sat->el >= 0.0) {
674
-            $aostime -= 0.0005; // 0.75 min
675
-            $this->predict_calc($sat, $qth, $aostime);
676
-        }
677
-
678
-        return $aostime;
679
-    }
680
-
681
-    /** Determine whether satellite ever reaches AOS.
682
-     *  @author John A. Magliacane, KD2BD
683
-     *  @author Alexandru Csete, OZ9AEC
684
-     *  @param Predict_Sat $sat The satellite data.
685
-     *  @param Predict_QTH $qth The observer's location data
686
-     *  @return bool true if the satellite will reach AOS, false otherwise.
687
-     *
688
-     */
689
-    public function has_aos(Predict_Sat $sat, Predict_QTH $qth)
690
-    {
691
-         $retcode = false;
692
-
693
-         /* FIXME */
694
-         if ($sat->meanmo == 0.0) {
695
-              $retcode = false;
696
-         } else {
697
-
698
-            /* xincl is already in RAD by select_ephemeris */
699
-            $lin = $sat->tle->xincl;
700
-            if ($lin >= self::pio2) {
701
-                $lin = self::pi - $lin;
702
-            }
703
-
704
-            $sma = 331.25 * exp(log(1440.0 / $sat->meanmo) * (2.0 / 3.0));
705
-            $apogee = $sma * (1.0 + $sat->tle->eo) - self::xkmper;
706
-
707
-            if ((acos(self::xkmper / ($apogee + self::xkmper)) + ($lin)) > abs($qth->lat * self::de2ra)) {
708
-                $retcode = true;
709
-            } else {
710
-                $retcode = false;
711
-            }
712
-        }
713
-
714
-        return $retcode;
715
-    }
716
-
717
-    /** Predict passes after a certain time.
718
-     *
719
-     *
720
-     * This function calculates num upcoming passes with AOS no earlier
721
-     * than t = start and not later that t = (start+maxdt). The function will
722
-     *  repeatedly call get_pass until
723
-     * the number of predicted passes is equal to num, the time has reached
724
-     * limit or the get_pass function returns NULL.
725
-     *
726
-     * note For no time limit use maxdt = 0.0
727
-     *
728
-     * note the data in sat will be corrupt (future) and must be refreshed
729
-     *      by the caller, if the caller will need it later on (eg. if the caller
730
-     *      is GtkSatList).
731
-     *
732
-     * note Prepending to a singly linked list is much faster than appending.
733
-     *      Therefore, the elements are prepended whereafter the GSList is
734
-     *      reversed
735
-     *
736
-     *
737
-     * @param Predict_Sat  $sat The satellite data
738
-     * @param Predict_QTH  $qth The observer's location data
739
-     * @param float $start The start julian date
740
-     * @param int   $maxdt The max # of days to look
741
-     * @param int   $num   The max # of passes to get
742
-     * @return array of Predict_Pass instances if found, empty array otherwise
743
-     */
744
-    public function get_passes(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt, $num = 0)
745
-    {
746
-        $passes = array();
747
-
748
-        /* if no number has been specified
663
+		$this->predict_calc($sat, $qth, $start);
664
+
665
+		/* check whether satellite has aos */
666
+		if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
667
+			($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
668
+			!$this->has_aos($sat, $qth)) {
669
+
670
+			return 0.0;
671
+		}
672
+
673
+		while ($sat->el >= 0.0) {
674
+			$aostime -= 0.0005; // 0.75 min
675
+			$this->predict_calc($sat, $qth, $aostime);
676
+		}
677
+
678
+		return $aostime;
679
+	}
680
+
681
+	/** Determine whether satellite ever reaches AOS.
682
+	 *  @author John A. Magliacane, KD2BD
683
+	 *  @author Alexandru Csete, OZ9AEC
684
+	 *  @param Predict_Sat $sat The satellite data.
685
+	 *  @param Predict_QTH $qth The observer's location data
686
+	 *  @return bool true if the satellite will reach AOS, false otherwise.
687
+	 *
688
+	 */
689
+	public function has_aos(Predict_Sat $sat, Predict_QTH $qth)
690
+	{
691
+		 $retcode = false;
692
+
693
+		 /* FIXME */
694
+		 if ($sat->meanmo == 0.0) {
695
+			  $retcode = false;
696
+		 } else {
697
+
698
+			/* xincl is already in RAD by select_ephemeris */
699
+			$lin = $sat->tle->xincl;
700
+			if ($lin >= self::pio2) {
701
+				$lin = self::pi - $lin;
702
+			}
703
+
704
+			$sma = 331.25 * exp(log(1440.0 / $sat->meanmo) * (2.0 / 3.0));
705
+			$apogee = $sma * (1.0 + $sat->tle->eo) - self::xkmper;
706
+
707
+			if ((acos(self::xkmper / ($apogee + self::xkmper)) + ($lin)) > abs($qth->lat * self::de2ra)) {
708
+				$retcode = true;
709
+			} else {
710
+				$retcode = false;
711
+			}
712
+		}
713
+
714
+		return $retcode;
715
+	}
716
+
717
+	/** Predict passes after a certain time.
718
+	 *
719
+	 *
720
+	 * This function calculates num upcoming passes with AOS no earlier
721
+	 * than t = start and not later that t = (start+maxdt). The function will
722
+	 *  repeatedly call get_pass until
723
+	 * the number of predicted passes is equal to num, the time has reached
724
+	 * limit or the get_pass function returns NULL.
725
+	 *
726
+	 * note For no time limit use maxdt = 0.0
727
+	 *
728
+	 * note the data in sat will be corrupt (future) and must be refreshed
729
+	 *      by the caller, if the caller will need it later on (eg. if the caller
730
+	 *      is GtkSatList).
731
+	 *
732
+	 * note Prepending to a singly linked list is much faster than appending.
733
+	 *      Therefore, the elements are prepended whereafter the GSList is
734
+	 *      reversed
735
+	 *
736
+	 *
737
+	 * @param Predict_Sat  $sat The satellite data
738
+	 * @param Predict_QTH  $qth The observer's location data
739
+	 * @param float $start The start julian date
740
+	 * @param int   $maxdt The max # of days to look
741
+	 * @param int   $num   The max # of passes to get
742
+	 * @return array of Predict_Pass instances if found, empty array otherwise
743
+	 */
744
+	public function get_passes(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt, $num = 0)
745
+	{
746
+		$passes = array();
747
+
748
+		/* if no number has been specified
749 749
             set it to something big */
750
-        if ($num == 0) {
751
-            $num = 100;
752
-        }
750
+		if ($num == 0) {
751
+			$num = 100;
752
+		}
753 753
 
754
-        $t = $start;
754
+		$t = $start;
755 755
 
756
-        for ($i = 0; $i < $num; $i++) {
757
-            $pass = $this->get_pass($sat, $qth, $t, $maxdt);
756
+		for ($i = 0; $i < $num; $i++) {
757
+			$pass = $this->get_pass($sat, $qth, $t, $maxdt);
758 758
 
759
-            if ($pass != null) {
760
-                $passes[] = $pass;
761
-                $t = $pass->los + 0.014; // +20 min
759
+			if ($pass != null) {
760
+				$passes[] = $pass;
761
+				$t = $pass->los + 0.014; // +20 min
762 762
 
763
-                /* if maxdt > 0.0 check whether we have reached t = start+maxdt
763
+				/* if maxdt > 0.0 check whether we have reached t = start+maxdt
764 764
                     if yes finish predictions
765 765
                 */
766
-                if (($maxdt > 0.0) && ($t >= ($start + $maxdt))) {
767
-                    $i = $num;
768
-                }
769
-            } else {
770
-                /* we can't get any more passes */
771
-                $i = $num;
772
-            }
773
-        }
774
-
775
-        return $passes;
776
-    }
777
-
778
-    /**
779
-     * Filters out visible passes and adds the visible aos, tca, los, and
780
-     * corresponding az and ele for each.
781
-     *
782
-     * @param array $passes The passes returned from get_passes()
783
-     *
784
-     * @author Bill Shupp
785
-     * @return array
786
-     */
787
-    public function filterVisiblePasses(array $passes)
788
-    {
789
-        $filtered = array();
790
-
791
-        foreach ($passes as $result) {
792
-            // Dummy check
793
-            if ($result->vis[0] != 'V') {
794
-                continue;
795
-            }
796
-
797
-            $aos    = false;
798
-            $aos_az = false;
799
-            $aos    = false;
800
-            $tca    = false;
801
-            $los_az = false;
802
-            $max_el = 0;
803
-
804
-            foreach ($result->details as $detail) {
805
-                if ($detail->vis != Predict::SAT_VIS_VISIBLE) {
806
-                    continue;
807
-                }
808
-                if ($detail->el < $this->minEle) {
809
-                    continue;
810
-                }
811
-
812
-                if ($aos == false) {
813
-                    $aos       = $detail->time;
814
-                    $aos_az    = $detail->az;
815
-                    $aos_el    = $detail->el;
816
-                    $tca       = $detail->time;
817
-                    $los       = $detail->time;
818
-                    $los_az    = $detail->az;
819
-                    $los_el    = $detail->el;
820
-                    $max_el    = $detail->el;
821
-                    $max_el_az = $detail->el;
822
-                    continue;
823
-                }
824
-                $los    = $detail->time;
825
-                $los_az = $detail->az;
826
-                $los_el = $detail->el;
827
-
828
-                if ($detail->el > $max_el) {
829
-                    $tca       = $detail->time;
830
-                    $max_el    = $detail->el;
831
-                    $max_el_az = $detail->az;
832
-                }
833
-            }
834
-
835
-            if ($aos === false) {
836
-                // Does not reach minimum elevation, skip
837
-                continue;
838
-            }
839
-
840
-            $result->visible_aos       = $aos;
841
-            $result->visible_aos_az    = $aos_az;
842
-            $result->visible_aos_el    = $aos_el;
843
-            $result->visible_tca       = $tca;
844
-            $result->visible_max_el    = $max_el;
845
-            $result->visible_max_el_az = $max_el_az;
846
-            $result->visible_los       = $los;
847
-            $result->visible_los_az    = $los_az;
848
-            $result->visible_los_el    = $los_el;
849
-
850
-            $filtered[] = $result;
851
-        }
852
-
853
-        return $filtered;
854
-    }
855
-
856
-    /**
857
-     * Translates aziumuth degrees to compass direction:
858
-     *
859
-     * N (0°), NNE (22.5°), NE (45°), ENE (67.5°), E (90°), ESE (112.5°),
860
-     * SE (135°), SSE (157.5°), S (180°), SSW (202.5°), SW (225°),
861
-     * WSW (247.5°), W (270°), WNW (292.5°), NW (315°), NNW (337.5°)
862
-     *
863
-     * @param int $az The azimuth in degrees, defaults to 0
864
-     *
865
-     * @return string
866
-     */
867
-    public function azDegreesToDirection($az = 0)
868
-    {
869
-        $i = floor($az / 22.5);
870
-        $m = (22.5 * (2 * $i + 1)) / 2;
871
-        $i = ($az >= $m) ? $i + 1 : $i;
872
-
873
-        return trim(substr('N  NNENE ENEE  ESESE SSES  SSWSW WSWW  WNWNW NNWN  ', $i * 3, 3));
874
-    }
766
+				if (($maxdt > 0.0) && ($t >= ($start + $maxdt))) {
767
+					$i = $num;
768
+				}
769
+			} else {
770
+				/* we can't get any more passes */
771
+				$i = $num;
772
+			}
773
+		}
774
+
775
+		return $passes;
776
+	}
777
+
778
+	/**
779
+	 * Filters out visible passes and adds the visible aos, tca, los, and
780
+	 * corresponding az and ele for each.
781
+	 *
782
+	 * @param array $passes The passes returned from get_passes()
783
+	 *
784
+	 * @author Bill Shupp
785
+	 * @return array
786
+	 */
787
+	public function filterVisiblePasses(array $passes)
788
+	{
789
+		$filtered = array();
790
+
791
+		foreach ($passes as $result) {
792
+			// Dummy check
793
+			if ($result->vis[0] != 'V') {
794
+				continue;
795
+			}
796
+
797
+			$aos    = false;
798
+			$aos_az = false;
799
+			$aos    = false;
800
+			$tca    = false;
801
+			$los_az = false;
802
+			$max_el = 0;
803
+
804
+			foreach ($result->details as $detail) {
805
+				if ($detail->vis != Predict::SAT_VIS_VISIBLE) {
806
+					continue;
807
+				}
808
+				if ($detail->el < $this->minEle) {
809
+					continue;
810
+				}
811
+
812
+				if ($aos == false) {
813
+					$aos       = $detail->time;
814
+					$aos_az    = $detail->az;
815
+					$aos_el    = $detail->el;
816
+					$tca       = $detail->time;
817
+					$los       = $detail->time;
818
+					$los_az    = $detail->az;
819
+					$los_el    = $detail->el;
820
+					$max_el    = $detail->el;
821
+					$max_el_az = $detail->el;
822
+					continue;
823
+				}
824
+				$los    = $detail->time;
825
+				$los_az = $detail->az;
826
+				$los_el = $detail->el;
827
+
828
+				if ($detail->el > $max_el) {
829
+					$tca       = $detail->time;
830
+					$max_el    = $detail->el;
831
+					$max_el_az = $detail->az;
832
+				}
833
+			}
834
+
835
+			if ($aos === false) {
836
+				// Does not reach minimum elevation, skip
837
+				continue;
838
+			}
839
+
840
+			$result->visible_aos       = $aos;
841
+			$result->visible_aos_az    = $aos_az;
842
+			$result->visible_aos_el    = $aos_el;
843
+			$result->visible_tca       = $tca;
844
+			$result->visible_max_el    = $max_el;
845
+			$result->visible_max_el_az = $max_el_az;
846
+			$result->visible_los       = $los;
847
+			$result->visible_los_az    = $los_az;
848
+			$result->visible_los_el    = $los_el;
849
+
850
+			$filtered[] = $result;
851
+		}
852
+
853
+		return $filtered;
854
+	}
855
+
856
+	/**
857
+	 * Translates aziumuth degrees to compass direction:
858
+	 *
859
+	 * N (0°), NNE (22.5°), NE (45°), ENE (67.5°), E (90°), ESE (112.5°),
860
+	 * SE (135°), SSE (157.5°), S (180°), SSW (202.5°), SW (225°),
861
+	 * WSW (247.5°), W (270°), WNW (292.5°), NW (315°), NNW (337.5°)
862
+	 *
863
+	 * @param int $az The azimuth in degrees, defaults to 0
864
+	 *
865
+	 * @return string
866
+	 */
867
+	public function azDegreesToDirection($az = 0)
868
+	{
869
+		$i = floor($az / 22.5);
870
+		$m = (22.5 * (2 * $i + 1)) / 2;
871
+		$i = ($az >= $m) ? $i + 1 : $i;
872
+
873
+		return trim(substr('N  NNENE ENEE  ESESE SSES  SSWSW WSWW  WNWNW NNWN  ', $i * 3, 3));
874
+	}
875 875
 }
Please login to merge, or discard this patch.