@@ -80,26 +80,26 @@ |
||
80 | 80 | return $centroid; |
81 | 81 | } |
82 | 82 | |
83 | - /** |
|
84 | - * Find the outermost point from the centroid |
|
85 | - * |
|
86 | - * @returns Point The outermost point |
|
87 | - */ |
|
83 | + /** |
|
84 | + * Find the outermost point from the centroid |
|
85 | + * |
|
86 | + * @returns Point The outermost point |
|
87 | + */ |
|
88 | 88 | public function outermostPoint() { |
89 | - $centroid = $this->getCentroid(); |
|
89 | + $centroid = $this->getCentroid(); |
|
90 | 90 | |
91 | - $max = array('length' => 0, 'point' => null); |
|
91 | + $max = array('length' => 0, 'point' => null); |
|
92 | 92 | |
93 | - foreach($this->getPoints() as $point) { |
|
94 | - $lineString = new LineString(array($centroid, $point)); |
|
93 | + foreach($this->getPoints() as $point) { |
|
94 | + $lineString = new LineString(array($centroid, $point)); |
|
95 | 95 | |
96 | - if($lineString->length() > $max['length']) { |
|
97 | - $max['length'] = $lineString->length(); |
|
98 | - $max['point'] = $point; |
|
99 | - } |
|
100 | - } |
|
96 | + if($lineString->length() > $max['length']) { |
|
97 | + $max['length'] = $lineString->length(); |
|
98 | + $max['point'] = $point; |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | - return $max['point']; |
|
102 | + return $max['point']; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | public function exteriorRing() { |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | $pts = $exterior_ring->getComponents(); |
25 | 25 | |
26 | 26 | $c = count($pts); |
27 | - if((int)$c == '0') return NULL; |
|
27 | + if ((int)$c == '0') return NULL; |
|
28 | 28 | $a = '0'; |
29 | - foreach($pts as $k => $p){ |
|
30 | - $j = ($k + 1) % $c; |
|
31 | - $a = $a + ($p->getX() * $pts[$j]->getY()) - ($p->getY() * $pts[$j]->getX()); |
|
29 | + foreach ($pts as $k => $p) { |
|
30 | + $j = ($k+1) % $c; |
|
31 | + $a = $a+($p->getX() * $pts[$j]->getY())-($p->getY() * $pts[$j]->getX()); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | if ($signed) $area = ($a / 2); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $pts = $exterior_ring->getComponents(); |
58 | 58 | |
59 | 59 | $c = count($pts); |
60 | - if((int)$c == '0') return NULL; |
|
60 | + if ((int)$c == '0') return NULL; |
|
61 | 61 | $cn = array('x' => '0', 'y' => '0'); |
62 | 62 | $a = $this->area(TRUE, TRUE); |
63 | 63 | |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | return $this->exteriorRing()->pointN(1); |
67 | 67 | } |
68 | 68 | |
69 | - foreach($pts as $k => $p){ |
|
70 | - $j = ($k + 1) % $c; |
|
71 | - $P = ($p->getX() * $pts[$j]->getY()) - ($p->getY() * $pts[$j]->getX()); |
|
72 | - $cn['x'] = $cn['x'] + ($p->getX() + $pts[$j]->getX()) * $P; |
|
73 | - $cn['y'] = $cn['y'] + ($p->getY() + $pts[$j]->getY()) * $P; |
|
69 | + foreach ($pts as $k => $p) { |
|
70 | + $j = ($k+1) % $c; |
|
71 | + $P = ($p->getX() * $pts[$j]->getY())-($p->getY() * $pts[$j]->getX()); |
|
72 | + $cn['x'] = $cn['x']+($p->getX()+$pts[$j]->getX()) * $P; |
|
73 | + $cn['y'] = $cn['y']+($p->getY()+$pts[$j]->getY()) * $P; |
|
74 | 74 | } |
75 | 75 | |
76 | - $cn['x'] = $cn['x'] / ( 6 * $a); |
|
77 | - $cn['y'] = $cn['y'] / ( 6 * $a); |
|
76 | + $cn['x'] = $cn['x'] / (6 * $a); |
|
77 | + $cn['y'] = $cn['y'] / (6 * $a); |
|
78 | 78 | |
79 | 79 | $centroid = new Point($cn['x'], $cn['y']); |
80 | 80 | return $centroid; |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | |
91 | 91 | $max = array('length' => 0, 'point' => null); |
92 | 92 | |
93 | - foreach($this->getPoints() as $point) { |
|
93 | + foreach ($this->getPoints() as $point) { |
|
94 | 94 | $lineString = new LineString(array($centroid, $point)); |
95 | 95 | |
96 | - if($lineString->length() > $max['length']) { |
|
96 | + if ($lineString->length() > $max['length']) { |
|
97 | 97 | $max['length'] = $lineString->length(); |
98 | 98 | $max['point'] = $point; |
99 | 99 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | $intersections = 0; |
163 | 163 | $vertices_count = count($vertices); |
164 | 164 | |
165 | - for ($i=1; $i < $vertices_count; $i++) { |
|
165 | + for ($i = 1; $i < $vertices_count; $i++) { |
|
166 | 166 | $vertex1 = $vertices[$i-1]; |
167 | 167 | $vertex2 = $vertices[$i]; |
168 | 168 | if ($vertex1->y() == $vertex2->y() |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | && $point->x() <= max($vertex1->x(), $vertex2->x()) |
178 | 178 | && $vertex1->y() != $vertex2->y()) { |
179 | 179 | $xinters = |
180 | - ($point->y() - $vertex1->y()) * ($vertex2->x() - $vertex1->x()) |
|
181 | - / ($vertex2->y() - $vertex1->y()) |
|
180 | + ($point->y()-$vertex1->y()) * ($vertex2->x()-$vertex1->x()) |
|
181 | + / ($vertex2->y()-$vertex1->y()) |
|
182 | 182 | + $vertex1->x(); |
183 | 183 | if ($xinters == $point->x()) { |
184 | 184 | // Check if point is on the polygon boundary (other than horizontal) |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | public function pointOnVertex($point) { |
202 | - foreach($this->getPoints() as $vertex) { |
|
202 | + foreach ($this->getPoints() as $vertex) { |
|
203 | 203 | if ($point->equals($vertex)) { |
204 | 204 | return true; |
205 | 205 | } |
@@ -14,7 +14,9 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function area($exterior_only = FALSE, $signed = FALSE) { |
17 | - if ($this->isEmpty()) return 0; |
|
17 | + if ($this->isEmpty()) { |
|
18 | + return 0; |
|
19 | + } |
|
18 | 20 | |
19 | 21 | if ($this->geos() && $exterior_only == FALSE) { |
20 | 22 | return $this->geos()->area(); |
@@ -24,15 +26,20 @@ discard block |
||
24 | 26 | $pts = $exterior_ring->getComponents(); |
25 | 27 | |
26 | 28 | $c = count($pts); |
27 | - if((int)$c == '0') return NULL; |
|
29 | + if((int)$c == '0') { |
|
30 | + return NULL; |
|
31 | + } |
|
28 | 32 | $a = '0'; |
29 | 33 | foreach($pts as $k => $p){ |
30 | 34 | $j = ($k + 1) % $c; |
31 | 35 | $a = $a + ($p->getX() * $pts[$j]->getY()) - ($p->getY() * $pts[$j]->getX()); |
32 | 36 | } |
33 | 37 | |
34 | - if ($signed) $area = ($a / 2); |
|
35 | - else $area = abs(($a / 2)); |
|
38 | + if ($signed) { |
|
39 | + $area = ($a / 2); |
|
40 | + } else { |
|
41 | + $area = abs(($a / 2)); |
|
42 | + } |
|
36 | 43 | |
37 | 44 | if ($exterior_only == TRUE) { |
38 | 45 | return $area; |
@@ -47,7 +54,9 @@ discard block |
||
47 | 54 | } |
48 | 55 | |
49 | 56 | public function centroid() { |
50 | - if ($this->isEmpty()) return NULL; |
|
57 | + if ($this->isEmpty()) { |
|
58 | + return NULL; |
|
59 | + } |
|
51 | 60 | |
52 | 61 | if ($this->geos()) { |
53 | 62 | return geoPHP::geosToGeometry($this->geos()->centroid()); |
@@ -57,7 +66,9 @@ discard block |
||
57 | 66 | $pts = $exterior_ring->getComponents(); |
58 | 67 | |
59 | 68 | $c = count($pts); |
60 | - if((int)$c == '0') return NULL; |
|
69 | + if((int)$c == '0') { |
|
70 | + return NULL; |
|
71 | + } |
|
61 | 72 | $cn = array('x' => '0', 'y' => '0'); |
62 | 73 | $a = $this->area(TRUE, TRUE); |
63 | 74 | |
@@ -103,12 +114,16 @@ discard block |
||
103 | 114 | } |
104 | 115 | |
105 | 116 | public function exteriorRing() { |
106 | - if ($this->isEmpty()) return new LineString(); |
|
117 | + if ($this->isEmpty()) { |
|
118 | + return new LineString(); |
|
119 | + } |
|
107 | 120 | return $this->components[0]; |
108 | 121 | } |
109 | 122 | |
110 | 123 | public function numInteriorRings() { |
111 | - if ($this->isEmpty()) return 0; |
|
124 | + if ($this->isEmpty()) { |
|
125 | + return 0; |
|
126 | + } |
|
112 | 127 | return $this->numGeometries()-1; |
113 | 128 | } |
114 | 129 | |
@@ -117,7 +132,9 @@ discard block |
||
117 | 132 | } |
118 | 133 | |
119 | 134 | public function dimension() { |
120 | - if ($this->isEmpty()) return 0; |
|
135 | + if ($this->isEmpty()) { |
|
136 | + return 0; |
|
137 | + } |
|
121 | 138 | return 2; |
122 | 139 | } |
123 | 140 | |
@@ -192,8 +209,7 @@ discard block |
||
192 | 209 | // If the number of edges we passed through is even, then it's in the polygon. |
193 | 210 | if ($intersections % 2 != 0) { |
194 | 211 | return TRUE; |
195 | - } |
|
196 | - else { |
|
212 | + } else { |
|
197 | 213 | return FALSE; |
198 | 214 | } |
199 | 215 | } |
@@ -51,11 +51,11 @@ |
||
51 | 51 | * */ |
52 | 52 | public function invertxy() |
53 | 53 | { |
54 | - for($i=0;$i<count($this->components);$i++) |
|
55 | - { |
|
56 | - if( method_exists($this->components[$i], 'invertxy' ) ) |
|
57 | - $this->components[$i]->invertxy(); |
|
58 | - } |
|
54 | + for($i=0;$i<count($this->components);$i++) |
|
55 | + { |
|
56 | + if( method_exists($this->components[$i], 'invertxy' ) ) |
|
57 | + $this->components[$i]->invertxy(); |
|
58 | + } |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | public function centroid() { |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | * */ |
52 | 52 | public function invertxy() |
53 | 53 | { |
54 | - for($i=0;$i<count($this->components);$i++) |
|
54 | + for ($i = 0; $i < count($this->components); $i++) |
|
55 | 55 | { |
56 | - if( method_exists($this->components[$i], 'invertxy' ) ) |
|
56 | + if (method_exists($this->components[$i], 'invertxy')) |
|
57 | 57 | $this->components[$i]->invertxy(); |
58 | 58 | } |
59 | 59 | } |
@@ -297,16 +297,16 @@ discard block |
||
297 | 297 | |
298 | 298 | // Not valid for this geometry type |
299 | 299 | // -------------------------------- |
300 | - public function x() { return NULL; } |
|
301 | - public function y() { return NULL; } |
|
302 | - public function startPoint() { return NULL; } |
|
303 | - public function endPoint() { return NULL; } |
|
304 | - public function isRing() { return NULL; } |
|
305 | - public function isClosed() { return NULL; } |
|
306 | - public function pointN($n) { return NULL; } |
|
307 | - public function exteriorRing() { return NULL; } |
|
300 | + public function x() { return NULL; } |
|
301 | + public function y() { return NULL; } |
|
302 | + public function startPoint() { return NULL; } |
|
303 | + public function endPoint() { return NULL; } |
|
304 | + public function isRing() { return NULL; } |
|
305 | + public function isClosed() { return NULL; } |
|
306 | + public function pointN($n) { return NULL; } |
|
307 | + public function exteriorRing() { return NULL; } |
|
308 | 308 | public function numInteriorRings() { return NULL; } |
309 | - public function interiorRingN($n) { return NULL; } |
|
310 | - public function pointOnSurface() { return NULL; } |
|
309 | + public function interiorRingN($n) { return NULL; } |
|
310 | + public function pointOnSurface() { return NULL; } |
|
311 | 311 | } |
312 | 312 |
@@ -24,8 +24,7 @@ discard block |
||
24 | 24 | foreach ($components as $component) { |
25 | 25 | if ($component instanceof Geometry) { |
26 | 26 | $this->components[] = $component; |
27 | - } |
|
28 | - else { |
|
27 | + } else { |
|
29 | 28 | throw new Exception("Cannot create a collection with non-geometries"); |
30 | 29 | } |
31 | 30 | } |
@@ -53,13 +52,16 @@ discard block |
||
53 | 52 | { |
54 | 53 | for($i=0;$i<count($this->components);$i++) |
55 | 54 | { |
56 | - if( method_exists($this->components[$i], 'invertxy' ) ) |
|
57 | - $this->components[$i]->invertxy(); |
|
55 | + if( method_exists($this->components[$i], 'invertxy' ) ) { |
|
56 | + $this->components[$i]->invertxy(); |
|
57 | + } |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | 61 | public function centroid() { |
62 | - if ($this->isEmpty()) return NULL; |
|
62 | + if ($this->isEmpty()) { |
|
63 | + return NULL; |
|
64 | + } |
|
63 | 65 | |
64 | 66 | if ($this->geos()) { |
65 | 67 | $geos_centroid = $this->geos()->centroid(); |
@@ -77,7 +79,9 @@ discard block |
||
77 | 79 | } |
78 | 80 | |
79 | 81 | public function getBBox() { |
80 | - if ($this->isEmpty()) return NULL; |
|
82 | + if ($this->isEmpty()) { |
|
83 | + return NULL; |
|
84 | + } |
|
81 | 85 | |
82 | 86 | if ($this->geos()) { |
83 | 87 | $envelope = $this->geos()->envelope(); |
@@ -145,7 +149,9 @@ discard block |
||
145 | 149 | |
146 | 150 | // By default, the boundary of a collection is the boundary of it's components |
147 | 151 | public function boundary() { |
148 | - if ($this->isEmpty()) return new LineString(); |
|
152 | + if ($this->isEmpty()) { |
|
153 | + return new LineString(); |
|
154 | + } |
|
149 | 155 | |
150 | 156 | if ($this->geos()) { |
151 | 157 | return $this->geos()->boundary(); |
@@ -167,8 +173,7 @@ discard block |
||
167 | 173 | $n = intval($n); |
168 | 174 | if (array_key_exists($n-1, $this->components)) { |
169 | 175 | return $this->components[$n-1]; |
170 | - } |
|
171 | - else { |
|
176 | + } else { |
|
172 | 177 | return NULL; |
173 | 178 | } |
174 | 179 | } |
@@ -211,10 +216,11 @@ discard block |
||
211 | 216 | public function isEmpty() { |
212 | 217 | if (!count($this->components)) { |
213 | 218 | return TRUE; |
214 | - } |
|
215 | - else { |
|
219 | + } else { |
|
216 | 220 | foreach ($this->components as $component) { |
217 | - if (!$component->isEmpty()) return FALSE; |
|
221 | + if (!$component->isEmpty()) { |
|
222 | + return FALSE; |
|
223 | + } |
|
218 | 224 | } |
219 | 225 | return TRUE; |
220 | 226 | } |
@@ -281,7 +287,9 @@ discard block |
||
281 | 287 | |
282 | 288 | // A collection is simple if all it's components are simple |
283 | 289 | foreach ($this->components as $component) { |
284 | - if (!$component->isSimple()) return FALSE; |
|
290 | + if (!$component->isSimple()) { |
|
291 | + return FALSE; |
|
292 | + } |
|
285 | 293 | } |
286 | 294 | |
287 | 295 | return TRUE; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | // Check to see if this is a 3D point |
35 | 35 | if ($z !== NULL) { |
36 | 36 | if (!is_numeric($z)) { |
37 | - throw new Exception("Cannot construct Point. z should be numeric"); |
|
37 | + throw new Exception("Cannot construct Point. z should be numeric"); |
|
38 | 38 | } |
39 | 39 | $this->dimension = 3; |
40 | 40 | } |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | * */ |
93 | 93 | public function invertxy() |
94 | 94 | { |
95 | - $x=$this->coords[0]; |
|
96 | - $this->coords[0]=$this->coords[1]; |
|
97 | - $this->coords[1]=$x; |
|
95 | + $x=$this->coords[0]; |
|
96 | + $this->coords[0]=$this->coords[1]; |
|
97 | + $this->coords[1]=$x; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | * */ |
93 | 93 | public function invertxy() |
94 | 94 | { |
95 | - $x=$this->coords[0]; |
|
96 | - $this->coords[0]=$this->coords[1]; |
|
97 | - $this->coords[1]=$x; |
|
95 | + $x = $this->coords[0]; |
|
96 | + $this->coords[0] = $this->coords[1]; |
|
97 | + $this->coords[1] = $x; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @see: http://php.net/manual/en/language.types.float.php |
169 | 169 | * @see: http://tubalmartin.github.io/spherical-geometry-php/#LatLng |
170 | 170 | */ |
171 | - return (abs($this->x() - $geometry->x()) <= 1.0E-9 && abs($this->y() - $geometry->y()) <= 1.0E-9); |
|
171 | + return (abs($this->x()-$geometry->x()) <= 1.0E-9 && abs($this->y()-$geometry->y()) <= 1.0E-9); |
|
172 | 172 | } |
173 | 173 | else if ($this->isEmpty() && $geometry->isEmpty()) { |
174 | 174 | return TRUE; |
@@ -183,17 +183,17 @@ discard block |
||
183 | 183 | } |
184 | 184 | |
185 | 185 | // Not valid for this geometry type |
186 | - public function numGeometries() { return NULL; } |
|
187 | - public function geometryN($n) { return NULL; } |
|
188 | - public function startPoint() { return NULL; } |
|
189 | - public function endPoint() { return NULL; } |
|
190 | - public function isRing() { return NULL; } |
|
191 | - public function isClosed() { return NULL; } |
|
192 | - public function pointN($n) { return NULL; } |
|
193 | - public function exteriorRing() { return NULL; } |
|
186 | + public function numGeometries() { return NULL; } |
|
187 | + public function geometryN($n) { return NULL; } |
|
188 | + public function startPoint() { return NULL; } |
|
189 | + public function endPoint() { return NULL; } |
|
190 | + public function isRing() { return NULL; } |
|
191 | + public function isClosed() { return NULL; } |
|
192 | + public function pointN($n) { return NULL; } |
|
193 | + public function exteriorRing() { return NULL; } |
|
194 | 194 | public function numInteriorRings() { return NULL; } |
195 | - public function interiorRingN($n) { return NULL; } |
|
196 | - public function pointOnSurface() { return NULL; } |
|
197 | - public function explode() { return NULL; } |
|
195 | + public function interiorRingN($n) { return NULL; } |
|
196 | + public function pointOnSurface() { return NULL; } |
|
197 | + public function explode() { return NULL; } |
|
198 | 198 | } |
199 | 199 |
@@ -79,8 +79,9 @@ discard block |
||
79 | 79 | public function z() { |
80 | 80 | if ($this->dimension == 3) { |
81 | 81 | return $this->coords[2]; |
82 | + } else { |
|
83 | + return NULL; |
|
82 | 84 | } |
83 | - else return NULL; |
|
84 | 85 | } |
85 | 86 | |
86 | 87 | /** |
@@ -144,8 +145,7 @@ discard block |
||
144 | 145 | public function isEmpty() { |
145 | 146 | if ($this->dimension == 0) { |
146 | 147 | return TRUE; |
147 | - } |
|
148 | - else { |
|
148 | + } else { |
|
149 | 149 | return FALSE; |
150 | 150 | } |
151 | 151 | } |
@@ -169,11 +169,9 @@ discard block |
||
169 | 169 | * @see: http://tubalmartin.github.io/spherical-geometry-php/#LatLng |
170 | 170 | */ |
171 | 171 | return (abs($this->x() - $geometry->x()) <= 1.0E-9 && abs($this->y() - $geometry->y()) <= 1.0E-9); |
172 | - } |
|
173 | - else if ($this->isEmpty() && $geometry->isEmpty()) { |
|
172 | + } else if ($this->isEmpty() && $geometry->isEmpty()) { |
|
174 | 173 | return TRUE; |
175 | - } |
|
176 | - else { |
|
174 | + } else { |
|
177 | 175 | return FALSE; |
178 | 176 | } |
179 | 177 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | abstract public function geometryN($n); |
22 | 22 | abstract public function startPoint(); |
23 | 23 | abstract public function endPoint(); |
24 | - abstract public function isRing(); // Mssing dependancy |
|
25 | - abstract public function isClosed(); // Missing dependancy |
|
24 | + abstract public function isRing(); // Mssing dependancy |
|
25 | + abstract public function isClosed(); // Missing dependancy |
|
26 | 26 | abstract public function numPoints(); |
27 | 27 | abstract public function pointN($n); |
28 | 28 | abstract public function exteriorRing(); |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 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']), |
|
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 | 73 | ); |
74 | 74 | |
75 | 75 | $outer_boundary = new LineString($points); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | // It hasn't been set yet, generate it |
148 | 148 | if (geoPHP::geosInstalled()) { |
149 | 149 | $reader = new GEOSWKBReader(); |
150 | - $this->geos = $reader->readHEX($this->out('wkb',TRUE)); |
|
150 | + $this->geos = $reader->readHEX($this->out('wkb', TRUE)); |
|
151 | 151 | } |
152 | 152 | else { |
153 | 153 | $this->geos = FALSE; |
@@ -57,7 +57,9 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | public function envelope() { |
60 | - if ($this->isEmpty()) return new Polygon(); |
|
60 | + if ($this->isEmpty()) { |
|
61 | + return new Polygon(); |
|
62 | + } |
|
61 | 63 | |
62 | 64 | if ($this->geos()) { |
63 | 65 | return geoPHP::geosToGeometry($this->geos()->envelope()); |
@@ -148,8 +150,7 @@ discard block |
||
148 | 150 | if (geoPHP::geosInstalled()) { |
149 | 151 | $reader = new GEOSWKBReader(); |
150 | 152 | $this->geos = $reader->readHEX($this->out('wkb',TRUE)); |
151 | - } |
|
152 | - else { |
|
153 | + } else { |
|
153 | 154 | $this->geos = FALSE; |
154 | 155 | } |
155 | 156 | return $this->geos; |
@@ -175,8 +176,7 @@ discard block |
||
175 | 176 | if ($this->geos()) { |
176 | 177 | if ($pattern) { |
177 | 178 | return $this->geos()->relate($geometry->geos(), $pattern); |
178 | - } |
|
179 | - else { |
|
179 | + } else { |
|
180 | 180 | return $this->geos()->relate($geometry->geos()); |
181 | 181 | } |
182 | 182 | } |
@@ -227,8 +227,7 @@ discard block |
||
227 | 227 | $geom = $geom->union($item->geos()); |
228 | 228 | } |
229 | 229 | return geoPHP::geosToGeometry($geom); |
230 | - } |
|
231 | - else { |
|
230 | + } else { |
|
232 | 231 | return geoPHP::geosToGeometry($this->geos()->union($geometry->geos())); |
233 | 232 | } |
234 | 233 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | foreach ($this->getPoints() as $delta => $point) { |
70 | 70 | $previous_point = $this->geometryN($delta); |
71 | 71 | if ($previous_point) { |
72 | - $length += sqrt(pow(($previous_point->getX() - $point->getX()), 2) + pow(($previous_point->getY()- $point->getY()), 2)); |
|
72 | + $length += sqrt(pow(($previous_point->getX()-$point->getX()), 2)+pow(($previous_point->getY()-$point->getY()), 2)); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | return $length; |
@@ -78,25 +78,25 @@ discard block |
||
78 | 78 | public function greatCircleLength($radius = 6378137) { |
79 | 79 | $length = 0; |
80 | 80 | $points = $this->getPoints(); |
81 | - for($i=0; $i<$this->numPoints()-1; $i++) { |
|
81 | + for ($i = 0; $i < $this->numPoints()-1; $i++) { |
|
82 | 82 | $point = $points[$i]; |
83 | 83 | $next_point = $points[$i+1]; |
84 | - if (!is_object($next_point)) {continue;} |
|
84 | + if (!is_object($next_point)) {continue; } |
|
85 | 85 | // Great circle method |
86 | 86 | $lat1 = deg2rad($point->getY()); |
87 | 87 | $lat2 = deg2rad($next_point->getY()); |
88 | 88 | $lon1 = deg2rad($point->getX()); |
89 | 89 | $lon2 = deg2rad($next_point->getX()); |
90 | - $dlon = $lon2 - $lon1; |
|
90 | + $dlon = $lon2-$lon1; |
|
91 | 91 | $length += |
92 | 92 | $radius * |
93 | 93 | atan2( |
94 | 94 | sqrt( |
95 | - pow(cos($lat2) * sin($dlon), 2) + |
|
96 | - pow(cos($lat1) * sin($lat2) - sin($lat1) * cos($lat2) * cos($dlon), 2) |
|
95 | + pow(cos($lat2) * sin($dlon), 2)+ |
|
96 | + pow(cos($lat1) * sin($lat2)-sin($lat1) * cos($lat2) * cos($dlon), 2) |
|
97 | 97 | ) |
98 | 98 | , |
99 | - sin($lat1) * sin($lat2) + |
|
99 | + sin($lat1) * sin($lat2)+ |
|
100 | 100 | cos($lat1) * cos($lat2) * cos($dlon) |
101 | 101 | ); |
102 | 102 | } |
@@ -107,15 +107,15 @@ discard block |
||
107 | 107 | public function haversineLength() { |
108 | 108 | $degrees = 0; |
109 | 109 | $points = $this->getPoints(); |
110 | - for($i=0; $i<$this->numPoints()-1; $i++) { |
|
110 | + for ($i = 0; $i < $this->numPoints()-1; $i++) { |
|
111 | 111 | $point = $points[$i]; |
112 | 112 | $next_point = $points[$i+1]; |
113 | - if (!is_object($next_point)) {continue;} |
|
113 | + if (!is_object($next_point)) {continue; } |
|
114 | 114 | $degree = rad2deg( |
115 | 115 | acos( |
116 | - sin(deg2rad($point->getY())) * sin(deg2rad($next_point->getY())) + |
|
116 | + sin(deg2rad($point->getY())) * sin(deg2rad($next_point->getY()))+ |
|
117 | 117 | cos(deg2rad($point->getY())) * cos(deg2rad($next_point->getY())) * |
118 | - cos(deg2rad(abs($point->getX() - $next_point->getX()))) |
|
118 | + cos(deg2rad(abs($point->getX()-$next_point->getX()))) |
|
119 | 119 | ) |
120 | 120 | ); |
121 | 121 | $degrees += $degree; |
@@ -167,18 +167,18 @@ discard block |
||
167 | 167 | $p3_x = $segment->endPoint()->x(); |
168 | 168 | $p3_y = $segment->endPoint()->y(); |
169 | 169 | |
170 | - $s1_x = $p1_x - $p0_x; $s1_y = $p1_y - $p0_y; |
|
171 | - $s2_x = $p3_x - $p2_x; $s2_y = $p3_y - $p2_y; |
|
170 | + $s1_x = $p1_x-$p0_x; $s1_y = $p1_y-$p0_y; |
|
171 | + $s2_x = $p3_x-$p2_x; $s2_y = $p3_y-$p2_y; |
|
172 | 172 | |
173 | - $fps = (-$s2_x * $s1_y) + ($s1_x * $s2_y); |
|
174 | - $fpt = (-$s2_x * $s1_y) + ($s1_x * $s2_y); |
|
173 | + $fps = (-$s2_x * $s1_y)+($s1_x * $s2_y); |
|
174 | + $fpt = (-$s2_x * $s1_y)+($s1_x * $s2_y); |
|
175 | 175 | |
176 | 176 | if ($fps == 0 || $fpt == 0) { |
177 | 177 | return FALSE; |
178 | 178 | } |
179 | 179 | |
180 | - $s = (-$s1_y * ($p0_x - $p2_x) + $s1_x * ($p0_y - $p2_y)) / $fps; |
|
181 | - $t = ( $s2_x * ($p0_y - $p2_y) - $s2_y * ($p0_x - $p2_x)) / $fpt; |
|
180 | + $s = (-$s1_y * ($p0_x-$p2_x)+$s1_x * ($p0_y-$p2_y)) / $fps; |
|
181 | + $t = ($s2_x * ($p0_y-$p2_y)-$s2_y * ($p0_x-$p2_x)) / $fpt; |
|
182 | 182 | |
183 | 183 | if ($s > 0 && $s < 1 && $t > 0 && $t < 1) { |
184 | 184 | // Collision detected |
@@ -53,7 +53,9 @@ |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | public function dimension() { |
56 | - if ($this->isEmpty()) return 0; |
|
56 | + if ($this->isEmpty()) { |
|
57 | + return 0; |
|
58 | + } |
|
57 | 59 | return 1; |
58 | 60 | } |
59 | 61 |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | public function geomFromText($text) { |
46 | 46 | // Change to lower-case and strip all CDATA |
47 | 47 | $text = strtolower($text); |
48 | - $text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s','',$text); |
|
48 | + $text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s', '', $text); |
|
49 | 49 | |
50 | 50 | // Load into DOMDocument |
51 | 51 | $xmlobj = new DOMDocument(); |
52 | 52 | @$xmlobj->loadXML($text); |
53 | 53 | if ($xmlobj === false) { |
54 | - throw new Exception("Invalid GPX: ". $text); |
|
54 | + throw new Exception("Invalid GPX: ".$text); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | $this->xmlobj = $xmlobj; |
58 | 58 | try { |
59 | 59 | $geom = $this->geomFromXML(); |
60 | - } catch(InvalidText $e) { |
|
61 | - throw new Exception("Cannot Read Geometry From GPX: ". $text); |
|
62 | - } catch(Exception $e) { |
|
60 | + } catch (InvalidText $e) { |
|
61 | + throw new Exception("Cannot Read Geometry From GPX: ".$text); |
|
62 | + } catch (Exception $e) { |
|
63 | 63 | throw $e; |
64 | 64 | } |
65 | 65 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $components[] = new Point($lon, $lat); |
113 | 113 | } |
114 | 114 | } |
115 | - if ($components) {$lines[] = new LineString($components);} |
|
115 | + if ($components) {$lines[] = new LineString($components); } |
|
116 | 116 | } |
117 | 117 | return $lines; |
118 | 118 | } |
@@ -34,7 +34,9 @@ |
||
34 | 34 | * @return string The GPX string representation of the input geometries |
35 | 35 | */ |
36 | 36 | public function write(Geometry $geometry, $namespace = FALSE) { |
37 | - if ($geometry->isEmpty()) return NULL; |
|
37 | + if ($geometry->isEmpty()) { |
|
38 | + return NULL; |
|
39 | + } |
|
38 | 40 | if ($namespace) { |
39 | 41 | $this->namespace = $namespace; |
40 | 42 | $this->nss = $namespace.':'; |
@@ -16,7 +16,7 @@ |
||
16 | 16 | $srid = $geometry->SRID(); |
17 | 17 | $wkt = ''; |
18 | 18 | if ($srid) { |
19 | - $wkt = 'SRID=' . $srid . ';'; |
|
19 | + $wkt = 'SRID='.$srid.';'; |
|
20 | 20 | $wkt .= $geometry->out('wkt'); |
21 | 21 | return $wkt; |
22 | 22 | } |
@@ -19,8 +19,7 @@ |
||
19 | 19 | $wkt = 'SRID=' . $srid . ';'; |
20 | 20 | $wkt .= $geometry->out('wkt'); |
21 | 21 | return $wkt; |
22 | - } |
|
23 | - else { |
|
22 | + } else { |
|
24 | 23 | return $geometry->out('wkt'); |
25 | 24 | } |
26 | 25 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | if ($type == 'GeometryCollection') { |
51 | 51 | return $this->objToGeometryCollection($obj); |
52 | 52 | } |
53 | - $method = 'arrayTo' . $type; |
|
53 | + $method = 'arrayTo'.$type; |
|
54 | 54 | return $this->$method($obj->coordinates); |
55 | 55 | } |
56 | 56 |
@@ -57,8 +57,7 @@ discard block |
||
57 | 57 | private function arrayToPoint($array) { |
58 | 58 | if (!empty($array)) { |
59 | 59 | return new Point($array[0], $array[1]); |
60 | - } |
|
61 | - else { |
|
60 | + } else { |
|
62 | 61 | return new Point(); |
63 | 62 | } |
64 | 63 | } |
@@ -125,8 +124,7 @@ discard block |
||
125 | 124 | public function write(Geometry $geometry, $return_array = FALSE) { |
126 | 125 | if ($return_array) { |
127 | 126 | return $this->getArray($geometry); |
128 | - } |
|
129 | - else { |
|
127 | + } else { |
|
130 | 128 | return json_encode($this->getArray($geometry)); |
131 | 129 | } |
132 | 130 | } |
@@ -144,11 +142,12 @@ discard block |
||
144 | 142 | 'type'=> 'GeometryCollection', |
145 | 143 | 'geometries'=> $component_array, |
146 | 144 | ); |
147 | - } |
|
148 | - else return array( |
|
145 | + } else { |
|
146 | + return array( |
|
149 | 147 | 'type'=> $geometry->getGeomType(), |
150 | 148 | 'coordinates'=> $geometry->asArray(), |
151 | 149 | ); |
150 | + } |
|
152 | 151 | } |
153 | 152 | } |
154 | 153 |
@@ -44,21 +44,21 @@ discard block |
||
44 | 44 | public function geomFromText($text) { |
45 | 45 | // Change to lower-case, strip all CDATA, and de-namespace |
46 | 46 | $text = strtolower($text); |
47 | - $text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s','',$text); |
|
47 | + $text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s', '', $text); |
|
48 | 48 | |
49 | 49 | // Load into DOMDOcument |
50 | 50 | $xmlobj = new DOMDocument(); |
51 | 51 | @$xmlobj->loadXML($text); |
52 | 52 | if ($xmlobj === false) { |
53 | - throw new Exception("Invalid GeoRSS: ". $text); |
|
53 | + throw new Exception("Invalid GeoRSS: ".$text); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | $this->xmlobj = $xmlobj; |
57 | 57 | try { |
58 | 58 | $geom = $this->geomFromXML(); |
59 | - } catch(InvalidText $e) { |
|
60 | - throw new Exception("Cannot Read Geometry From GeoRSS: ". $text); |
|
61 | - } catch(Exception $e) { |
|
59 | + } catch (InvalidText $e) { |
|
60 | + throw new Exception("Cannot Read Geometry From GeoRSS: ".$text); |
|
61 | + } catch (Exception $e) { |
|
62 | 62 | throw $e; |
63 | 63 | } |
64 | 64 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | return $coords; |
88 | 88 | } |
89 | 89 | |
90 | - $latlon = explode(' ',$string); |
|
90 | + $latlon = explode(' ', $string); |
|
91 | 91 | foreach ($latlon as $key => $item) { |
92 | 92 | if (!($key % 2)) { |
93 | 93 | // It's a latitude |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $polygons = array(); |
152 | 152 | $box_elements = $this->xmlobj->getElementsByTagName('box'); |
153 | 153 | foreach ($box_elements as $box) { |
154 | - $parts = explode(' ',trim($box->firstChild->nodeValue)); |
|
154 | + $parts = explode(' ', trim($box->firstChild->nodeValue)); |
|
155 | 155 | $components = array( |
156 | 156 | new Point($parts[3], $parts[2]), |
157 | 157 | new Point($parts[3], $parts[0]), |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $points = array(); |
172 | 172 | $circle_elements = $this->xmlobj->getElementsByTagName('circle'); |
173 | 173 | foreach ($circle_elements as $circle) { |
174 | - $parts = explode(' ',trim($circle->firstChild->nodeValue)); |
|
174 | + $parts = explode(' ', trim($circle->firstChild->nodeValue)); |
|
175 | 175 | $points[] = new Point($parts[1], $parts[0]); |
176 | 176 | } |
177 | 177 | return $points; |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $output = '<'.$this->nss.'line>'; |
213 | 213 | foreach ($geom->getComponents() as $k => $point) { |
214 | 214 | $output .= $point->getY().' '.$point->getX(); |
215 | - if ($k < ($geom->numGeometries() -1)) $output .= ' '; |
|
215 | + if ($k < ($geom->numGeometries()-1)) $output .= ' '; |
|
216 | 216 | } |
217 | 217 | $output .= '</'.$this->nss.'line>'; |
218 | 218 | return $output; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | $exterior_ring = $geom->exteriorRing(); |
224 | 224 | foreach ($exterior_ring->getComponents() as $k => $point) { |
225 | 225 | $output .= $point->getY().' '.$point->getX(); |
226 | - if ($k < ($exterior_ring->numGeometries() -1)) $output .= ' '; |
|
226 | + if ($k < ($exterior_ring->numGeometries()-1)) $output .= ' '; |
|
227 | 227 | } |
228 | 228 | $output .= '</'.$this->nss.'polygon>'; |
229 | 229 | return $output; |
@@ -92,8 +92,7 @@ discard block |
||
92 | 92 | if (!($key % 2)) { |
93 | 93 | // It's a latitude |
94 | 94 | $lat = $item; |
95 | - } |
|
96 | - else { |
|
95 | + } else { |
|
97 | 96 | // It's a longitude |
98 | 97 | $lon = $item; |
99 | 98 | $coords[] = new Point($lon, $lat); |
@@ -111,8 +110,7 @@ discard block |
||
111 | 110 | } |
112 | 111 | if (!empty($point_array)) { |
113 | 112 | $points[] = $point_array[0]; |
114 | - } |
|
115 | - else { |
|
113 | + } else { |
|
116 | 114 | $points[] = new Point(); |
117 | 115 | } |
118 | 116 | } |
@@ -137,8 +135,7 @@ discard block |
||
137 | 135 | $points = $this->getPointsFromCoords(trim($poly->firstChild->nodeValue)); |
138 | 136 | $exterior_ring = new LineString($points); |
139 | 137 | $polygons[] = new Polygon(array($exterior_ring)); |
140 | - } |
|
141 | - else { |
|
138 | + } else { |
|
142 | 139 | // It's an EMPTY polygon |
143 | 140 | $polygons[] = new Polygon(); |
144 | 141 | } |
@@ -212,7 +209,9 @@ discard block |
||
212 | 209 | $output = '<'.$this->nss.'line>'; |
213 | 210 | foreach ($geom->getComponents() as $k => $point) { |
214 | 211 | $output .= $point->getY().' '.$point->getX(); |
215 | - if ($k < ($geom->numGeometries() -1)) $output .= ' '; |
|
212 | + if ($k < ($geom->numGeometries() -1)) { |
|
213 | + $output .= ' '; |
|
214 | + } |
|
216 | 215 | } |
217 | 216 | $output .= '</'.$this->nss.'line>'; |
218 | 217 | return $output; |
@@ -223,7 +222,9 @@ discard block |
||
223 | 222 | $exterior_ring = $geom->exteriorRing(); |
224 | 223 | foreach ($exterior_ring->getComponents() as $k => $point) { |
225 | 224 | $output .= $point->getY().' '.$point->getX(); |
226 | - if ($k < ($exterior_ring->numGeometries() -1)) $output .= ' '; |
|
225 | + if ($k < ($exterior_ring->numGeometries() -1)) { |
|
226 | + $output .= ' '; |
|
227 | + } |
|
227 | 228 | } |
228 | 229 | $output .= '</'.$this->nss.'polygon>'; |
229 | 230 | return $output; |