@@ -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 | |
@@ -71,7 +68,9 @@ discard block |
||
71 | 68 | $data_string = $this->trimParens($data_string); |
72 | 69 | |
73 | 70 | // If it's marked as empty, then return an empty line |
74 | - if ($data_string == 'EMPTY') return new LineString(); |
|
71 | + if ($data_string == 'EMPTY') { |
|
72 | + return new LineString(); |
|
73 | + } |
|
75 | 74 | |
76 | 75 | $parts = explode(',',$data_string); |
77 | 76 | $points = array(); |
@@ -85,13 +84,19 @@ discard block |
||
85 | 84 | $data_string = $this->trimParens($data_string); |
86 | 85 | |
87 | 86 | // If it's marked as empty, then return an empty polygon |
88 | - if ($data_string == 'EMPTY') return new Polygon(); |
|
87 | + if ($data_string == 'EMPTY') { |
|
88 | + return new Polygon(); |
|
89 | + } |
|
89 | 90 | |
90 | 91 | $parts = explode('),(',$data_string); |
91 | 92 | $lines = array(); |
92 | 93 | foreach ($parts as $part) { |
93 | - if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
|
94 | - if (!$this->endsWith($part,')')) $part = $part . ')'; |
|
94 | + if (!$this->beginsWith($part,'(')) { |
|
95 | + $part = '(' . $part; |
|
96 | + } |
|
97 | + if (!$this->endsWith($part,')')) { |
|
98 | + $part = $part . ')'; |
|
99 | + } |
|
95 | 100 | $lines[] = $this->parseLineString($part); |
96 | 101 | } |
97 | 102 | return new Polygon($lines); |
@@ -101,7 +106,9 @@ discard block |
||
101 | 106 | $data_string = $this->trimParens($data_string); |
102 | 107 | |
103 | 108 | // If it's marked as empty, then return an empty MutiPoint |
104 | - if ($data_string == 'EMPTY') return new MultiPoint(); |
|
109 | + if ($data_string == 'EMPTY') { |
|
110 | + return new MultiPoint(); |
|
111 | + } |
|
105 | 112 | |
106 | 113 | $parts = explode(',',$data_string); |
107 | 114 | $points = array(); |
@@ -115,14 +122,20 @@ discard block |
||
115 | 122 | $data_string = $this->trimParens($data_string); |
116 | 123 | |
117 | 124 | // If it's marked as empty, then return an empty multi-linestring |
118 | - if ($data_string == 'EMPTY') return new MultiLineString(); |
|
125 | + if ($data_string == 'EMPTY') { |
|
126 | + return new MultiLineString(); |
|
127 | + } |
|
119 | 128 | |
120 | 129 | $parts = explode('),(',$data_string); |
121 | 130 | $lines = array(); |
122 | 131 | foreach ($parts as $part) { |
123 | 132 | // Repair the string if the explode broke it |
124 | - if (!$this->beginsWith($part,'(')) $part = '(' . $part; |
|
125 | - if (!$this->endsWith($part,')')) $part = $part . ')'; |
|
133 | + if (!$this->beginsWith($part,'(')) { |
|
134 | + $part = '(' . $part; |
|
135 | + } |
|
136 | + if (!$this->endsWith($part,')')) { |
|
137 | + $part = $part . ')'; |
|
138 | + } |
|
126 | 139 | $lines[] = $this->parseLineString($part); |
127 | 140 | } |
128 | 141 | return new MultiLineString($lines); |
@@ -132,14 +145,20 @@ discard block |
||
132 | 145 | $data_string = $this->trimParens($data_string); |
133 | 146 | |
134 | 147 | // If it's marked as empty, then return an empty multi-polygon |
135 | - if ($data_string == 'EMPTY') return new MultiPolygon(); |
|
148 | + if ($data_string == 'EMPTY') { |
|
149 | + return new MultiPolygon(); |
|
150 | + } |
|
136 | 151 | |
137 | 152 | $parts = explode(')),((',$data_string); |
138 | 153 | $polys = array(); |
139 | 154 | foreach ($parts as $part) { |
140 | 155 | // Repair the string if the explode broke it |
141 | - if (!$this->beginsWith($part,'((')) $part = '((' . $part; |
|
142 | - if (!$this->endsWith($part,'))')) $part = $part . '))'; |
|
156 | + if (!$this->beginsWith($part,'((')) { |
|
157 | + $part = '((' . $part; |
|
158 | + } |
|
159 | + if (!$this->endsWith($part,'))')) { |
|
160 | + $part = $part . '))'; |
|
161 | + } |
|
143 | 162 | $polys[] = $this->parsePolygon($part); |
144 | 163 | } |
145 | 164 | return new MultiPolygon($polys); |
@@ -149,7 +168,9 @@ discard block |
||
149 | 168 | $data_string = $this->trimParens($data_string); |
150 | 169 | |
151 | 170 | // If it's marked as empty, then return an empty geom-collection |
152 | - if ($data_string == 'EMPTY') return new GeometryCollection(); |
|
171 | + if ($data_string == 'EMPTY') { |
|
172 | + return new GeometryCollection(); |
|
173 | + } |
|
153 | 174 | |
154 | 175 | $geometries = array(); |
155 | 176 | $matches = array(); |
@@ -180,18 +201,25 @@ discard block |
||
180 | 201 | // We want to only strip off one set of parenthesis |
181 | 202 | if ($this->beginsWith($str, '(')) { |
182 | 203 | return substr($str,1,-1); |
204 | + } else { |
|
205 | + return $str; |
|
183 | 206 | } |
184 | - else return $str; |
|
185 | 207 | } |
186 | 208 | |
187 | 209 | protected function beginsWith($str, $char) { |
188 | - if (substr($str,0,strlen($char)) == $char) return TRUE; |
|
189 | - else return FALSE; |
|
210 | + if (substr($str,0,strlen($char)) == $char) { |
|
211 | + return TRUE; |
|
212 | + } else { |
|
213 | + return FALSE; |
|
214 | + } |
|
190 | 215 | } |
191 | 216 | |
192 | 217 | protected function endsWith($str, $char) { |
193 | - if (substr($str,(0 - strlen($char))) == $char) return TRUE; |
|
194 | - else return FALSE; |
|
218 | + if (substr($str,(0 - strlen($char))) == $char) { |
|
219 | + return TRUE; |
|
220 | + } else { |
|
221 | + return FALSE; |
|
222 | + } |
|
195 | 223 | } |
196 | 224 | |
197 | 225 | /** |
@@ -211,8 +239,7 @@ discard block |
||
211 | 239 | |
212 | 240 | if ($geometry->isEmpty()) { |
213 | 241 | return strtoupper($geometry->geometryType()).' EMPTY'; |
214 | - } |
|
215 | - else if ($data = $this->extractData($geometry)) { |
|
242 | + } else if ($data = $this->extractData($geometry)) { |
|
216 | 243 | return strtoupper($geometry->geometryType()).' ('.$data.')'; |
217 | 244 | } |
218 | 245 | } |
@@ -30,15 +30,16 @@ discard block |
||
30 | 30 | * @return Geometry|GeometryCollection |
31 | 31 | */ |
32 | 32 | public function read($address, $return_type = 'point', $bounds = FALSE, $return_multiple = FALSE) { |
33 | - if (is_array($address)) $address = join(',', $address); |
|
33 | + if (is_array($address)) { |
|
34 | + $address = join(',', $address); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | if (gettype($bounds) == 'object') { |
36 | 38 | $bounds = $bounds->getBBox(); |
37 | 39 | } |
38 | 40 | if (gettype($bounds) == 'array') { |
39 | 41 | $bounds_string = '&bounds='.$bounds['miny'].','.$bounds['minx'].'|'.$bounds['maxy'].','.$bounds['maxx']; |
40 | - } |
|
41 | - else { |
|
42 | + } else { |
|
42 | 43 | $bounds_string = ''; |
43 | 44 | } |
44 | 45 | |
@@ -73,10 +74,12 @@ discard block |
||
73 | 74 | return new MultiPolygon($polygons); |
74 | 75 | } |
75 | 76 | } |
76 | - } |
|
77 | - else { |
|
78 | - if ($this->result->status) throw new Exception('Error in Google Geocoder: '.$this->result->status); |
|
79 | - else throw new Exception('Unknown error in Google Geocoder'); |
|
77 | + } else { |
|
78 | + if ($this->result->status) { |
|
79 | + throw new Exception('Error in Google Geocoder: '.$this->result->status); |
|
80 | + } else { |
|
81 | + throw new Exception('Unknown error in Google Geocoder'); |
|
82 | + } |
|
80 | 83 | return FALSE; |
81 | 84 | } |
82 | 85 | } |
@@ -106,10 +109,12 @@ discard block |
||
106 | 109 | if ($return_type == 'array') { |
107 | 110 | return $this->result->results[0]->address_components; |
108 | 111 | } |
109 | - } |
|
110 | - else { |
|
111 | - if ($this->result->status) throw new Exception('Error in Google Reverse Geocoder: '.$this->result->status); |
|
112 | - else throw new Exception('Unknown error in Google Reverse Geocoder'); |
|
112 | + } else { |
|
113 | + if ($this->result->status) { |
|
114 | + throw new Exception('Error in Google Reverse Geocoder: '.$this->result->status); |
|
115 | + } else { |
|
116 | + throw new Exception('Unknown error in Google Reverse Geocoder'); |
|
117 | + } |
|
113 | 118 | return FALSE; |
114 | 119 | } |
115 | 120 | } |
@@ -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 | } |
@@ -19,8 +19,7 @@ discard block |
||
19 | 19 | $ll = $this->decode($hash); |
20 | 20 | if (!$as_grid) { |
21 | 21 | return new Point($ll['medlon'], $ll['medlat']); |
22 | - } |
|
23 | - else { |
|
22 | + } else { |
|
24 | 23 | return new Polygon(array( |
25 | 24 | new LineString(array( |
26 | 25 | new Point($ll['minlon'], $ll['maxlat']), |
@@ -40,12 +39,13 @@ discard block |
||
40 | 39 | * @see GeoAdapter::write() |
41 | 40 | */ |
42 | 41 | public function write(Geometry $geometry, $precision = NULL){ |
43 | - if ($geometry->isEmpty()) return ''; |
|
42 | + if ($geometry->isEmpty()) { |
|
43 | + return ''; |
|
44 | + } |
|
44 | 45 | |
45 | 46 | if($geometry->geometryType() === 'Point'){ |
46 | 47 | return $this->encodePoint($geometry, $precision); |
47 | - } |
|
48 | - else { |
|
48 | + } else { |
|
49 | 49 | // The geohash is the hash grid ID that fits the envelope |
50 | 50 | $envelope = $geometry->envelope(); |
51 | 51 | $geohashes = array(); |
@@ -138,19 +138,59 @@ discard block |
||
138 | 138 | for($i=0,$c=strlen($hash);$i<$c;$i++) { |
139 | 139 | $v = strpos($this->table,$hash[$i]); |
140 | 140 | if(1&$i) { |
141 | - if(16&$v)$minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
142 | - if(8&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
143 | - if(4&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
144 | - if(2&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
145 | - if(1&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
141 | + if(16&$v) { |
|
142 | + $minlat = ($minlat+$maxlat)/2; |
|
143 | + } else { |
|
144 | + $maxlat = ($minlat+$maxlat)/2; |
|
145 | + } |
|
146 | + if(8&$v) { |
|
147 | + $minlon = ($minlon+$maxlon)/2; |
|
148 | + } else { |
|
149 | + $maxlon = ($minlon+$maxlon)/2; |
|
150 | + } |
|
151 | + if(4&$v) { |
|
152 | + $minlat = ($minlat+$maxlat)/2; |
|
153 | + } else { |
|
154 | + $maxlat = ($minlat+$maxlat)/2; |
|
155 | + } |
|
156 | + if(2&$v) { |
|
157 | + $minlon = ($minlon+$maxlon)/2; |
|
158 | + } else { |
|
159 | + $maxlon = ($minlon+$maxlon)/2; |
|
160 | + } |
|
161 | + if(1&$v) { |
|
162 | + $minlat = ($minlat+$maxlat)/2; |
|
163 | + } else { |
|
164 | + $maxlat = ($minlat+$maxlat)/2; |
|
165 | + } |
|
146 | 166 | $latE /= 8; |
147 | 167 | $lonE /= 4; |
148 | 168 | } else { |
149 | - if(16&$v)$minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
150 | - if(8&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
151 | - if(4&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
152 | - if(2&$v) $minlat = ($minlat+$maxlat)/2; else $maxlat = ($minlat+$maxlat)/2; |
|
153 | - if(1&$v) $minlon = ($minlon+$maxlon)/2; else $maxlon = ($minlon+$maxlon)/2; |
|
169 | + if(16&$v) { |
|
170 | + $minlon = ($minlon+$maxlon)/2; |
|
171 | + } else { |
|
172 | + $maxlon = ($minlon+$maxlon)/2; |
|
173 | + } |
|
174 | + if(8&$v) { |
|
175 | + $minlat = ($minlat+$maxlat)/2; |
|
176 | + } else { |
|
177 | + $maxlat = ($minlat+$maxlat)/2; |
|
178 | + } |
|
179 | + if(4&$v) { |
|
180 | + $minlon = ($minlon+$maxlon)/2; |
|
181 | + } else { |
|
182 | + $maxlon = ($minlon+$maxlon)/2; |
|
183 | + } |
|
184 | + if(2&$v) { |
|
185 | + $minlat = ($minlat+$maxlat)/2; |
|
186 | + } else { |
|
187 | + $maxlat = ($minlat+$maxlat)/2; |
|
188 | + } |
|
189 | + if(1&$v) { |
|
190 | + $minlon = ($minlon+$maxlon)/2; |
|
191 | + } else { |
|
192 | + $maxlon = ($minlon+$maxlon)/2; |
|
193 | + } |
|
154 | 194 | $latE /= 4; |
155 | 195 | $lonE /= 8; |
156 | 196 | } |
@@ -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.':'; |
@@ -120,8 +120,7 @@ discard block |
||
120 | 120 | public function write(Geometry $geometry, $return_array = FALSE) { |
121 | 121 | if ($return_array) { |
122 | 122 | return $this->getArray($geometry); |
123 | - } |
|
124 | - else { |
|
123 | + } else { |
|
125 | 124 | return json_encode($this->getArray($geometry)); |
126 | 125 | } |
127 | 126 | } |
@@ -139,11 +138,12 @@ discard block |
||
139 | 138 | 'type'=> 'GeometryCollection', |
140 | 139 | 'geometries'=> $component_array, |
141 | 140 | ); |
142 | - } |
|
143 | - else return array( |
|
141 | + } else { |
|
142 | + return array( |
|
144 | 143 | 'type'=> $geometry->getGeomType(), |
145 | 144 | 'coordinates'=> $geometry->asArray(), |
146 | 145 | ); |
146 | + } |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 |
@@ -94,7 +94,9 @@ discard block |
||
94 | 94 | $line_length = unpack('L',fread($mem,4)); |
95 | 95 | |
96 | 96 | // Return an empty linestring if there is no line-length |
97 | - if (!$line_length[1]) return new LineString(); |
|
97 | + if (!$line_length[1]) { |
|
98 | + return new LineString(); |
|
99 | + } |
|
98 | 100 | |
99 | 101 | // Read the nubmer of points x2 (each point is two coords) into decimal-floats |
100 | 102 | $line_coords = unpack('d*', fread($mem,$line_length[1]*$this->dimension*8)); |
@@ -190,8 +192,7 @@ discard block |
||
190 | 192 | if ($write_as_hex) { |
191 | 193 | $unpacked = unpack('H*',$wkb); |
192 | 194 | return $unpacked[1]; |
193 | - } |
|
194 | - else { |
|
195 | + } else { |
|
195 | 196 | return $wkb; |
196 | 197 | } |
197 | 198 | } |
@@ -89,8 +89,7 @@ discard block |
||
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | - } |
|
93 | - else { |
|
92 | + } else { |
|
94 | 93 | // The document does not have a placemark, try to create a valid geometry from the root element |
95 | 94 | $node_name = $this->xmlobj->documentElement->nodeName == 'multigeometry' ? 'geometrycollection' : $this->xmlobj->documentElement->nodeName; |
96 | 95 | if (array_key_exists($node_name, $geom_types)) { |
@@ -220,7 +219,9 @@ discard block |
||
220 | 219 | $str .= '<'.$this->nss.'coordinates>'; |
221 | 220 | $i=0; |
222 | 221 | foreach ($geom->getComponents() as $comp) { |
223 | - if ($i != 0) $str .= ' '; |
|
222 | + if ($i != 0) { |
|
223 | + $str .= ' '; |
|
224 | + } |
|
224 | 225 | $str .= $comp->getX() .','. $comp->getY(); |
225 | 226 | $i++; |
226 | 227 | } |
@@ -9,7 +9,9 @@ discard block |
||
9 | 9 | protected $geom_type = 'Polygon'; |
10 | 10 | |
11 | 11 | public function area($exterior_only = FALSE, $signed = FALSE) { |
12 | - if ($this->isEmpty()) return 0; |
|
12 | + if ($this->isEmpty()) { |
|
13 | + return 0; |
|
14 | + } |
|
13 | 15 | |
14 | 16 | if ($this->geos() && $exterior_only == FALSE) { |
15 | 17 | return $this->geos()->area(); |
@@ -19,15 +21,20 @@ discard block |
||
19 | 21 | $pts = $exterior_ring->getComponents(); |
20 | 22 | |
21 | 23 | $c = count($pts); |
22 | - if((int)$c == '0') return NULL; |
|
24 | + if((int)$c == '0') { |
|
25 | + return NULL; |
|
26 | + } |
|
23 | 27 | $a = '0'; |
24 | 28 | foreach($pts as $k => $p){ |
25 | 29 | $j = ($k + 1) % $c; |
26 | 30 | $a = $a + ($p->getX() * $pts[$j]->getY()) - ($p->getY() * $pts[$j]->getX()); |
27 | 31 | } |
28 | 32 | |
29 | - if ($signed) $area = ($a / 2); |
|
30 | - else $area = abs(($a / 2)); |
|
33 | + if ($signed) { |
|
34 | + $area = ($a / 2); |
|
35 | + } else { |
|
36 | + $area = abs(($a / 2)); |
|
37 | + } |
|
31 | 38 | |
32 | 39 | if ($exterior_only == TRUE) { |
33 | 40 | return $area; |
@@ -42,7 +49,9 @@ discard block |
||
42 | 49 | } |
43 | 50 | |
44 | 51 | public function centroid() { |
45 | - if ($this->isEmpty()) return NULL; |
|
52 | + if ($this->isEmpty()) { |
|
53 | + return NULL; |
|
54 | + } |
|
46 | 55 | |
47 | 56 | if ($this->geos()) { |
48 | 57 | return geoPHP::geosToGeometry($this->geos()->centroid()); |
@@ -52,7 +61,9 @@ discard block |
||
52 | 61 | $pts = $exterior_ring->getComponents(); |
53 | 62 | |
54 | 63 | $c = count($pts); |
55 | - if((int)$c == '0') return NULL; |
|
64 | + if((int)$c == '0') { |
|
65 | + return NULL; |
|
66 | + } |
|
56 | 67 | $cn = array('x' => '0', 'y' => '0'); |
57 | 68 | $a = $this->area(TRUE, TRUE); |
58 | 69 | |
@@ -98,12 +109,16 @@ discard block |
||
98 | 109 | } |
99 | 110 | |
100 | 111 | public function exteriorRing() { |
101 | - if ($this->isEmpty()) return new LineString(); |
|
112 | + if ($this->isEmpty()) { |
|
113 | + return new LineString(); |
|
114 | + } |
|
102 | 115 | return $this->components[0]; |
103 | 116 | } |
104 | 117 | |
105 | 118 | public function numInteriorRings() { |
106 | - if ($this->isEmpty()) return 0; |
|
119 | + if ($this->isEmpty()) { |
|
120 | + return 0; |
|
121 | + } |
|
107 | 122 | return $this->numGeometries()-1; |
108 | 123 | } |
109 | 124 | |
@@ -112,7 +127,9 @@ discard block |
||
112 | 127 | } |
113 | 128 | |
114 | 129 | public function dimension() { |
115 | - if ($this->isEmpty()) return 0; |
|
130 | + if ($this->isEmpty()) { |
|
131 | + return 0; |
|
132 | + } |
|
116 | 133 | return 2; |
117 | 134 | } |
118 | 135 | |
@@ -187,8 +204,7 @@ discard block |
||
187 | 204 | // If the number of edges we passed through is even, then it's in the polygon. |
188 | 205 | if ($intersections % 2 != 0) { |
189 | 206 | return TRUE; |
190 | - } |
|
191 | - else { |
|
207 | + } else { |
|
192 | 208 | return FALSE; |
193 | 209 | } |
194 | 210 | } |