@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function read($wkb, $is_hex_string = FALSE) { |
32 | 32 | if ($is_hex_string) { |
33 | - $wkb = pack('H*',$wkb); |
|
33 | + $wkb = pack('H*', $wkb); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | if (empty($wkb)) { |
37 | - throw new Exception('Cannot read empty WKB geometry. Found ' . gettype($wkb)); |
|
37 | + throw new Exception('Cannot read empty WKB geometry. Found '.gettype($wkb)); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | $mem = fopen('php://memory', 'r+'); |
@@ -74,20 +74,20 @@ discard block |
||
74 | 74 | case 3: |
75 | 75 | return $this->getPolygon($mem); |
76 | 76 | case 4: |
77 | - return $this->getMulti($mem,'point'); |
|
77 | + return $this->getMulti($mem, 'point'); |
|
78 | 78 | case 5: |
79 | - return $this->getMulti($mem,'line'); |
|
79 | + return $this->getMulti($mem, 'line'); |
|
80 | 80 | case 6: |
81 | - return $this->getMulti($mem,'polygon'); |
|
81 | + return $this->getMulti($mem, 'polygon'); |
|
82 | 82 | case 7: |
83 | - return $this->getMulti($mem,'geometry'); |
|
83 | + return $this->getMulti($mem, 'geometry'); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | 87 | function getPoint(&$mem) { |
88 | - $point_coords = unpack("d*", fread($mem,$this->dimension*8)); |
|
88 | + $point_coords = unpack("d*", fread($mem, $this->dimension * 8)); |
|
89 | 89 | if (!empty($point_coords)) { |
90 | - return new Point($point_coords[1],$point_coords[2]); |
|
90 | + return new Point($point_coords[1], $point_coords[2]); |
|
91 | 91 | } |
92 | 92 | else { |
93 | 93 | return new Point(); // EMPTY point |
@@ -96,20 +96,20 @@ discard block |
||
96 | 96 | |
97 | 97 | function getLinstring(&$mem) { |
98 | 98 | // Get the number of points expected in this string out of the first 4 bytes |
99 | - $line_length = unpack('L',fread($mem,4)); |
|
99 | + $line_length = unpack('L', fread($mem, 4)); |
|
100 | 100 | |
101 | 101 | // Return an empty linestring if there is no line-length |
102 | 102 | if (!$line_length[1]) return new LineString(); |
103 | 103 | |
104 | 104 | // Read the nubmer of points x2 (each point is two coords) into decimal-floats |
105 | - $line_coords = unpack('d*', fread($mem,$line_length[1]*$this->dimension*8)); |
|
105 | + $line_coords = unpack('d*', fread($mem, $line_length[1] * $this->dimension * 8)); |
|
106 | 106 | |
107 | 107 | // We have our coords, build up the linestring |
108 | 108 | $components = array(); |
109 | 109 | $i = 1; |
110 | 110 | $num_coords = count($line_coords); |
111 | 111 | while ($i <= $num_coords) { |
112 | - $components[] = new Point($line_coords[$i],$line_coords[$i+1]); |
|
112 | + $components[] = new Point($line_coords[$i], $line_coords[$i+1]); |
|
113 | 113 | $i += 2; |
114 | 114 | } |
115 | 115 | return new LineString($components); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | function getPolygon(&$mem) { |
119 | 119 | // Get the number of linestring expected in this poly out of the first 4 bytes |
120 | - $poly_length = unpack('L',fread($mem,4)); |
|
120 | + $poly_length = unpack('L', fread($mem, 4)); |
|
121 | 121 | |
122 | 122 | $components = array(); |
123 | 123 | $i = 1; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | function getMulti(&$mem, $type) { |
132 | 132 | // Get the number of items expected in this multi out of the first 4 bytes |
133 | - $multi_length = unpack('L',fread($mem,4)); |
|
133 | + $multi_length = unpack('L', fread($mem, 4)); |
|
134 | 134 | |
135 | 135 | $components = array(); |
136 | 136 | $i = 1; |
@@ -159,41 +159,41 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public function write(Geometry $geometry, $write_as_hex = FALSE) { |
161 | 161 | // We always write into NDR (little endian) |
162 | - $wkb = pack('c',1); |
|
162 | + $wkb = pack('c', 1); |
|
163 | 163 | |
164 | 164 | switch ($geometry->getGeomType()) { |
165 | 165 | case 'Point'; |
166 | - $wkb .= pack('L',1); |
|
166 | + $wkb .= pack('L', 1); |
|
167 | 167 | $wkb .= $this->writePoint($geometry); |
168 | 168 | break; |
169 | 169 | case 'LineString'; |
170 | - $wkb .= pack('L',2); |
|
170 | + $wkb .= pack('L', 2); |
|
171 | 171 | $wkb .= $this->writeLineString($geometry); |
172 | 172 | break; |
173 | 173 | case 'Polygon'; |
174 | - $wkb .= pack('L',3); |
|
174 | + $wkb .= pack('L', 3); |
|
175 | 175 | $wkb .= $this->writePolygon($geometry); |
176 | 176 | break; |
177 | 177 | case 'MultiPoint'; |
178 | - $wkb .= pack('L',4); |
|
178 | + $wkb .= pack('L', 4); |
|
179 | 179 | $wkb .= $this->writeMulti($geometry); |
180 | 180 | break; |
181 | 181 | case 'MultiLineString'; |
182 | - $wkb .= pack('L',5); |
|
182 | + $wkb .= pack('L', 5); |
|
183 | 183 | $wkb .= $this->writeMulti($geometry); |
184 | 184 | break; |
185 | 185 | case 'MultiPolygon'; |
186 | - $wkb .= pack('L',6); |
|
186 | + $wkb .= pack('L', 6); |
|
187 | 187 | $wkb .= $this->writeMulti($geometry); |
188 | 188 | break; |
189 | 189 | case 'GeometryCollection'; |
190 | - $wkb .= pack('L',7); |
|
190 | + $wkb .= pack('L', 7); |
|
191 | 191 | $wkb .= $this->writeMulti($geometry); |
192 | 192 | break; |
193 | 193 | } |
194 | 194 | |
195 | 195 | if ($write_as_hex) { |
196 | - $unpacked = unpack('H*',$wkb); |
|
196 | + $unpacked = unpack('H*', $wkb); |
|
197 | 197 | return $unpacked[1]; |
198 | 198 | } |
199 | 199 | else { |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | function writePoint($point) { |
205 | 205 | // Set the coords |
206 | 206 | if (!$point->isEmpty()) { |
207 | - $wkb = pack('dd',$point->x(), $point->y()); |
|
207 | + $wkb = pack('dd', $point->x(), $point->y()); |
|
208 | 208 | return $wkb; |
209 | 209 | } else { |
210 | 210 | return ''; |
@@ -213,11 +213,11 @@ discard block |
||
213 | 213 | |
214 | 214 | function writeLineString($line) { |
215 | 215 | // Set the number of points in this line |
216 | - $wkb = pack('L',$line->numPoints()); |
|
216 | + $wkb = pack('L', $line->numPoints()); |
|
217 | 217 | |
218 | 218 | // Set the coords |
219 | 219 | foreach ($line->getComponents() as $point) { |
220 | - $wkb .= pack('dd',$point->x(), $point->y()); |
|
220 | + $wkb .= pack('dd', $point->x(), $point->y()); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | return $wkb; |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | |
226 | 226 | function writePolygon($poly) { |
227 | 227 | // Set the number of lines in this poly |
228 | - $wkb = pack('L',$poly->numGeometries()); |
|
228 | + $wkb = pack('L', $poly->numGeometries()); |
|
229 | 229 | |
230 | 230 | // Write the lines |
231 | 231 | foreach ($poly->getComponents() as $line) { |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | function writeMulti($geometry) { |
239 | 239 | // Set the number of components |
240 | - $wkb = pack('L',$geometry->numGeometries()); |
|
240 | + $wkb = pack('L', $geometry->numGeometries()); |
|
241 | 241 | |
242 | 242 | // Write the components |
243 | 243 | foreach ($geometry->getComponents() as $component) { |
@@ -88,8 +88,7 @@ discard block |
||
88 | 88 | $point_coords = unpack("d*", fread($mem,$this->dimension*8)); |
89 | 89 | if (!empty($point_coords)) { |
90 | 90 | return new Point($point_coords[1],$point_coords[2]); |
91 | - } |
|
92 | - else { |
|
91 | + } else { |
|
93 | 92 | return new Point(); // EMPTY point |
94 | 93 | } |
95 | 94 | } |
@@ -99,7 +98,9 @@ discard block |
||
99 | 98 | $line_length = unpack('L',fread($mem,4)); |
100 | 99 | |
101 | 100 | // Return an empty linestring if there is no line-length |
102 | - if (!$line_length[1]) return new LineString(); |
|
101 | + if (!$line_length[1]) { |
|
102 | + return new LineString(); |
|
103 | + } |
|
103 | 104 | |
104 | 105 | // Read the nubmer of points x2 (each point is two coords) into decimal-floats |
105 | 106 | $line_coords = unpack('d*', fread($mem,$line_length[1]*$this->dimension*8)); |
@@ -195,8 +196,7 @@ discard block |
||
195 | 196 | if ($write_as_hex) { |
196 | 197 | $unpacked = unpack('H*',$wkb); |
197 | 198 | return $unpacked[1]; |
198 | - } |
|
199 | - else { |
|
199 | + } else { |
|
200 | 200 | return $wkb; |
201 | 201 | } |
202 | 202 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @see http://en.wikipedia.org/wiki/Geohash |
7 | 7 | * |
8 | 8 | */ |
9 | -class GeoHash extends GeoAdapter{ |
|
9 | +class GeoHash extends GeoAdapter { |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * base32 encoding character map. |
@@ -16,24 +16,24 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * array of neighbouring hash character maps. |
18 | 18 | */ |
19 | - private $neighbours = array ( |
|
19 | + private $neighbours = array( |
|
20 | 20 | // north |
21 | - 'top' => array ( |
|
21 | + 'top' => array( |
|
22 | 22 | 'even' => 'p0r21436x8zb9dcf5h7kjnmqesgutwvy', |
23 | 23 | 'odd' => 'bc01fg45238967deuvhjyznpkmstqrwx' |
24 | 24 | ), |
25 | 25 | // east |
26 | - 'right' => array ( |
|
26 | + 'right' => array( |
|
27 | 27 | 'even' => 'bc01fg45238967deuvhjyznpkmstqrwx', |
28 | 28 | 'odd' => 'p0r21436x8zb9dcf5h7kjnmqesgutwvy' |
29 | 29 | ), |
30 | 30 | // west |
31 | - 'left' => array ( |
|
31 | + 'left' => array( |
|
32 | 32 | 'even' => '238967debc01fg45kmstqrwxuvhjyznp', |
33 | 33 | 'odd' => '14365h7k9dcfesgujnmqp0r2twvyx8zb' |
34 | 34 | ), |
35 | 35 | // south |
36 | - 'bottom' => array ( |
|
36 | + 'bottom' => array( |
|
37 | 37 | 'even' => '14365h7k9dcfesgujnmqp0r2twvyx8zb', |
38 | 38 | 'odd' => '238967debc01fg45kmstqrwxuvhjyznp' |
39 | 39 | ) |
@@ -42,24 +42,24 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * array of bordering hash character maps. |
44 | 44 | */ |
45 | - private $borders = array ( |
|
45 | + private $borders = array( |
|
46 | 46 | // north |
47 | - 'top' => array ( |
|
47 | + 'top' => array( |
|
48 | 48 | 'even' => 'prxz', |
49 | 49 | 'odd' => 'bcfguvyz' |
50 | 50 | ), |
51 | 51 | // east |
52 | - 'right' => array ( |
|
52 | + 'right' => array( |
|
53 | 53 | 'even' => 'bcfguvyz', |
54 | 54 | 'odd' => 'prxz' |
55 | 55 | ), |
56 | 56 | // west |
57 | - 'left' => array ( |
|
57 | + 'left' => array( |
|
58 | 58 | 'even' => '0145hjnp', |
59 | 59 | 'odd' => '028b' |
60 | 60 | ), |
61 | 61 | // south |
62 | - 'bottom' => array ( |
|
62 | + 'bottom' => array( |
|
63 | 63 | 'even' => '028b', |
64 | 64 | 'odd' => '0145hjnp' |
65 | 65 | ) |
@@ -95,10 +95,10 @@ discard block |
||
95 | 95 | * @param Point $geometry |
96 | 96 | * @see GeoAdapter::write() |
97 | 97 | */ |
98 | - public function write(Geometry $geometry, $precision = NULL){ |
|
98 | + public function write(Geometry $geometry, $precision = NULL) { |
|
99 | 99 | if ($geometry->isEmpty()) return ''; |
100 | 100 | |
101 | - if($geometry->geometryType() === 'Point'){ |
|
101 | + if ($geometry->geometryType() === 'Point') { |
|
102 | 102 | return $this->encodePoint($geometry, $precision); |
103 | 103 | } |
104 | 104 | else { |
@@ -130,30 +130,30 @@ discard block |
||
130 | 130 | * @author algorithm based on code by Alexander Songe <[email protected]> |
131 | 131 | * @see https://github.com/asonge/php-geohash/issues/1 |
132 | 132 | */ |
133 | - private function encodePoint($point, $precision = NULL){ |
|
133 | + private function encodePoint($point, $precision = NULL) { |
|
134 | 134 | if ($precision === NULL) { |
135 | - $lap = strlen($point->y())-strpos($point->y(),"."); |
|
136 | - $lop = strlen($point->x())-strpos($point->x(),"."); |
|
137 | - $precision = pow(10,-max($lap-1,$lop-1,0))/2; |
|
135 | + $lap = strlen($point->y())-strpos($point->y(), "."); |
|
136 | + $lop = strlen($point->x())-strpos($point->x(), "."); |
|
137 | + $precision = pow(10, -max($lap-1, $lop-1, 0)) / 2; |
|
138 | 138 | } |
139 | 139 | |
140 | - $minlat = -90; |
|
141 | - $maxlat = 90; |
|
140 | + $minlat = -90; |
|
141 | + $maxlat = 90; |
|
142 | 142 | $minlon = -180; |
143 | - $maxlon = 180; |
|
144 | - $latE = 90; |
|
145 | - $lonE = 180; |
|
143 | + $maxlon = 180; |
|
144 | + $latE = 90; |
|
145 | + $lonE = 180; |
|
146 | 146 | $i = 0; |
147 | 147 | $error = 180; |
148 | - $hash=''; |
|
149 | - while($error>=$precision) { |
|
148 | + $hash = ''; |
|
149 | + while ($error >= $precision) { |
|
150 | 150 | $chr = 0; |
151 | - for($b=4;$b>=0;--$b) { |
|
152 | - if((1&$b) == (1&$i)) { |
|
151 | + for ($b = 4; $b >= 0; --$b) { |
|
152 | + if ((1&$b) == (1&$i)) { |
|
153 | 153 | // even char, even bit OR odd char, odd bit...a lon |
154 | - $next = ($minlon+$maxlon)/2; |
|
155 | - if($point->x()>$next) { |
|
156 | - $chr |= pow(2,$b); |
|
154 | + $next = ($minlon+$maxlon) / 2; |
|
155 | + if ($point->x() > $next) { |
|
156 | + $chr |= pow(2, $b); |
|
157 | 157 | $minlon = $next; |
158 | 158 | } else { |
159 | 159 | $maxlon = $next; |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | $lonE /= 2; |
162 | 162 | } else { |
163 | 163 | // odd char, even bit OR even char, odd bit...a lat |
164 | - $next = ($minlat+$maxlat)/2; |
|
165 | - if($point->y()>$next) { |
|
166 | - $chr |= pow(2,$b); |
|
164 | + $next = ($minlat+$maxlat) / 2; |
|
165 | + if ($point->y() > $next) { |
|
166 | + $chr |= pow(2, $b); |
|
167 | 167 | $minlat = $next; |
168 | 168 | } else { |
169 | 169 | $maxlat = $next; |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | } |
174 | 174 | $hash .= $this->table[$chr]; |
175 | 175 | $i++; |
176 | - $error = min($latE,$lonE); |
|
176 | + $error = min($latE, $lonE); |
|
177 | 177 | } |
178 | 178 | return $hash; |
179 | 179 | } |
@@ -183,30 +183,30 @@ discard block |
||
183 | 183 | * @author algorithm based on code by Alexander Songe <[email protected]> |
184 | 184 | * @see https://github.com/asonge/php-geohash/issues/1 |
185 | 185 | */ |
186 | - private function decode($hash){ |
|
186 | + private function decode($hash) { |
|
187 | 187 | $ll = array(); |
188 | - $minlat = -90; |
|
189 | - $maxlat = 90; |
|
188 | + $minlat = -90; |
|
189 | + $maxlat = 90; |
|
190 | 190 | $minlon = -180; |
191 | - $maxlon = 180; |
|
192 | - $latE = 90; |
|
193 | - $lonE = 180; |
|
194 | - for($i=0,$c=strlen($hash);$i<$c;$i++) { |
|
195 | - $v = strpos($this->table,$hash[$i]); |
|
196 | - if(1&$i) { |
|
197 | - if(16&$v)$minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
198 | - if(8&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
199 | - if(4&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
200 | - if(2&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
201 | - if(1&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
191 | + $maxlon = 180; |
|
192 | + $latE = 90; |
|
193 | + $lonE = 180; |
|
194 | + for ($i = 0, $c = strlen($hash); $i < $c; $i++) { |
|
195 | + $v = strpos($this->table, $hash[$i]); |
|
196 | + if (1&$i) { |
|
197 | + if (16&$v)$minlat = ($minlat+$maxlat) / 2; else $maxlat = ($minlat+$maxlat) / 2; |
|
198 | + if (8&$v) $minlon = ($minlon+$maxlon) / 2; else $maxlon = ($minlon+$maxlon) / 2; |
|
199 | + if (4&$v) $minlat = ($minlat+$maxlat) / 2; else $maxlat = ($minlat+$maxlat) / 2; |
|
200 | + if (2&$v) $minlon = ($minlon+$maxlon) / 2; else $maxlon = ($minlon+$maxlon) / 2; |
|
201 | + if (1&$v) $minlat = ($minlat+$maxlat) / 2; else $maxlat = ($minlat+$maxlat) / 2; |
|
202 | 202 | $latE /= 8; |
203 | 203 | $lonE /= 4; |
204 | 204 | } else { |
205 | - if(16&$v)$minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
206 | - if(8&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
207 | - if(4&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
208 | - if(2&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
209 | - if(1&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
205 | + if (16&$v)$minlon = ($minlon+$maxlon) / 2; else $maxlon = ($minlon+$maxlon) / 2; |
|
206 | + if (8&$v) $minlat = ($minlat+$maxlat) / 2; else $maxlat = ($minlat+$maxlat) / 2; |
|
207 | + if (4&$v) $minlon = ($minlon+$maxlon) / 2; else $maxlon = ($minlon+$maxlon) / 2; |
|
208 | + if (2&$v) $minlat = ($minlat+$maxlat) / 2; else $maxlat = ($minlat+$maxlat) / 2; |
|
209 | + if (1&$v) $minlon = ($minlon+$maxlon) / 2; else $maxlon = ($minlon+$maxlon) / 2; |
|
210 | 210 | $latE /= 4; |
211 | 211 | $lonE /= 8; |
212 | 212 | } |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | $ll['minlon'] = $minlon; |
216 | 216 | $ll['maxlat'] = $maxlat; |
217 | 217 | $ll['maxlon'] = $maxlon; |
218 | - $ll['medlat'] = round(($minlat+$maxlat)/2, max(1, -round(log10($latE)))-1); |
|
219 | - $ll['medlon'] = round(($minlon+$maxlon)/2, max(1, -round(log10($lonE)))-1); |
|
218 | + $ll['medlat'] = round(($minlat+$maxlat) / 2, max(1, -round(log10($latE)))-1); |
|
219 | + $ll['medlon'] = round(($minlon+$maxlon) / 2, max(1, -round(log10($lonE)))-1); |
|
220 | 220 | return $ll; |
221 | 221 | } |
222 | 222 | |
@@ -237,11 +237,11 @@ discard block |
||
237 | 237 | * @param string $direction the direction of the neighbor (top, bottom, left or right) |
238 | 238 | * @return string the geohash of the adjacent cell |
239 | 239 | */ |
240 | - public function adjacent($hash, $direction){ |
|
240 | + public function adjacent($hash, $direction) { |
|
241 | 241 | $last = substr($hash, -1); |
242 | - $type = (strlen($hash) % 2)? 'odd': 'even'; |
|
243 | - $base = substr($hash, 0, strlen($hash) - 1); |
|
244 | - if(strpos(($this->borders[$direction][$type]), $last) !== false){ |
|
242 | + $type = (strlen($hash) % 2) ? 'odd' : 'even'; |
|
243 | + $base = substr($hash, 0, strlen($hash)-1); |
|
244 | + if (strpos(($this->borders[$direction][$type]), $last) !== false) { |
|
245 | 245 | $base = $this->adjacent($base, $direction); |
246 | 246 | } |
247 | 247 | return $base.$this->table[strpos($this->neighbours[$direction][$type], $last)]; |
@@ -75,8 +75,7 @@ discard block |
||
75 | 75 | $ll = $this->decode($hash); |
76 | 76 | if (!$as_grid) { |
77 | 77 | return new Point($ll['medlon'], $ll['medlat']); |
78 | - } |
|
79 | - else { |
|
78 | + } else { |
|
80 | 79 | return new Polygon(array( |
81 | 80 | new LineString(array( |
82 | 81 | new Point($ll['minlon'], $ll['maxlat']), |
@@ -96,12 +95,13 @@ discard block |
||
96 | 95 | * @see GeoAdapter::write() |
97 | 96 | */ |
98 | 97 | public function write(Geometry $geometry, $precision = NULL){ |
99 | - if ($geometry->isEmpty()) return ''; |
|
98 | + if ($geometry->isEmpty()) { |
|
99 | + return ''; |
|
100 | + } |
|
100 | 101 | |
101 | 102 | if($geometry->geometryType() === 'Point'){ |
102 | 103 | return $this->encodePoint($geometry, $precision); |
103 | - } |
|
104 | - else { |
|
104 | + } else { |
|
105 | 105 | // The geohash is the hash grid ID that fits the envelope |
106 | 106 | $envelope = $geometry->envelope(); |
107 | 107 | $geohashes = array(); |
@@ -194,19 +194,59 @@ discard block |
||
194 | 194 | for($i=0,$c=strlen($hash);$i<$c;$i++) { |
195 | 195 | $v = strpos($this->table,$hash[$i]); |
196 | 196 | if(1&$i) { |
197 | - if(16&$v)$minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
198 | - if(8&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
199 | - if(4&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
200 | - if(2&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
201 | - if(1&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
197 | + if(16&$v) { |
|
198 | + $minlat = ($minlat+$maxlat)/2; |
|
199 | + } else { |
|
200 | + $maxlat = ($minlat+$maxlat)/2; |
|
201 | + } |
|
202 | + if(8&$v) { |
|
203 | + $minlon = ($minlon+$maxlon)/2; |
|
204 | + } else { |
|
205 | + $maxlon = ($minlon+$maxlon)/2; |
|
206 | + } |
|
207 | + if(4&$v) { |
|
208 | + $minlat = ($minlat+$maxlat)/2; |
|
209 | + } else { |
|
210 | + $maxlat = ($minlat+$maxlat)/2; |
|
211 | + } |
|
212 | + if(2&$v) { |
|
213 | + $minlon = ($minlon+$maxlon)/2; |
|
214 | + } else { |
|
215 | + $maxlon = ($minlon+$maxlon)/2; |
|
216 | + } |
|
217 | + if(1&$v) { |
|
218 | + $minlat = ($minlat+$maxlat)/2; |
|
219 | + } else { |
|
220 | + $maxlat = ($minlat+$maxlat)/2; |
|
221 | + } |
|
202 | 222 | $latE /= 8; |
203 | 223 | $lonE /= 4; |
204 | 224 | } else { |
205 | - if(16&$v)$minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
206 | - if(8&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
207 | - if(4&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
208 | - if(2&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
209 | - if(1&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
225 | + if(16&$v) { |
|
226 | + $minlon = ($minlon+$maxlon)/2; |
|
227 | + } else { |
|
228 | + $maxlon = ($minlon+$maxlon)/2; |
|
229 | + } |
|
230 | + if(8&$v) { |
|
231 | + $minlat = ($minlat+$maxlat)/2; |
|
232 | + } else { |
|
233 | + $maxlat = ($minlat+$maxlat)/2; |
|
234 | + } |
|
235 | + if(4&$v) { |
|
236 | + $minlon = ($minlon+$maxlon)/2; |
|
237 | + } else { |
|
238 | + $maxlon = ($minlon+$maxlon)/2; |
|
239 | + } |
|
240 | + if(2&$v) { |
|
241 | + $minlat = ($minlat+$maxlat)/2; |
|
242 | + } else { |
|
243 | + $maxlat = ($minlat+$maxlat)/2; |
|
244 | + } |
|
245 | + if(1&$v) { |
|
246 | + $minlon = ($minlon+$maxlon)/2; |
|
247 | + } else { |
|
248 | + $maxlon = ($minlon+$maxlon)/2; |
|
249 | + } |
|
210 | 250 | $latE /= 4; |
211 | 251 | $lonE /= 8; |
212 | 252 | } |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | $wkt = trim($wkt); |
17 | 17 | |
18 | 18 | // If it contains a ';', then it contains additional SRID data |
19 | - if (strpos($wkt,';')) { |
|
19 | + if (strpos($wkt, ';')) { |
|
20 | 20 | $parts = explode(';', $wkt); |
21 | 21 | $wkt = $parts[1]; |
22 | - $eparts = explode('=',$parts[0]); |
|
22 | + $eparts = explode('=', $parts[0]); |
|
23 | 23 | $srid = $eparts[1]; |
24 | 24 | } |
25 | 25 | else { |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | // If it's marked as empty, then return an empty point |
68 | 68 | if ($data_string == 'EMPTY') return new Point(); |
69 | 69 | |
70 | - $parts = explode(' ',$data_string); |
|
70 | + $parts = explode(' ', $data_string); |
|
71 | 71 | return new Point($parts[0], $parts[1]); |
72 | 72 | } |
73 | 73 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | // If it's marked as empty, then return an empty line |
78 | 78 | if ($data_string == 'EMPTY') return new LineString(); |
79 | 79 | |
80 | - $parts = explode(',',$data_string); |
|
80 | + $parts = explode(',', $data_string); |
|
81 | 81 | $points = array(); |
82 | 82 | foreach ($parts as $part) { |
83 | 83 | $points[] = $this->parsePoint($part); |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | // If it's marked as empty, then return an empty polygon |
92 | 92 | if ($data_string == 'EMPTY') return new Polygon(); |
93 | 93 | |
94 | - $parts = explode('),(',$data_string); |
|
94 | + $parts = explode('),(', $data_string); |
|
95 | 95 | $lines = array(); |
96 | 96 | foreach ($parts as $part) { |
97 | - if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
|
98 | - if (!$this->endsWith($part,')')) $part = $part . ')'; |
|
97 | + if (!$this->beginsWith($part, '(')) $part = '('.$part; |
|
98 | + if (!$this->endsWith($part, ')')) $part = $part.')'; |
|
99 | 99 | $lines[] = $this->parseLineString($part); |
100 | 100 | } |
101 | 101 | return new Polygon($lines); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | // If it's marked as empty, then return an empty MutiPoint |
108 | 108 | if ($data_string == 'EMPTY') return new MultiPoint(); |
109 | 109 | |
110 | - $parts = explode(',',$data_string); |
|
110 | + $parts = explode(',', $data_string); |
|
111 | 111 | $points = array(); |
112 | 112 | foreach ($parts as $part) { |
113 | 113 | $points[] = $this->parsePoint($part); |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | // If it's marked as empty, then return an empty multi-linestring |
122 | 122 | if ($data_string == 'EMPTY') return new MultiLineString(); |
123 | 123 | |
124 | - $parts = explode('),(',$data_string); |
|
124 | + $parts = explode('),(', $data_string); |
|
125 | 125 | $lines = array(); |
126 | 126 | foreach ($parts as $part) { |
127 | 127 | // Repair the string if the explode broke it |
128 | - if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
|
129 | - if (!$this->endsWith($part,')')) $part = $part . ')'; |
|
128 | + if (!$this->beginsWith($part, '(')) $part = '('.$part; |
|
129 | + if (!$this->endsWith($part, ')')) $part = $part.')'; |
|
130 | 130 | $lines[] = $this->parseLineString($part); |
131 | 131 | } |
132 | 132 | return new MultiLineString($lines); |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | // If it's marked as empty, then return an empty multi-polygon |
139 | 139 | if ($data_string == 'EMPTY') return new MultiPolygon(); |
140 | 140 | |
141 | - $parts = explode(')),((',$data_string); |
|
141 | + $parts = explode(')),((', $data_string); |
|
142 | 142 | $polys = array(); |
143 | 143 | foreach ($parts as $part) { |
144 | 144 | // Repair the string if the explode broke it |
145 | - if (!$this->beginsWith($part,'((')) $part = '((' . $part; |
|
146 | - if (!$this->endsWith($part,'))')) $part = $part . '))'; |
|
145 | + if (!$this->beginsWith($part, '((')) $part = '(('.$part; |
|
146 | + if (!$this->endsWith($part, '))')) $part = $part.'))'; |
|
147 | 147 | $polys[] = $this->parsePolygon($part); |
148 | 148 | } |
149 | 149 | return new MultiPolygon($polys); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | |
172 | 172 | if ($first_paren !== FALSE) { |
173 | 173 | return substr($wkt, $first_paren); |
174 | - } elseif (strstr($wkt,'EMPTY')) { |
|
174 | + } elseif (strstr($wkt, 'EMPTY')) { |
|
175 | 175 | return 'EMPTY'; |
176 | 176 | } else |
177 | 177 | return FALSE; |
@@ -185,18 +185,18 @@ discard block |
||
185 | 185 | |
186 | 186 | // We want to only strip off one set of parenthesis |
187 | 187 | if ($this->beginsWith($str, '(')) { |
188 | - return substr($str,1,-1); |
|
188 | + return substr($str, 1, -1); |
|
189 | 189 | } |
190 | 190 | else return $str; |
191 | 191 | } |
192 | 192 | |
193 | 193 | protected function beginsWith($str, $char) { |
194 | - if (substr($str,0,strlen($char)) == $char) return TRUE; |
|
194 | + if (substr($str, 0, strlen($char)) == $char) return TRUE; |
|
195 | 195 | else return FALSE; |
196 | 196 | } |
197 | 197 | |
198 | 198 | protected function endsWith($str, $char) { |
199 | - if (substr($str,(0 - strlen($char))) == $char) return TRUE; |
|
199 | + if (substr($str, (0-strlen($char))) == $char) return TRUE; |
|
200 | 200 | else return FALSE; |
201 | 201 | } |
202 | 202 |
@@ -21,8 +21,7 @@ discard block |
||
21 | 21 | $wkt = $parts[1]; |
22 | 22 | $eparts = explode('=',$parts[0]); |
23 | 23 | $srid = $eparts[1]; |
24 | - } |
|
25 | - else { |
|
24 | + } else { |
|
26 | 25 | $srid = NULL; |
27 | 26 | } |
28 | 27 | |
@@ -33,8 +32,7 @@ discard block |
||
33 | 32 | $geom = geoPHP::geosToGeometry($reader->read($wkt)); |
34 | 33 | $geom->setSRID($srid); |
35 | 34 | return $geom; |
36 | - } |
|
37 | - else { |
|
35 | + } else { |
|
38 | 36 | return geoPHP::geosToGeometry($reader->read($wkt)); |
39 | 37 | } |
40 | 38 | } |
@@ -52,8 +50,7 @@ discard block |
||
52 | 50 | $geom = $this->$method($data_string); |
53 | 51 | $geom->setSRID($srid); |
54 | 52 | return $geom; |
55 | - } |
|
56 | - else { |
|
53 | + } else { |
|
57 | 54 | return $this->$method($data_string); |
58 | 55 | } |
59 | 56 | |
@@ -65,7 +62,9 @@ discard block |
||
65 | 62 | $data_string = $this->trimParens($data_string); |
66 | 63 | |
67 | 64 | // If it's marked as empty, then return an empty point |
68 | - if ($data_string == 'EMPTY') return new Point(); |
|
65 | + if ($data_string == 'EMPTY') { |
|
66 | + return new Point(); |
|
67 | + } |
|
69 | 68 | |
70 | 69 | $parts = explode(' ',$data_string); |
71 | 70 | return new Point($parts[0], $parts[1]); |
@@ -75,7 +74,9 @@ discard block |
||
75 | 74 | $data_string = $this->trimParens($data_string); |
76 | 75 | |
77 | 76 | // If it's marked as empty, then return an empty line |
78 | - if ($data_string == 'EMPTY') return new LineString(); |
|
77 | + if ($data_string == 'EMPTY') { |
|
78 | + return new LineString(); |
|
79 | + } |
|
79 | 80 | |
80 | 81 | $parts = explode(',',$data_string); |
81 | 82 | $points = array(); |
@@ -89,13 +90,19 @@ discard block |
||
89 | 90 | $data_string = $this->trimParens($data_string); |
90 | 91 | |
91 | 92 | // If it's marked as empty, then return an empty polygon |
92 | - if ($data_string == 'EMPTY') return new Polygon(); |
|
93 | + if ($data_string == 'EMPTY') { |
|
94 | + return new Polygon(); |
|
95 | + } |
|
93 | 96 | |
94 | 97 | $parts = explode('),(',$data_string); |
95 | 98 | $lines = array(); |
96 | 99 | foreach ($parts as $part) { |
97 | - if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
|
98 | - if (!$this->endsWith($part,')')) $part = $part . ')'; |
|
100 | + if (!$this->beginsWith($part,'(')) { |
|
101 | + $part = '(' . $part; |
|
102 | + } |
|
103 | + if (!$this->endsWith($part,')')) { |
|
104 | + $part = $part . ')'; |
|
105 | + } |
|
99 | 106 | $lines[] = $this->parseLineString($part); |
100 | 107 | } |
101 | 108 | return new Polygon($lines); |
@@ -105,7 +112,9 @@ discard block |
||
105 | 112 | $data_string = $this->trimParens($data_string); |
106 | 113 | |
107 | 114 | // If it's marked as empty, then return an empty MutiPoint |
108 | - if ($data_string == 'EMPTY') return new MultiPoint(); |
|
115 | + if ($data_string == 'EMPTY') { |
|
116 | + return new MultiPoint(); |
|
117 | + } |
|
109 | 118 | |
110 | 119 | $parts = explode(',',$data_string); |
111 | 120 | $points = array(); |
@@ -119,14 +128,20 @@ discard block |
||
119 | 128 | $data_string = $this->trimParens($data_string); |
120 | 129 | |
121 | 130 | // If it's marked as empty, then return an empty multi-linestring |
122 | - if ($data_string == 'EMPTY') return new MultiLineString(); |
|
131 | + if ($data_string == 'EMPTY') { |
|
132 | + return new MultiLineString(); |
|
133 | + } |
|
123 | 134 | |
124 | 135 | $parts = explode('),(',$data_string); |
125 | 136 | $lines = array(); |
126 | 137 | foreach ($parts as $part) { |
127 | 138 | // Repair the string if the explode broke it |
128 | - if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
|
129 | - if (!$this->endsWith($part,')')) $part = $part . ')'; |
|
139 | + if (!$this->beginsWith($part,'(')) { |
|
140 | + $part = '(' . $part; |
|
141 | + } |
|
142 | + if (!$this->endsWith($part,')')) { |
|
143 | + $part = $part . ')'; |
|
144 | + } |
|
130 | 145 | $lines[] = $this->parseLineString($part); |
131 | 146 | } |
132 | 147 | return new MultiLineString($lines); |
@@ -136,14 +151,20 @@ discard block |
||
136 | 151 | $data_string = $this->trimParens($data_string); |
137 | 152 | |
138 | 153 | // If it's marked as empty, then return an empty multi-polygon |
139 | - if ($data_string == 'EMPTY') return new MultiPolygon(); |
|
154 | + if ($data_string == 'EMPTY') { |
|
155 | + return new MultiPolygon(); |
|
156 | + } |
|
140 | 157 | |
141 | 158 | $parts = explode(')),((',$data_string); |
142 | 159 | $polys = array(); |
143 | 160 | foreach ($parts as $part) { |
144 | 161 | // Repair the string if the explode broke it |
145 | - if (!$this->beginsWith($part,'((')) $part = '((' . $part; |
|
146 | - if (!$this->endsWith($part,'))')) $part = $part . '))'; |
|
162 | + if (!$this->beginsWith($part,'((')) { |
|
163 | + $part = '((' . $part; |
|
164 | + } |
|
165 | + if (!$this->endsWith($part,'))')) { |
|
166 | + $part = $part . '))'; |
|
167 | + } |
|
147 | 168 | $polys[] = $this->parsePolygon($part); |
148 | 169 | } |
149 | 170 | return new MultiPolygon($polys); |
@@ -153,7 +174,9 @@ discard block |
||
153 | 174 | $data_string = $this->trimParens($data_string); |
154 | 175 | |
155 | 176 | // If it's marked as empty, then return an empty geom-collection |
156 | - if ($data_string == 'EMPTY') return new GeometryCollection(); |
|
177 | + if ($data_string == 'EMPTY') { |
|
178 | + return new GeometryCollection(); |
|
179 | + } |
|
157 | 180 | |
158 | 181 | $geometries = array(); |
159 | 182 | $matches = array(); |
@@ -173,8 +196,9 @@ discard block |
||
173 | 196 | return substr($wkt, $first_paren); |
174 | 197 | } elseif (strstr($wkt,'EMPTY')) { |
175 | 198 | return 'EMPTY'; |
176 | - } else |
|
177 | - return FALSE; |
|
199 | + } else { |
|
200 | + return FALSE; |
|
201 | + } |
|
178 | 202 | } |
179 | 203 | |
180 | 204 | /** |
@@ -186,18 +210,25 @@ discard block |
||
186 | 210 | // We want to only strip off one set of parenthesis |
187 | 211 | if ($this->beginsWith($str, '(')) { |
188 | 212 | return substr($str,1,-1); |
213 | + } else { |
|
214 | + return $str; |
|
189 | 215 | } |
190 | - else return $str; |
|
191 | 216 | } |
192 | 217 | |
193 | 218 | protected function beginsWith($str, $char) { |
194 | - if (substr($str,0,strlen($char)) == $char) return TRUE; |
|
195 | - else return FALSE; |
|
219 | + if (substr($str,0,strlen($char)) == $char) { |
|
220 | + return TRUE; |
|
221 | + } else { |
|
222 | + return FALSE; |
|
223 | + } |
|
196 | 224 | } |
197 | 225 | |
198 | 226 | protected function endsWith($str, $char) { |
199 | - if (substr($str,(0 - strlen($char))) == $char) return TRUE; |
|
200 | - else return FALSE; |
|
227 | + if (substr($str,(0 - strlen($char))) == $char) { |
|
228 | + return TRUE; |
|
229 | + } else { |
|
230 | + return FALSE; |
|
231 | + } |
|
201 | 232 | } |
202 | 233 | |
203 | 234 | /** |
@@ -217,8 +248,7 @@ discard block |
||
217 | 248 | |
218 | 249 | if ($geometry->isEmpty()) { |
219 | 250 | return strtoupper($geometry->geometryType()).' EMPTY'; |
220 | - } |
|
221 | - else if ($data = $this->extractData($geometry)) { |
|
251 | + } else if ($data = $this->extractData($geometry)) { |
|
222 | 252 | return strtoupper($geometry->geometryType()).' ('.$data.')'; |
223 | 253 | } |
224 | 254 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function read($wkb, $is_hex_string = FALSE) { |
16 | 16 | if ($is_hex_string) { |
17 | - $wkb = pack('H*',$wkb); |
|
17 | + $wkb = pack('H*', $wkb); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | // Open the wkb up in memory so we can examine the SRID |
@@ -51,41 +51,41 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function write(Geometry $geometry, $write_as_hex = FALSE) { |
53 | 53 | // We always write into NDR (little endian) |
54 | - $wkb = pack('c',1); |
|
54 | + $wkb = pack('c', 1); |
|
55 | 55 | |
56 | 56 | switch ($geometry->getGeomType()) { |
57 | 57 | case 'Point'; |
58 | - $wkb .= pack('L',1); |
|
58 | + $wkb .= pack('L', 1); |
|
59 | 59 | $wkb .= $this->writePoint($geometry); |
60 | 60 | break; |
61 | 61 | case 'LineString'; |
62 | - $wkb .= pack('L',2); |
|
62 | + $wkb .= pack('L', 2); |
|
63 | 63 | $wkb .= $this->writeLineString($geometry); |
64 | 64 | break; |
65 | 65 | case 'Polygon'; |
66 | - $wkb .= pack('L',3); |
|
66 | + $wkb .= pack('L', 3); |
|
67 | 67 | $wkb .= $this->writePolygon($geometry); |
68 | 68 | break; |
69 | 69 | case 'MultiPoint'; |
70 | - $wkb .= pack('L',4); |
|
70 | + $wkb .= pack('L', 4); |
|
71 | 71 | $wkb .= $this->writeMulti($geometry); |
72 | 72 | break; |
73 | 73 | case 'MultiLineString'; |
74 | - $wkb .= pack('L',5); |
|
74 | + $wkb .= pack('L', 5); |
|
75 | 75 | $wkb .= $this->writeMulti($geometry); |
76 | 76 | break; |
77 | 77 | case 'MultiPolygon'; |
78 | - $wkb .= pack('L',6); |
|
78 | + $wkb .= pack('L', 6); |
|
79 | 79 | $wkb .= $this->writeMulti($geometry); |
80 | 80 | break; |
81 | 81 | case 'GeometryCollection'; |
82 | - $wkb .= pack('L',7); |
|
82 | + $wkb .= pack('L', 7); |
|
83 | 83 | $wkb .= $this->writeMulti($geometry); |
84 | 84 | break; |
85 | 85 | } |
86 | 86 | |
87 | 87 | if ($write_as_hex) { |
88 | - $unpacked = unpack('H*',$wkb); |
|
88 | + $unpacked = unpack('H*', $wkb); |
|
89 | 89 | return $unpacked[1]; |
90 | 90 | } |
91 | 91 | else { |
@@ -24,8 +24,7 @@ discard block |
||
24 | 24 | $base_info = unpack("corder/ctype/cz/cm/cs", fread($mem, 5)); |
25 | 25 | if ($base_info['s']) { |
26 | 26 | $srid = current(unpack("Lsrid", fread($mem, 4))); |
27 | - } |
|
28 | - else { |
|
27 | + } else { |
|
29 | 28 | $srid = NULL; |
30 | 29 | } |
31 | 30 | fclose($mem); |
@@ -87,8 +86,7 @@ discard block |
||
87 | 86 | if ($write_as_hex) { |
88 | 87 | $unpacked = unpack('H*',$wkb); |
89 | 88 | return $unpacked[1]; |
90 | - } |
|
91 | - else { |
|
89 | + } else { |
|
92 | 90 | return $wkb; |
93 | 91 | } |
94 | 92 | } |
@@ -52,21 +52,21 @@ discard block |
||
52 | 52 | public function geomFromText($text) { |
53 | 53 | // Change to lower-case and strip all CDATA |
54 | 54 | $text = mb_strtolower($text, mb_detect_encoding($text)); |
55 | - $text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s','',$text); |
|
55 | + $text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s', '', $text); |
|
56 | 56 | |
57 | 57 | // Load into DOMDocument |
58 | 58 | $xmlobj = new DOMDocument(); |
59 | 59 | @$xmlobj->loadXML($text); |
60 | 60 | if ($xmlobj === false) { |
61 | - throw new Exception("Invalid KML: ". $text); |
|
61 | + throw new Exception("Invalid KML: ".$text); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | $this->xmlobj = $xmlobj; |
65 | 65 | try { |
66 | 66 | $geom = $this->geomFromXML(); |
67 | - } catch(InvalidText $e) { |
|
68 | - throw new Exception("Cannot Read Geometry From KML: ". $text); |
|
69 | - } catch(Exception $e) { |
|
67 | + } catch (InvalidText $e) { |
|
68 | + throw new Exception("Cannot Read Geometry From KML: ".$text); |
|
69 | + } catch (Exception $e) { |
|
70 | 70 | throw $e; |
71 | 71 | } |
72 | 72 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | protected function parsePoint($xml) { |
116 | 116 | $coordinates = $this->_extractCoordinates($xml); |
117 | 117 | if (!empty($coordinates)) { |
118 | - return new Point($coordinates[0][0],$coordinates[0][1]); |
|
118 | + return new Point($coordinates[0][0], $coordinates[0][1]); |
|
119 | 119 | } |
120 | 120 | else { |
121 | 121 | return new Point(); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $coordinates = $this->_extractCoordinates($xml); |
127 | 127 | $point_array = array(); |
128 | 128 | foreach ($coordinates as $set) { |
129 | - $point_array[] = new Point($set[0],$set[1]); |
|
129 | + $point_array[] = new Point($set[0], $set[1]); |
|
130 | 130 | } |
131 | 131 | return new LineString($point_array); |
132 | 132 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | foreach ($coord_sets as $set_string) { |
181 | 181 | $set_string = trim($set_string); |
182 | 182 | if ($set_string) { |
183 | - $set_array = explode(',',$set_string); |
|
183 | + $set_array = explode(',', $set_string); |
|
184 | 184 | if (count($set_array) >= 2) { |
185 | 185 | $coordinates[] = $set_array; |
186 | 186 | } |
@@ -226,21 +226,21 @@ discard block |
||
226 | 226 | $type = $geom->getGeomType(); |
227 | 227 | } |
228 | 228 | |
229 | - $str = '<'.$this->nss . $type .'>'; |
|
229 | + $str = '<'.$this->nss.$type.'>'; |
|
230 | 230 | |
231 | 231 | if (!$geom->isEmpty()) { |
232 | 232 | $str .= '<'.$this->nss.'coordinates>'; |
233 | - $i=0; |
|
233 | + $i = 0; |
|
234 | 234 | foreach ($geom->getComponents() as $comp) { |
235 | 235 | if ($i != 0) $str .= ' '; |
236 | - $str .= $comp->getX() .','. $comp->getY(); |
|
236 | + $str .= $comp->getX().','.$comp->getY(); |
|
237 | 237 | $i++; |
238 | 238 | } |
239 | 239 | |
240 | 240 | $str .= '</'.$this->nss.'coordinates>'; |
241 | 241 | } |
242 | 242 | |
243 | - $str .= '</'. $this->nss . $type .'>'; |
|
243 | + $str .= '</'.$this->nss.$type.'>'; |
|
244 | 244 | |
245 | 245 | return $str; |
246 | 246 | } |
@@ -249,13 +249,13 @@ discard block |
||
249 | 249 | $components = $geom->getComponents(); |
250 | 250 | $str = ''; |
251 | 251 | if (!empty($components)) { |
252 | - $str = '<'.$this->nss.'outerBoundaryIs>' . $this->linestringToKML($components[0], 'LinearRing') . '</'.$this->nss.'outerBoundaryIs>'; |
|
252 | + $str = '<'.$this->nss.'outerBoundaryIs>'.$this->linestringToKML($components[0], 'LinearRing').'</'.$this->nss.'outerBoundaryIs>'; |
|
253 | 253 | foreach (array_slice($components, 1) as $comp) { |
254 | - $str .= '<'.$this->nss.'innerBoundaryIs>' . $this->linestringToKML($comp) . '</'.$this->nss.'innerBoundaryIs>'; |
|
254 | + $str .= '<'.$this->nss.'innerBoundaryIs>'.$this->linestringToKML($comp).'</'.$this->nss.'innerBoundaryIs>'; |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | - return '<'.$this->nss.'Polygon>'. $str .'</'.$this->nss.'Polygon>'; |
|
258 | + return '<'.$this->nss.'Polygon>'.$str.'</'.$this->nss.'Polygon>'; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | public function collectionToKML($geom) { |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $str .= $sub_adapter->write($comp); |
267 | 267 | } |
268 | 268 | |
269 | - return $str .'</'.$this->nss.'MultiGeometry>'; |
|
269 | + return $str.'</'.$this->nss.'MultiGeometry>'; |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | } |
@@ -88,8 +88,7 @@ discard block |
||
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | - } |
|
92 | - else { |
|
91 | + } else { |
|
93 | 92 | // The document does not have a placemark, try to create a valid geometry from the root element |
94 | 93 | $node_name = $this->xmlobj->documentElement->nodeName == 'multigeometry' ? 'geometrycollection' : $this->xmlobj->documentElement->nodeName; |
95 | 94 | if (array_key_exists($node_name, $geom_types)) { |
@@ -116,8 +115,7 @@ discard block |
||
116 | 115 | $coordinates = $this->_extractCoordinates($xml); |
117 | 116 | if (!empty($coordinates)) { |
118 | 117 | return new Point($coordinates[0][0],$coordinates[0][1]); |
119 | - } |
|
120 | - else { |
|
118 | + } else { |
|
121 | 119 | return new Point(); |
122 | 120 | } |
123 | 121 | } |
@@ -232,7 +230,9 @@ discard block |
||
232 | 230 | $str .= '<'.$this->nss.'coordinates>'; |
233 | 231 | $i=0; |
234 | 232 | foreach ($geom->getComponents() as $comp) { |
235 | - if ($i != 0) $str .= ' '; |
|
233 | + if ($i != 0) { |
|
234 | + $str .= ' '; |
|
235 | + } |
|
236 | 236 | $str .= $comp->getX() .','. $comp->getY(); |
237 | 237 | $i++; |
238 | 238 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | static function getAdapterMap() { |
93 | - return array ( |
|
93 | + return array( |
|
94 | 94 | 'wkt' => 'WKT', |
95 | 95 | 'ewkt' => 'EWKT', |
96 | 96 | 'wkb' => 'WKB', |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | |
154 | 154 | // If the geometry cannot even theoretically be reduced more, then pass it back |
155 | 155 | if (gettype($geometry) == 'object') { |
156 | - $passbacks = array('Point','LineString','Polygon'); |
|
157 | - if (in_array($geometry->geometryType(),$passbacks)) { |
|
156 | + $passbacks = array('Point', 'LineString', 'Polygon'); |
|
157 | + if (in_array($geometry->geometryType(), $passbacks)) { |
|
158 | 158 | return $geometry; |
159 | 159 | } |
160 | 160 | } |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | // If it is a mutlti-geometry, check to see if it just has one member |
163 | 163 | // If it does, then pass the member, if not, then just pass back the geometry |
164 | 164 | if (gettype($geometry) == 'object') { |
165 | - $simple_collections = array('MultiPoint','MultiLineString','MultiPolygon'); |
|
166 | - if (in_array(get_class($geometry),$passbacks)) { |
|
165 | + $simple_collections = array('MultiPoint', 'MultiLineString', 'MultiPolygon'); |
|
166 | + if (in_array(get_class($geometry), $passbacks)) { |
|
167 | 167 | $components = $geometry->getComponents(); |
168 | 168 | if (count($components) == 1) { |
169 | 169 | return $components[0]; |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $geometries = array(); |
183 | 183 | $geom_types = array(); |
184 | 184 | |
185 | - $collections = array('MultiPoint','MultiLineString','MultiPolygon','GeometryCollection'); |
|
185 | + $collections = array('MultiPoint', 'MultiLineString', 'MultiPolygon', 'GeometryCollection'); |
|
186 | 186 | |
187 | 187 | foreach ($geometry as $item) { |
188 | 188 | if ($item) { |
@@ -52,7 +52,9 @@ discard block |
||
52 | 52 | if (!$type) { |
53 | 53 | // If the user is trying to load a Geometry from a Geometry... Just pass it back |
54 | 54 | if (is_object($data)) { |
55 | - if ($data instanceOf Geometry) return $data; |
|
55 | + if ($data instanceOf Geometry) { |
|
56 | + return $data; |
|
57 | + } |
|
56 | 58 | } |
57 | 59 | |
58 | 60 | $detected = geoPHP::detectFormat($data); |
@@ -119,7 +121,9 @@ discard block |
||
119 | 121 | |
120 | 122 | static function geosInstalled($force = NULL) { |
121 | 123 | static $geos_installed = NULL; |
122 | - if ($force !== NULL) $geos_installed = $force; |
|
124 | + if ($force !== NULL) { |
|
125 | + $geos_installed = $force; |
|
126 | + } |
|
123 | 127 | if ($geos_installed !== NULL) { |
124 | 128 | return $geos_installed; |
125 | 129 | } |
@@ -147,8 +151,12 @@ discard block |
||
147 | 151 | static function geometryReduce($geometry) { |
148 | 152 | // If it's an array of one, then just parse the one |
149 | 153 | if (is_array($geometry)) { |
150 | - if (empty($geometry)) return FALSE; |
|
151 | - if (count($geometry) == 1) return geoPHP::geometryReduce(array_shift($geometry)); |
|
154 | + if (empty($geometry)) { |
|
155 | + return FALSE; |
|
156 | + } |
|
157 | + if (count($geometry) == 1) { |
|
158 | + return geoPHP::geometryReduce(array_shift($geometry)); |
|
159 | + } |
|
152 | 160 | } |
153 | 161 | |
154 | 162 | // If the geometry cannot even theoretically be reduced more, then pass it back |
@@ -167,8 +175,7 @@ discard block |
||
167 | 175 | $components = $geometry->getComponents(); |
168 | 176 | if (count($components) == 1) { |
169 | 177 | return $components[0]; |
170 | - } |
|
171 | - else { |
|
178 | + } else { |
|
172 | 179 | return $geometry; |
173 | 180 | } |
174 | 181 | } |
@@ -191,8 +198,7 @@ discard block |
||
191 | 198 | $geometries[] = $component; |
192 | 199 | $geom_types[] = $component->geometryType(); |
193 | 200 | } |
194 | - } |
|
195 | - else { |
|
201 | + } else { |
|
196 | 202 | $geometries[] = $item; |
197 | 203 | $geom_types[] = $item->geometryType(); |
198 | 204 | } |
@@ -208,13 +214,11 @@ discard block |
||
208 | 214 | if (count($geom_types) == 1) { |
209 | 215 | if (count($geometries) == 1) { |
210 | 216 | return $geometries[0]; |
211 | - } |
|
212 | - else { |
|
217 | + } else { |
|
213 | 218 | $class = 'Multi'.$geom_types[0]; |
214 | 219 | return new $class($geometries); |
215 | 220 | } |
216 | - } |
|
217 | - else { |
|
221 | + } else { |
|
218 | 222 | return new GeometryCollection($geometries); |
219 | 223 | } |
220 | 224 | } |
@@ -229,7 +233,9 @@ discard block |
||
229 | 233 | $bytes = unpack("c*", fread($mem, 11)); |
230 | 234 | |
231 | 235 | // If bytes is empty, then we were passed empty input |
232 | - if (empty($bytes)) return FALSE; |
|
236 | + if (empty($bytes)) { |
|
237 | + return FALSE; |
|
238 | + } |
|
233 | 239 | |
234 | 240 | // First char is a tab, space or carriage-return. trim it and try again |
235 | 241 | if ($bytes[1] == 9 || $bytes[1] == 10 || $bytes[1] == 32) { |
@@ -240,8 +246,11 @@ discard block |
||
240 | 246 | // Detect WKB or EWKB -- first byte is 1 (little endian indicator) |
241 | 247 | if ($bytes[1] == 1) { |
242 | 248 | // If SRID byte is TRUE (1), it's EWKB |
243 | - if ($bytes[5]) return 'ewkb'; |
|
244 | - else return 'wkb'; |
|
249 | + if ($bytes[5]) { |
|
250 | + return 'ewkb'; |
|
251 | + } else { |
|
252 | + return 'wkb'; |
|
253 | + } |
|
245 | 254 | } |
246 | 255 | |
247 | 256 | // Detect HEX encoded WKB or EWKB (PostGIS format) -- first byte is 48, second byte is 49 (hex '01' => first-byte = 1) |
@@ -274,12 +283,24 @@ discard block |
||
274 | 283 | if ($bytes[1] == 60) { |
275 | 284 | // grab the first 256 characters |
276 | 285 | $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'; |
|
286 | + if (strpos($string, '<kml') !== FALSE) { |
|
287 | + return 'kml'; |
|
288 | + } |
|
289 | + if (strpos($string, '<coordinate') !== FALSE) { |
|
290 | + return 'kml'; |
|
291 | + } |
|
292 | + if (strpos($string, '<gpx') !== FALSE) { |
|
293 | + return 'gpx'; |
|
294 | + } |
|
295 | + if (strpos($string, '<georss') !== FALSE) { |
|
296 | + return 'georss'; |
|
297 | + } |
|
298 | + if (strpos($string, '<rss') !== FALSE) { |
|
299 | + return 'georss'; |
|
300 | + } |
|
301 | + if (strpos($string, '<feed') !== FALSE) { |
|
302 | + return 'georss'; |
|
303 | + } |
|
283 | 304 | } |
284 | 305 | |
285 | 306 | // We need an 8 byte string for geohash and unpacked WKB / WKT |
@@ -30,7 +30,7 @@ |
||
30 | 30 | * Simple test to make sure the plugin.info.txt is in correct format |
31 | 31 | */ |
32 | 32 | public function test_plugininfo() { |
33 | - $file = __DIR__ . '/../plugin.info.txt'; |
|
33 | + $file = __DIR__.'/../plugin.info.txt'; |
|
34 | 34 | $this->assertFileExists($file); |
35 | 35 | |
36 | 36 | $info = confToHash($file); |