| @@ -13,6 +13,9 @@ discard block | ||
| 13 | 13 |  function sparql_connect( $endpoint ) { return new sparql_connection( $endpoint ); } | 
| 14 | 14 | |
| 15 | 15 |  function sparql_ns( $short, $long, $db = null ) { return _sparql_a_connection( $db )->ns( $short, $long ); } | 
| 16 | +/** | |
| 17 | + * @param string $sparql | |
| 18 | + */ | |
| 16 | 19 |  function sparql_query( $sparql, $db = null ) { return _sparql_a_connection( $db )->query( $sparql ); } | 
| 17 | 20 |  function sparql_errno( $db = null ) { return _sparql_a_connection( $db )->errno(); } | 
| 18 | 21 |  function sparql_error( $db = null ) { return _sparql_a_connection( $db )->error(); } | 
| @@ -84,6 +87,9 @@ discard block | ||
| 84 | 87 | $this->params = $params; | 
| 85 | 88 | } | 
| 86 | 89 | |
| 90 | + /** | |
| 91 | + * @param integer $timeout | |
| 92 | + */ | |
| 87 | 93 | function query( $query, $timeout=null ) | 
| 88 | 94 |  	{	 | 
| 89 | 95 | $prefixes = ""; | 
| @@ -324,6 +330,10 @@ discard block | ||
| 324 | 330 | var $fields; | 
| 325 | 331 | var $db; | 
| 326 | 332 | var $i = 0; | 
| 333 | + | |
| 334 | + /** | |
| 335 | + * @param sparql_connection $db | |
| 336 | + */ | |
| 327 | 337 | function __construct( $db, $rows, $fields ) | 
| 328 | 338 |  	{ | 
| 329 | 339 | $this->rows = $rows; | 
| @@ -215,14 +215,7 @@ discard block | ||
| 215 | 215 | } | 
| 216 | 216 | $r = null; | 
| 217 | 217 | |
| 218 | -		if( $code == "select" ) { $r = $this->test_select(); } | |
| 219 | -		elseif( $code == "constant_as" ) { $r = $this->test_constant_as(); } | |
| 220 | -		elseif( $code == "math_as" ) { $r = $this->test_math_as(); } | |
| 221 | -		elseif( $code == "count" ) { $r = $this->test_count(); } | |
| 222 | -		elseif( $code == "max" ) { $r = $this->test_max(); } | |
| 223 | -		elseif( $code == "load" ) { $r = $this->test_load(); } | |
| 224 | -		elseif( $code == "sample" ) { $r = $this->test_sample(); } | |
| 225 | -		else { print "<p>Unknown capability code: '$code'</p>"; return false; } | |
| 218 | +		if( $code == "select" ) { $r = $this->test_select(); } elseif( $code == "constant_as" ) { $r = $this->test_constant_as(); } elseif( $code == "math_as" ) { $r = $this->test_math_as(); } elseif( $code == "count" ) { $r = $this->test_count(); } elseif( $code == "max" ) { $r = $this->test_max(); } elseif( $code == "load" ) { $r = $this->test_load(); } elseif( $code == "sample" ) { $r = $this->test_sample(); } else { print "<p>Unknown capability code: '$code'</p>"; return false; } | |
| 226 | 219 | $this->caps[$code] = $r; | 
| 227 | 220 | if( isset( $this->caps_cache ) ) | 
| 228 | 221 |  		{ | 
| @@ -231,8 +224,7 @@ discard block | ||
| 231 | 224 | if( $was_cached ) | 
| 232 | 225 |  			{ | 
| 233 | 226 | dba_replace( $db_key, $db_val, $this->caps_cache ); | 
| 234 | - } | |
| 235 | - else | |
| 227 | + } else | |
| 236 | 228 |  			{ | 
| 237 | 229 | dba_insert( $db_key, $db_val, $this->caps_cache ); | 
| 238 | 230 | } | 
| @@ -118,6 +118,9 @@ discard block | ||
| 118 | 118 | ); | 
| 119 | 119 | } | 
| 120 | 120 | |
| 121 | + /** | |
| 122 | + * @param boolean $force | |
| 123 | + */ | |
| 121 | 124 |    static function geosInstalled($force = NULL) {
 | 
| 122 | 125 | static $geos_installed = NULL; | 
| 123 | 126 | if ($force !== NULL) $geos_installed = $force; | 
| @@ -222,6 +225,10 @@ discard block | ||
| 222 | 225 | |
| 223 | 226 | // Detect a format given a value. This function is meant to be SPEEDY. | 
| 224 | 227 | // It could make a mistake in XML detection if you are mixing or using namespaces in weird ways (ie, KML inside an RSS feed) | 
| 228 | + | |
| 229 | + /** | |
| 230 | + * @return string | |
| 231 | + */ | |
| 225 | 232 |    static function detectFormat(&$input) {
 | 
| 226 | 233 |      $mem = fopen('php://memory', 'r+');
 | 
| 227 | 234 | fwrite($mem, $input, 11); // Write 11 bytes - we can detect the vast majority of formats in the first 11 bytes | 
| @@ -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); | 
| @@ -120,7 +122,9 @@ discard block | ||
| 120 | 122 | |
| 121 | 123 |    static function geosInstalled($force = NULL) {
 | 
| 122 | 124 | static $geos_installed = NULL; | 
| 123 | - if ($force !== NULL) $geos_installed = $force; | |
| 125 | +    if ($force !== NULL) { | |
| 126 | + $geos_installed = $force; | |
| 127 | + } | |
| 124 | 128 |      if ($geos_installed !== NULL) {
 | 
| 125 | 129 | return $geos_installed; | 
| 126 | 130 | } | 
| @@ -148,8 +152,12 @@ discard block | ||
| 148 | 152 |    static function geometryReduce($geometry) {
 | 
| 149 | 153 | // If it's an array of one, then just parse the one | 
| 150 | 154 |      if (is_array($geometry)) {
 | 
| 151 | - if (empty($geometry)) return FALSE; | |
| 152 | - if (count($geometry) == 1) return geoPHP::geometryReduce(array_shift($geometry)); | |
| 155 | +      if (empty($geometry)) { | |
| 156 | + return FALSE; | |
| 157 | + } | |
| 158 | +      if (count($geometry) == 1) { | |
| 159 | + return geoPHP::geometryReduce(array_shift($geometry)); | |
| 160 | + } | |
| 153 | 161 | } | 
| 154 | 162 | |
| 155 | 163 | // If the geometry cannot even theoretically be reduced more, then pass it back | 
| @@ -168,8 +176,7 @@ discard block | ||
| 168 | 176 | $components = $geometry->getComponents(); | 
| 169 | 177 |          if (count($components) == 1) {
 | 
| 170 | 178 | return $components[0]; | 
| 171 | - } | |
| 172 | -        else {
 | |
| 179 | +        } else {
 | |
| 173 | 180 | return $geometry; | 
| 174 | 181 | } | 
| 175 | 182 | } | 
| @@ -192,8 +199,7 @@ discard block | ||
| 192 | 199 | $geometries[] = $component; | 
| 193 | 200 | $geom_types[] = $component->geometryType(); | 
| 194 | 201 | } | 
| 195 | - } | |
| 196 | -        else {
 | |
| 202 | +        } else {
 | |
| 197 | 203 | $geometries[] = $item; | 
| 198 | 204 | $geom_types[] = $item->geometryType(); | 
| 199 | 205 | } | 
| @@ -209,13 +215,11 @@ discard block | ||
| 209 | 215 |      if (count($geom_types) == 1) {
 | 
| 210 | 216 |        if (count($geometries) == 1) {
 | 
| 211 | 217 | return $geometries[0]; | 
| 212 | - } | |
| 213 | -      else {
 | |
| 218 | +      } else {
 | |
| 214 | 219 | $class = 'Multi'.$geom_types[0]; | 
| 215 | 220 | return new $class($geometries); | 
| 216 | 221 | } | 
| 217 | - } | |
| 218 | -    else {
 | |
| 222 | +    } else {
 | |
| 219 | 223 | return new GeometryCollection($geometries); | 
| 220 | 224 | } | 
| 221 | 225 | } | 
| @@ -230,7 +234,9 @@ discard block | ||
| 230 | 234 |      $bytes = unpack("c*", fread($mem, 11));
 | 
| 231 | 235 | |
| 232 | 236 | // If bytes is empty, then we were passed empty input | 
| 233 | - if (empty($bytes)) return FALSE; | |
| 237 | +    if (empty($bytes)) { | |
| 238 | + return FALSE; | |
| 239 | + } | |
| 234 | 240 | |
| 235 | 241 | // First char is a tab, space or carriage-return. trim it and try again | 
| 236 | 242 |      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 | 
| @@ -113,7 +113,6 @@ discard block | ||
| 113 | 113 | * Serializes an object into a geojson string | 
| 114 | 114 | * | 
| 115 | 115 | * | 
| 116 | - * @param Geometry $obj The object to serialize | |
| 117 | 116 | * | 
| 118 | 117 | * @return string The GeoJSON string | 
| 119 | 118 | */ | 
| @@ -126,6 +125,9 @@ discard block | ||
| 126 | 125 | } | 
| 127 | 126 | } | 
| 128 | 127 | |
| 128 | + /** | |
| 129 | + * @param Geometry $geometry | |
| 130 | + */ | |
| 129 | 131 |    public function getArray($geometry) { | 
| 130 | 132 |      if ($geometry->getGeomType() == 'GeometryCollection') { | 
| 131 | 133 | $component_array = array(); | 
| @@ -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 | |
| @@ -18,8 +18,6 @@ discard block | ||
| 18 | 18 | /** | 
| 19 | 19 | * Read GeoRSS string into geometry objects | 
| 20 | 20 | * | 
| 21 | - * @param string $georss - an XML feed containing geoRSS | |
| 22 | - * | |
| 23 | 21 | * @return Geometry|GeometryCollection | 
| 24 | 22 | */ | 
| 25 | 23 |    public function read($gpx) {
 | 
| @@ -80,6 +78,9 @@ discard block | ||
| 80 | 78 | return geoPHP::geometryReduce($geometries); | 
| 81 | 79 | } | 
| 82 | 80 | |
| 81 | + /** | |
| 82 | + * @param string $string | |
| 83 | + */ | |
| 83 | 84 |    protected function getPointsFromCoords($string) {
 | 
| 84 | 85 | $coords = array(); | 
| 85 | 86 |      $latlon = explode(' ',$string);
 | 
| @@ -87,8 +87,7 @@ discard block | ||
| 87 | 87 |        if (!($key % 2)) {
 | 
| 88 | 88 | // It's a latitude | 
| 89 | 89 | $lat = $item; | 
| 90 | - } | |
| 91 | -      else {
 | |
| 90 | +      } else {
 | |
| 92 | 91 | // It's a longitude | 
| 93 | 92 | $lon = $item; | 
| 94 | 93 | $coords[] = new Point($lon, $lat); | 
| @@ -125,8 +124,7 @@ discard block | ||
| 125 | 124 | $points = $this->getPointsFromCoords(trim($poly->firstChild->nodeValue)); | 
| 126 | 125 | $exterior_ring = new LineString($points); | 
| 127 | 126 | $polygons[] = new Polygon(array($exterior_ring)); | 
| 128 | - } | |
| 129 | -      else {
 | |
| 127 | +      } else {
 | |
| 130 | 128 | // It's an EMPTY polygon | 
| 131 | 129 | $polygons[] = new Polygon(); | 
| 132 | 130 | } | 
| @@ -196,7 +194,9 @@ discard block | ||
| 196 | 194 | $output = '<'.$this->nss.'line>'; | 
| 197 | 195 |      foreach ($geom->getComponents() as $k => $point) {
 | 
| 198 | 196 | $output .= $point->getY().' '.$point->getX(); | 
| 199 | - if ($k < ($geom->numGeometries() -1)) $output .= ' '; | |
| 197 | +      if ($k < ($geom->numGeometries() -1)) { | |
| 198 | + $output .= ' '; | |
| 199 | + } | |
| 200 | 200 | } | 
| 201 | 201 | $output .= '</'.$this->nss.'line>'; | 
| 202 | 202 | return $output; | 
| @@ -207,7 +207,9 @@ discard block | ||
| 207 | 207 | $exterior_ring = $geom->exteriorRing(); | 
| 208 | 208 |      foreach ($exterior_ring->getComponents() as $k => $point) {
 | 
| 209 | 209 | $output .= $point->getY().' '.$point->getX(); | 
| 210 | - if ($k < ($exterior_ring->numGeometries() -1)) $output .= ' '; | |
| 210 | +      if ($k < ($exterior_ring->numGeometries() -1)) { | |
| 211 | + $output .= ' '; | |
| 212 | + } | |
| 211 | 213 | } | 
| 212 | 214 | $output .= '</'.$this->nss.'polygon>'; | 
| 213 | 215 | return $output; | 
| @@ -42,6 +42,9 @@ | ||
| 42 | 42 | return '<'.$this->nss.'gpx creator="geoPHP" version="1.0">'.$this->geometryToGPX($geometry).'</'.$this->nss.'gpx>'; | 
| 43 | 43 | } | 
| 44 | 44 | |
| 45 | + /** | |
| 46 | + * @param string $text | |
| 47 | + */ | |
| 45 | 48 |    public function geomFromText($text) {
 | 
| 46 | 49 | // Change to lower-case and strip all CDATA | 
| 47 | 50 | $text = strtolower($text); | 
| @@ -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.':'; | 
| @@ -49,6 +49,9 @@ discard block | ||
| 49 | 49 | return $this->geometryToKML($geometry); | 
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | + /** | |
| 53 | + * @param string $text | |
| 54 | + */ | |
| 52 | 55 |    public function geomFromText($text) {
 | 
| 53 | 56 | |
| 54 | 57 | // Change to lower-case and strip all CDATA | 
| @@ -184,6 +187,9 @@ discard block | ||
| 184 | 187 | return $coordinates; | 
| 185 | 188 | } | 
| 186 | 189 | |
| 190 | + /** | |
| 191 | + * @param Geometry $geom | |
| 192 | + */ | |
| 187 | 193 |    private function geometryToKML($geom) {
 | 
| 188 | 194 | $type = strtolower($geom->getGeomType()); | 
| 189 | 195 |      switch ($type) {
 | 
| @@ -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 | } | 
| @@ -123,6 +123,9 @@ discard block | ||
| 123 | 123 | return new Polygon($components); | 
| 124 | 124 | } | 
| 125 | 125 | |
| 126 | + /** | |
| 127 | + * @param string $type | |
| 128 | + */ | |
| 126 | 129 |    function getMulti(&$mem, $type) {
 | 
| 127 | 130 | // Get the number of items expected in this multi out of the first 4 bytes | 
| 128 | 131 |      $multi_length = unpack('L',fread($mem,4));
 | 
| @@ -196,6 +199,9 @@ discard block | ||
| 196 | 199 | } | 
| 197 | 200 | } | 
| 198 | 201 | |
| 202 | + /** | |
| 203 | + * @param Geometry $point | |
| 204 | + */ | |
| 199 | 205 |    function writePoint($point) {
 | 
| 200 | 206 | // Set the coords | 
| 201 | 207 |      $wkb = pack('dd',$point->x(), $point->y());
 | 
| @@ -215,6 +221,9 @@ discard block | ||
| 215 | 221 | return $wkb; | 
| 216 | 222 | } | 
| 217 | 223 | |
| 224 | + /** | |
| 225 | + * @param Geometry $poly | |
| 226 | + */ | |
| 218 | 227 |    function writePolygon($poly) {
 | 
| 219 | 228 | // Set the number of lines in this poly | 
| 220 | 229 |      $wkb = pack('L',$poly->numGeometries());
 | 
| @@ -227,6 +236,9 @@ discard block | ||
| 227 | 236 | return $wkb; | 
| 228 | 237 | } | 
| 229 | 238 | |
| 239 | + /** | |
| 240 | + * @param Geometry $geometry | |
| 241 | + */ | |
| 230 | 242 |    function writeMulti($geometry) {
 | 
| 231 | 243 | // Set the number of components | 
| 232 | 244 |      $wkb = pack('L',$geometry->numGeometries());
 | 
| @@ -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 | } | 
| @@ -8,7 +8,6 @@ discard block | ||
| 8 | 8 | /** | 
| 9 | 9 | * Read WKT string into geometry objects | 
| 10 | 10 | * | 
| 11 | - * @param string $WKT A WKT string | |
| 12 | 11 | * | 
| 13 | 12 | * @return Geometry | 
| 14 | 13 | */ | 
| @@ -184,11 +183,17 @@ discard block | ||
| 184 | 183 | else return $str; | 
| 185 | 184 | } | 
| 186 | 185 | |
| 186 | + /** | |
| 187 | + * @param string $char | |
| 188 | + */ | |
| 187 | 189 |    protected function beginsWith($str, $char) { | 
| 188 | 190 | if (substr($str,0,strlen($char)) == $char) return TRUE; | 
| 189 | 191 | else return FALSE; | 
| 190 | 192 | } | 
| 191 | 193 | |
| 194 | + /** | |
| 195 | + * @param string $char | |
| 196 | + */ | |
| 192 | 197 |    protected function endsWith($str, $char) { | 
| 193 | 198 | if (substr($str,(0 - strlen($char))) == $char) return TRUE; | 
| 194 | 199 | else return FALSE; | 
| @@ -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 | } | 
| @@ -193,6 +193,9 @@ | ||
| 193 | 193 | } | 
| 194 | 194 | } | 
| 195 | 195 | |
| 196 | + /** | |
| 197 | + * @param Point $point | |
| 198 | + */ | |
| 196 | 199 |    public function pointOnVertex($point) { | 
| 197 | 200 |      foreach($this->getPoints() as $vertex) { | 
| 198 | 201 |        if ($point->equals($vertex)) { | 
| @@ -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 | } |