@@ -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 | } |
@@ -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 |
@@ -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 |
@@ -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; |
@@ -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 |
@@ -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 | } |
@@ -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 | } |
@@ -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 |
@@ -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; |