-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced a CoordinateSystem object
This aggregates the $is3D, $isMeasured and $SRID variables for geometries.
- Loading branch information
Showing
27 changed files
with
767 additions
and
953 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
<?php | ||
|
||
namespace Brick\Geo; | ||
|
||
use Brick\Geo\Exception\GeometryException; | ||
|
||
/** | ||
* Represents the dimensionality and spatial reference system of a geometry. | ||
*/ | ||
class CoordinateSystem | ||
{ | ||
/** | ||
* @var boolean | ||
*/ | ||
private $hasZ; | ||
|
||
/** | ||
* @var boolean | ||
*/ | ||
private $hasM; | ||
|
||
/** | ||
* @var integer | ||
*/ | ||
private $srid; | ||
|
||
/** | ||
* @param boolean $hasZ | ||
* @param boolean $hasM | ||
* @param integer $srid | ||
*/ | ||
private function __construct($hasZ, $hasM, $srid) | ||
{ | ||
$this->hasZ = $hasZ; | ||
$this->hasM = $hasM; | ||
$this->srid = $srid; | ||
} | ||
|
||
/** | ||
* @param boolean $hasZ | ||
* @param boolean $hasM | ||
* @param integer $srid | ||
* | ||
* @return CoordinateSystem | ||
*/ | ||
public static function create($hasZ, $hasM, $srid = 0) | ||
{ | ||
return new CoordinateSystem((bool) $hasZ, (bool) $hasM, (int) $srid); | ||
} | ||
|
||
/** | ||
* @param integer $srid | ||
* | ||
* @return CoordinateSystem | ||
*/ | ||
public static function xy($srid = 0) | ||
{ | ||
return new self(false, false, (int) $srid); | ||
} | ||
|
||
/** | ||
* @param integer $srid | ||
* | ||
* @return CoordinateSystem | ||
*/ | ||
public static function xyz($srid = 0) | ||
{ | ||
return new self(true, false, (int) $srid); | ||
} | ||
|
||
/** | ||
* @param integer $srid | ||
* | ||
* @return CoordinateSystem | ||
*/ | ||
public static function xym($srid = 0) | ||
{ | ||
return new self(false, true, (int) $srid); | ||
} | ||
|
||
/** | ||
* @param integer $srid | ||
* | ||
* @return CoordinateSystem | ||
*/ | ||
public static function xyzm($srid = 0) | ||
{ | ||
return new self(true, true, (int) $srid); | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function hasZ() | ||
{ | ||
return $this->hasZ; | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function hasM() | ||
{ | ||
return $this->hasM; | ||
} | ||
|
||
/** | ||
* @return integer | ||
*/ | ||
public function SRID() | ||
{ | ||
return $this->srid; | ||
} | ||
|
||
/** | ||
* @return integer | ||
* | ||
* @throws GeometryException | ||
*/ | ||
public function coordinateDimension() | ||
{ | ||
$coordinateDimension = 2; | ||
|
||
if ($this->hasZ) { | ||
$coordinateDimension++; | ||
} | ||
|
||
if ($this->hasM) { | ||
$coordinateDimension++; | ||
} | ||
|
||
return $coordinateDimension; | ||
} | ||
|
||
/** | ||
* @return integer | ||
*/ | ||
public function spatialDimension() | ||
{ | ||
return $this->hasZ ? 3 : 2; | ||
} | ||
|
||
/** | ||
* Returns the dimensionality name. | ||
* | ||
* @return string XY, XYZ, XYM, or XYZM. | ||
*/ | ||
public function name() | ||
{ | ||
$name = 'XY'; | ||
|
||
if ($this->hasZ) { | ||
$name .= 'Z'; | ||
} | ||
|
||
if ($this->hasM) { | ||
$name .= 'M'; | ||
} | ||
|
||
return $name; | ||
} | ||
|
||
/** | ||
* @param Geometry $geometry | ||
* | ||
* @return void | ||
* | ||
* @throws GeometryException | ||
*/ | ||
public function check(Geometry $geometry) | ||
{ | ||
if ($geometry->is3D() !== $this->hasZ || $geometry->isMeasured() !== $this->hasM) { | ||
throw new GeometryException('Invalid geometry dimension'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.