@@ -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 | } |
@@ -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; |
@@ -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 | } |
@@ -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 | } |
@@ -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 | |
@@ -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.':'; |
@@ -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 | } |
@@ -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 | |
@@ -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; |