From 8657fcd0dbbdc7fcabcf8eec018b949d03387225 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Thu, 16 Apr 2015 19:56:14 +0200 Subject: [PATCH] Introduced a CoordinateSystem object This aggregates the $is3D, $isMeasured and $SRID variables for geometries. --- src/CircularString.php | 17 +- src/CompoundCurve.php | 17 +- src/CoordinateSystem.php | 176 ++++++++++++++++ src/CurvePolygon.php | 17 +- src/Exception/GeometryException.php | 4 +- src/Geometry.php | 143 ++++--------- src/GeometryCollection.php | 42 +--- src/IO/WKBAbstractReader.php | 198 ++++++++---------- src/IO/WKTAbstractReader.php | 302 ++++++++++++---------------- src/LineString.php | 36 +--- src/Point.php | 98 +++++++-- src/Polygon.php | 39 +--- src/PolyhedralSurface.php | 38 +--- src/Triangle.php | 13 +- tests/AbstractTestCase.php | 189 +++++++---------- tests/CircularStringTest.php | 16 +- tests/CompoundCurveTest.php | 16 +- tests/CurvePolygonTest.php | 4 +- tests/IO/EWKTWriterTest.php | 59 ++++-- tests/IO/WKTWriterTest.php | 65 ++++-- tests/MultiCurveTest.php | 2 +- tests/MultiSurfaceTest.php | 2 +- tests/PointTest.php | 198 ------------------ tests/PolygonTest.php | 4 +- tests/PolyhedralSurfaceTest.php | 16 +- tests/TINTest.php | 2 +- tests/TriangleTest.php | 7 +- 27 files changed, 767 insertions(+), 953 deletions(-) create mode 100644 src/CoordinateSystem.php diff --git a/src/CircularString.php b/src/CircularString.php index b18ee569..a7ec3dc2 100644 --- a/src/CircularString.php +++ b/src/CircularString.php @@ -20,23 +20,16 @@ class CircularString extends Curve implements \Countable, \IteratorAggregate protected $points = []; /** - * @param Point[] $points - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param Point[] $points + * @param CoordinateSystem|null $cs * * @return CircularString * * @throws GeometryException */ - public static function create(array $points, $is3D, $isMeasured, $srid = 0) + public static function create(array $points, CoordinateSystem $cs = null) { - $is3D = (bool) $is3D; - $isMeasured = (bool) $isMeasured; - - $srid = (int) $srid; - - self::checkGeometries($points, Point::class, $is3D, $isMeasured, $srid); + $cs = self::checkGeometries($points, Point::class, $cs); if ($points) { $numPoints = count($points); @@ -50,7 +43,7 @@ public static function create(array $points, $is3D, $isMeasured, $srid = 0) } } - $circularString = new CircularString(! $points, $is3D, $isMeasured, $srid); + $circularString = new CircularString($cs, ! $points); $circularString->points = array_values($points); return $circularString; diff --git a/src/CompoundCurve.php b/src/CompoundCurve.php index 82ff8b73..09b42b0c 100644 --- a/src/CompoundCurve.php +++ b/src/CompoundCurve.php @@ -17,23 +17,16 @@ class CompoundCurve extends Curve implements \Countable, \IteratorAggregate protected $curves = []; /** - * @param Curve[] $curves - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param Curve[] $curves + * @param CoordinateSystem|null $cs * * @return CompoundCurve * * @throws GeometryException */ - public static function create(array $curves, $is3D, $isMeasured, $srid = 0) + public static function create(array $curves, CoordinateSystem $cs = null) { - $is3D = (bool) $is3D; - $isMeasured = (bool) $isMeasured; - - $srid = (int) $srid; - - self::checkGeometries($curves, Curve::class, $is3D, $isMeasured, $srid); + $cs = self::checkGeometries($curves, Curve::class, $cs); /** @var Curve|null $previousCurve */ $previousCurve = null; @@ -51,7 +44,7 @@ public static function create(array $curves, $is3D, $isMeasured, $srid = 0) $previousCurve = $curve; } - $compoundCurve = new CompoundCurve(! $curves, $is3D, $isMeasured, $srid); + $compoundCurve = new CompoundCurve($cs, ! $curves); $compoundCurve->curves = array_values($curves); return $compoundCurve; diff --git a/src/CoordinateSystem.php b/src/CoordinateSystem.php new file mode 100644 index 00000000..c99ec1e5 --- /dev/null +++ b/src/CoordinateSystem.php @@ -0,0 +1,176 @@ +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'); + } + } +} diff --git a/src/CurvePolygon.php b/src/CurvePolygon.php index 27772448..ca02edcb 100644 --- a/src/CurvePolygon.php +++ b/src/CurvePolygon.php @@ -23,25 +23,18 @@ class CurvePolygon extends Surface implements \Countable, \IteratorAggregate protected $rings = []; /** - * @param Curve[] $rings - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param Curve[] $rings + * @param CoordinateSystem|null $cs * * @return static * * @throws GeometryException */ - public static function create(array $rings, $is3D, $isMeasured, $srid = 0) + public static function create(array $rings, CoordinateSystem $cs = null) { - $is3D = (bool) $is3D; - $isMeasured = (bool) $isMeasured; + $cs = self::checkGeometries($rings, Curve::class, $cs); - $srid = (int) $srid; - - self::checkGeometries($rings, Curve::class, $is3D, $isMeasured, $srid); - - $CurvePolygon = new static(! $rings, $is3D, $isMeasured, $srid); + $CurvePolygon = new static($cs, ! $rings); $CurvePolygon->rings = array_values($rings); return $CurvePolygon; diff --git a/src/Exception/GeometryException.php b/src/Exception/GeometryException.php index 5904fa64..c595ffcc 100644 --- a/src/Exception/GeometryException.php +++ b/src/Exception/GeometryException.php @@ -85,7 +85,7 @@ public static function dimensionalityMix($a, $b) */ public static function incompatibleDimensionality(Geometry $geometry, $geometryType, $is3D, $isMeasured) { - $message = 'Incompatible dimensionality: %s cannot contain %s.'; + $message = 'Incompatible dimensionality: cannot mix %s with %s.'; $a = self::geometryType($geometryType, $is3D, $isMeasured); $b = self::typeOf($geometry); @@ -102,7 +102,7 @@ public static function incompatibleDimensionality(Geometry $geometry, $geometryT */ public static function incompatibleSRID(Geometry $geometry, $geometryType, $srid) { - $message = 'Incompatible SRID: %s with SRID %d cannot contain %s with SRID %d.'; + $message = 'Incompatible SRID: cannot mix %s using SRID %d with %s using SRID %d.'; return new self(sprintf($message, $geometryType, $srid, $geometry->geometryType(), $geometry->SRID())); } diff --git a/src/Geometry.php b/src/Geometry.php index d26a0515..f9552cfb 100644 --- a/src/Geometry.php +++ b/src/Geometry.php @@ -42,42 +42,20 @@ abstract class Geometry protected $isEmpty; /** - * Whether this geometry has z coordinate values. - * - * @var boolean - */ - protected $is3D; - - /** - * Whether this geometry has m coordinate values. - * - * @var boolean + * @var CoordinateSystem */ - protected $isMeasured; - - /** - * The Spatial Reference System ID for this geometry. - * - * @var integer - */ - protected $srid; + protected $coordinateSystem; /** * Private constructor. Use a factory method to obtain an instance. * - * All parameters are assumed to be validated as their respective types. - * - * @param boolean $isEmpty Whether this geometry is empty. - * @param boolean $is3D Whether this geometry has z coordinate values. - * @param boolean $isMeasured Whether this geometry has m coordinate values. - * @param integer $srid The Spatial Reference System ID for this geometry. + * @param CoordinateSystem $coordinateSystem The coordinate system of this geometry. + * @param boolean $isEmpty Whether this geometry is empty. Must be validated as a boolean. */ - protected function __construct($isEmpty, $is3D, $isMeasured, $srid) + protected function __construct(CoordinateSystem $coordinateSystem, $isEmpty) { - $this->isEmpty = $isEmpty; - $this->is3D = $is3D; - $this->isMeasured = $isMeasured; - $this->srid = $srid; + $this->coordinateSystem = $coordinateSystem; + $this->isEmpty = $isEmpty; } /** @@ -161,22 +139,10 @@ abstract public function dimension(); * The ordinates x, y and z are spatial, and the ordinate m is a measure. * * @return integer - * - * @throws GeometryException */ public function coordinateDimension() { - $coordinateDimension = 2; - - if ($this->is3D) { - $coordinateDimension++; - } - - if ($this->isMeasured) { - $coordinateDimension++; - } - - return $coordinateDimension; + return $this->coordinateSystem->coordinateDimension(); } /** @@ -189,7 +155,7 @@ public function coordinateDimension() */ public function spatialDimension() { - return $this->is3D ? 3 : 2; + return $this->coordinateSystem->spatialDimension(); } /** @@ -206,7 +172,7 @@ abstract public function geometryType(); */ public function SRID() { - return $this->srid; + return $this->coordinateSystem->SRID(); } /** @@ -312,7 +278,7 @@ public function isSimple() */ public function is3D() { - return $this->is3D; + return $this->coordinateSystem->hasZ(); } /** @@ -322,7 +288,7 @@ public function is3D() */ public function isMeasured() { - return $this->isMeasured; + return $this->coordinateSystem->hasM(); } /** @@ -678,6 +644,16 @@ public function maxDistance(Geometry $geometry) return GeometryEngineRegistry::get()->maxDistance($this, $geometry); } + /** + * Returns the coordinate system of this geometry. + * + * @return CoordinateSystem + */ + public function coordinateSystem() + { + return $this->coordinateSystem; + } + /** * Returns the raw coordinates of this geometry as an array. * @@ -698,58 +674,16 @@ final public function __toString() } /** - * Gets the dimensions of an array of geometries. + * @param array $geometries The geometries to check. + * @param string $className The expected FQCN of the geometries. + * @param CoordinateSystem|null $cs The expected coordinate system of the geometries. + * Set to NULL to infer the coordinate system from the geometries. * - * If dimensionality is mixed, an exception is thrown. - * - * @internal - * - * @param Geometry[] $geometries The geometries, validated as such. - * @param boolean $is3D A variable to store whether the geometries have Z coordinates. - * @param boolean $isMeasured A variable to store whether the geometries have M coordinates. - * @param integer $srid A variable to store the SRID of the geometries. - * - * @return void - * - * @throws GeometryException If dimensionality is mixed. - */ - protected static function getDimensions(array $geometries, & $is3D, & $isMeasured, & $srid) - { - $is3D = false; - $isMeasured = false; - $srid = 0; - - $previous = null; - - foreach ($geometries as $geometry) { - if ($previous === null) { - $is3D = $geometry->is3D(); - $isMeasured = $geometry->isMeasured(); - $srid = $geometry->SRID(); - $previous = $geometry; - } else { - if ($geometry->is3D() !== $is3D || $geometry->isMeasured() !== $isMeasured) { - throw GeometryException::dimensionalityMix($previous, $geometry); - } - if ($geometry->SRID() !== $srid) { - throw new GeometryException('Incompatible SRID: %d and %d.', $srid, $geometry->SRID()); - } - } - } - } - - /** - * @param array $geometries The geometries to check. - * @param string $className The expected FQCN of the geometries. - * @param boolean $is3D Whether the geometries are expected to have a Z coordinate. - * @param boolean $isMeasured Whether the geometries are expected to have a M coordinate. - * @param integer $srid The expected SRID of the geometries. - * - * @return void + * @return CoordinateSystem * * @throws GeometryException */ - protected static function checkGeometries(array $geometries, $className, $is3D, $isMeasured, $srid) + protected static function checkGeometries(array $geometries, $className, CoordinateSystem $cs = null) { $reflectionClass = new \ReflectionClass(static::class); $geometryType = $reflectionClass->getShortName(); @@ -766,13 +700,24 @@ protected static function checkGeometries(array $geometries, $className, $is3D, /** @var Geometry $geometry */ - if ($geometry->is3D() !== $is3D || $geometry->isMeasured() !== $isMeasured) { - throw GeometryException::incompatibleDimensionality($geometry, $geometryType, $is3D, $isMeasured); - } + if ($cs === null) { + $cs = $geometry->coordinateSystem(); + $geometryType = $geometry->geometryType(); + } else { + if ($geometry->is3D() !== $cs->hasZ() || $geometry->isMeasured() !== $cs->hasM()) { + throw GeometryException::incompatibleDimensionality($geometry, $geometryType, $cs->hasZ(), $cs->hasM()); + } - if ($geometry->SRID() !== $srid) { - throw GeometryException::incompatibleSRID($geometry, $geometryType, $srid); + if ($geometry->SRID() !== $cs->SRID()) { + throw GeometryException::incompatibleSRID($geometry, $geometryType, $cs->SRID()); + } } } + + if ($cs === null) { + throw new GeometryException(sprintf('A Coordinate System must be provided when creating an empty %s.', $geometryType)); + } + + return $cs; } } diff --git a/src/GeometryCollection.php b/src/GeometryCollection.php index dff50c25..0eb1e32a 100644 --- a/src/GeometryCollection.php +++ b/src/GeometryCollection.php @@ -35,7 +35,7 @@ class GeometryCollection extends Geometry implements \Countable, \IteratorAggreg */ public static function xy(array $geometries, $srid = 0) { - return self::create($geometries, false, false, $srid); + return self::create($geometries, CoordinateSystem::xy($srid)); } /** @@ -46,7 +46,7 @@ public static function xy(array $geometries, $srid = 0) */ public static function xyz(array $geometries, $srid = 0) { - return self::create($geometries, true, false, $srid); + return self::create($geometries, CoordinateSystem::xyz($srid)); } /** @@ -57,7 +57,7 @@ public static function xyz(array $geometries, $srid = 0) */ public static function xym(array $geometries, $srid = 0) { - return self::create($geometries, false, true, $srid); + return self::create($geometries, CoordinateSystem::xym($srid)); } /** @@ -68,36 +68,29 @@ public static function xym(array $geometries, $srid = 0) */ public static function xyzm(array $geometries, $srid = 0) { - return self::create($geometries, true, true, $srid); + return self::create($geometries, CoordinateSystem::xyzm($srid)); } /** - * @param Geometry[] $geometries - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param Geometry[] $geometries + * @param CoordinateSystem|null $cs * * @return static * * @throws GeometryException */ - public static function create(array $geometries, $is3D, $isMeasured, $srid = 0) + public static function create(array $geometries, CoordinateSystem $cs = null) { - $is3D = (bool) $is3D; - $isMeasured = (bool) $isMeasured; - - $srid = (int) $srid; - - self::checkGeometries($geometries, static::containedGeometryType(), $is3D, $isMeasured, $srid); + $cs = self::checkGeometries($geometries, static::containedGeometryType(), $cs); - $geometryCollection = new static(self::checkEmpty($geometries), $is3D, $isMeasured, $srid); + $geometryCollection = new static($cs, self::checkEmpty($geometries)); $geometryCollection->geometries = array_values($geometries); return $geometryCollection; } /** - * @deprecated Use a factory method that explictly specifies the dimensionality and SRID. + * @deprecated Use create() instead. * * @param array $geometries An array of Geometry objects. * @@ -107,20 +100,7 @@ public static function create(array $geometries, $is3D, $isMeasured, $srid = 0) */ public static function factory(array $geometries) { - $geometryType = static::containedGeometryType(); - - foreach ($geometries as $geometry) { - if (! $geometry instanceof $geometryType) { - throw GeometryException::unexpectedGeometryType($geometryType, $geometry); - } - } - - self::getDimensions($geometries, $is3D, $isMeasured, $srid); - - $geometryCollection = new static(self::checkEmpty($geometries), $is3D, $isMeasured, $srid); - $geometryCollection->geometries = array_values($geometries); - - return $geometryCollection; + return static::create($geometries); } /** diff --git a/src/IO/WKBAbstractReader.php b/src/IO/WKBAbstractReader.php index 1d41d8a9..70988875 100644 --- a/src/IO/WKBAbstractReader.php +++ b/src/IO/WKBAbstractReader.php @@ -2,6 +2,7 @@ namespace Brick\Geo\IO; +use Brick\Geo\CoordinateSystem; use Brick\Geo\Exception\GeometryException; use Brick\Geo\Exception\GeometryParseException; use Brick\Geo\Geometry; @@ -51,320 +52,283 @@ protected function readGeometry(WKBBuffer $buffer, $srid) $this->readGeometryHeader($buffer, $geometryType, $is3D, $isMeasured, $srid); + $cs = CoordinateSystem::create($is3D, $isMeasured, $srid); + switch ($geometryType) { case Geometry::POINT: - return $this->readPoint($buffer, $is3D, $isMeasured, $srid); + return $this->readPoint($buffer, $cs); case Geometry::LINESTRING: - return $this->readLineString($buffer, $is3D, $isMeasured, $srid); + return $this->readLineString($buffer, $cs); case Geometry::CIRCULARSTRING: - return $this->readCircularString($buffer, $is3D, $isMeasured, $srid); + return $this->readCircularString($buffer, $cs); case Geometry::COMPOUNDCURVE: - return $this->readCompoundCurve($buffer, $is3D, $isMeasured, $srid); + return $this->readCompoundCurve($buffer, $cs); case Geometry::POLYGON: - return $this->readPolygon($buffer, $is3D, $isMeasured, $srid); + return $this->readPolygon($buffer, $cs); case Geometry::CURVEPOLYGON: - return $this->readCurvePolygon($buffer, $is3D, $isMeasured, $srid); + return $this->readCurvePolygon($buffer, $cs); case Geometry::MULTIPOINT: - return $this->readMultiPoint($buffer, $is3D, $isMeasured, $srid); + return $this->readMultiPoint($buffer, $cs); case Geometry::MULTILINESTRING: - return $this->readMultiLineString($buffer, $is3D, $isMeasured, $srid); + return $this->readMultiLineString($buffer, $cs); case Geometry::MULTIPOLYGON: - return $this->readMultiPolygon($buffer, $is3D, $isMeasured, $srid); + return $this->readMultiPolygon($buffer, $cs); case Geometry::GEOMETRYCOLLECTION: - return $this->readGeometryCollection($buffer, $is3D, $isMeasured, $srid); + return $this->readGeometryCollection($buffer, $cs); case Geometry::POLYHEDRALSURFACE: - return $this->readPolyhedralSurface($buffer, $is3D, $isMeasured, $srid); + return $this->readPolyhedralSurface($buffer, $cs); case Geometry::TIN: - return $this->readTIN($buffer, $is3D, $isMeasured, $srid); + return $this->readTIN($buffer, $cs); case Geometry::TRIANGLE: - return $this->readTriangle($buffer, $is3D, $isMeasured, $srid); + return $this->readTriangle($buffer, $cs); } throw GeometryParseException::unsupportedGeometryType($geometryType); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\Point */ - private function readPoint(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readPoint(WKBBuffer $buffer, CoordinateSystem $cs) { - $count = 2 + ($is3D ? 1 : 0) + ($isMeasured ? 1 : 0); - $values = $buffer->readDoubles($count); - - if ($is3D && $isMeasured) { - return Point::xyzm($values[1], $values[2], $values[3], $values[4], $srid); - } - - if ($is3D) { - return Point::xyz($values[1], $values[2], $values[3], $srid); - } - - if ($isMeasured) { - return Point::xym($values[1], $values[2], $values[3], $srid); - } + $coords = $buffer->readDoubles($cs->coordinateDimension()); - return Point::xy($values[1], $values[2], $srid); + return Point::create(array_values($coords), $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\LineString */ - private function readLineString(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readLineString(WKBBuffer $buffer, CoordinateSystem $cs) { $numPoints = $buffer->readUnsignedLong(); $points = []; for ($i = 0; $i < $numPoints; $i++) { - $points[] = $this->readPoint($buffer, $is3D, $isMeasured, $srid); + $points[] = $this->readPoint($buffer, $cs); } - return LineString::create($points, $is3D, $isMeasured, $srid); + return LineString::create($points, $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\LineString */ - private function readCircularString(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readCircularString(WKBBuffer $buffer, CoordinateSystem $cs) { $numPoints = $buffer->readUnsignedLong(); $points = []; for ($i = 0; $i < $numPoints; $i++) { - $points[] = $this->readPoint($buffer, $is3D, $isMeasured, $srid); + $points[] = $this->readPoint($buffer, $cs); } - return CircularString::create($points, $is3D, $isMeasured, $srid); + return CircularString::create($points, $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\CompoundCurve */ - private function readCompoundCurve(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readCompoundCurve(WKBBuffer $buffer, CoordinateSystem $cs) { $numCurves = $buffer->readUnsignedLong(); $curves = []; for ($i = 0; $i < $numCurves; $i++) { - $curves[] = $this->readGeometry($buffer, $srid); + $curves[] = $this->readGeometry($buffer, $cs->SRID()); } - return CompoundCurve::create($curves, $is3D, $isMeasured, $srid); + return CompoundCurve::create($curves, $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\Polygon */ - private function readPolygon(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readPolygon(WKBBuffer $buffer, CoordinateSystem $cs) { $numRings = $buffer->readUnsignedLong(); $rings = []; for ($i = 0; $i < $numRings; $i++) { - $rings[] = $this->readLineString($buffer, $is3D, $isMeasured, $srid); + $rings[] = $this->readLineString($buffer, $cs); } - return Polygon::create($rings, $is3D, $isMeasured, $srid); + return Polygon::create($rings, $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\CurvePolygon */ - private function readCurvePolygon(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readCurvePolygon(WKBBuffer $buffer, CoordinateSystem $cs) { $numRings = $buffer->readUnsignedLong(); $rings = []; for ($i = 0; $i < $numRings; $i++) { - $rings[] = $this->readGeometry($buffer, $srid); + $rings[] = $this->readGeometry($buffer, $cs->SRID()); } - return CurvePolygon::create($rings, $is3D, $isMeasured, $srid); + return CurvePolygon::create($rings, $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\MultiPoint */ - private function readMultiPoint(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readMultiPoint(WKBBuffer $buffer, CoordinateSystem $cs) { $numPoints = $buffer->readUnsignedLong(); $points = []; for ($i = 0; $i < $numPoints; $i++) { - $points[] = $this->readGeometry($buffer, $srid); + $points[] = $this->readGeometry($buffer, $cs->SRID()); } - return MultiPoint::create($points, $is3D, $isMeasured, $srid); + return MultiPoint::create($points, $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\MultiLineString */ - private function readMultiLineString(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readMultiLineString(WKBBuffer $buffer, CoordinateSystem $cs) { $numLineStrings = $buffer->readUnsignedLong(); $lineStrings = []; for ($i = 0; $i < $numLineStrings; $i++) { - $lineStrings[] = $this->readGeometry($buffer, $srid); + $lineStrings[] = $this->readGeometry($buffer, $cs->SRID()); } - return MultiLineString::create($lineStrings, $is3D, $isMeasured, $srid); + return MultiLineString::create($lineStrings, $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\MultiPolygon */ - private function readMultiPolygon(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readMultiPolygon(WKBBuffer $buffer, CoordinateSystem $cs) { $numPolygons = $buffer->readUnsignedLong(); $polygons = []; for ($i = 0; $i < $numPolygons; $i++) { - $polygons[] = $this->readGeometry($buffer, $srid); + $polygons[] = $this->readGeometry($buffer, $cs->SRID()); } - return MultiPolygon::create($polygons, $is3D, $isMeasured, $srid); + return MultiPolygon::create($polygons, $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\GeometryCollection */ - private function readGeometryCollection(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readGeometryCollection(WKBBuffer $buffer, CoordinateSystem $cs) { $numGeometries = $buffer->readUnsignedLong(); $geometries = []; for ($i = 0; $i < $numGeometries; $i++) { - $geometries[] = $this->readGeometry($buffer, $srid); + $geometries[] = $this->readGeometry($buffer, $cs->SRID()); } - return GeometryCollection::create($geometries, $is3D, $isMeasured, $srid); + return GeometryCollection::create($geometries, $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\PolyhedralSurface */ - private function readPolyhedralSurface(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readPolyhedralSurface(WKBBuffer $buffer, CoordinateSystem $cs) { $numPatches = $buffer->readUnsignedLong(); $patches = []; for ($i = 0; $i < $numPatches; $i++) { - $patches[] = $this->readGeometry($buffer, $srid); + $patches[] = $this->readGeometry($buffer, $cs->SRID()); } - return PolyhedralSurface::create($patches, $is3D, $isMeasured, $srid); + return PolyhedralSurface::create($patches, $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\TIN */ - private function readTIN(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readTIN(WKBBuffer $buffer, CoordinateSystem $cs) { $numPatches = $buffer->readUnsignedLong(); $patches = []; for ($i = 0; $i < $numPatches; $i++) { - $patches[] = $this->readGeometry($buffer, $srid); + $patches[] = $this->readGeometry($buffer, $cs->SRID()); } - return TIN::create($patches, $is3D, $isMeasured, $srid); + return TIN::create($patches, $cs); } /** - * @param WKBBuffer $buffer - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKBBuffer $buffer + * @param CoordinateSystem $cs * * @return \Brick\Geo\Triangle */ - private function readTriangle(WKBBuffer $buffer, $is3D, $isMeasured, $srid) + private function readTriangle(WKBBuffer $buffer, CoordinateSystem $cs) { $numRings = $buffer->readUnsignedLong(); $rings = []; for ($i = 0; $i < $numRings; $i++) { - $rings[] = $this->readLineString($buffer, $is3D, $isMeasured, $srid); + $rings[] = $this->readLineString($buffer, $cs); } - return Triangle::create($rings, $is3D, $isMeasured, $srid); + return Triangle::create($rings, $cs); } } diff --git a/src/IO/WKTAbstractReader.php b/src/IO/WKTAbstractReader.php index 7ea0b18f..7363e892 100644 --- a/src/IO/WKTAbstractReader.php +++ b/src/IO/WKTAbstractReader.php @@ -2,6 +2,7 @@ namespace Brick\Geo\IO; +use Brick\Geo\Geometry; use Brick\Geo\Point; use Brick\Geo\LineString; use Brick\Geo\CircularString; @@ -15,6 +16,7 @@ use Brick\Geo\PolyhedralSurface; use Brick\Geo\TIN; use Brick\Geo\Triangle; +use Brick\Geo\CoordinateSystem; use Brick\Geo\Exception\GeometryException; /** @@ -26,9 +28,9 @@ abstract class WKTAbstractReader * @param WKTParser $parser * @param integer $srid * - * @return \Brick\Geo\Geometry + * @return Geometry * - * @throws \Brick\Geo\Exception\GeometryException + * @throws GeometryException */ protected function readGeometry(WKTParser $parser, $srid) { @@ -64,97 +66,99 @@ protected function readGeometry(WKTParser $parser, $srid) } } + $cs = CoordinateSystem::create($is3D, $isMeasured, $srid); + switch ($geometryType) { case 'POINT': if ($isEmpty) { - return Point::pointEmpty($is3D, $isMeasured, $srid); + return Point::pointEmpty($cs); } - return $this->readPointText($parser, $is3D, $isMeasured, $srid); + return $this->readPointText($parser, $cs); case 'LINESTRING': if ($isEmpty) { - return LineString::create([], $is3D, $isMeasured, $srid); + return LineString::create([], $cs); } - return $this->readLineStringText($parser, $is3D, $isMeasured, $srid); + return $this->readLineStringText($parser, $cs); case 'CIRCULARSTRING': if ($isEmpty) { - return CircularString::create([], $is3D, $isMeasured, $srid); + return CircularString::create([], $cs); } - return $this->readCircularStringText($parser, $is3D, $isMeasured, $srid); + return $this->readCircularStringText($parser, $cs); case 'COMPOUNDCURVE': if ($isEmpty) { - return CompoundCurve::create([], $is3D, $isMeasured, $srid); + return CompoundCurve::create([], $cs); } - return $this->readCompoundCurveText($parser, $is3D, $isMeasured, $srid); + return $this->readCompoundCurveText($parser, $cs); case 'POLYGON': if ($isEmpty) { - return Polygon::create([], $is3D, $isMeasured, $srid); + return Polygon::create([], $cs); } - return $this->readPolygonText($parser, $is3D, $isMeasured, $srid); + return $this->readPolygonText($parser, $cs); case 'CURVEPOLYGON': if ($isEmpty) { - return CurvePolygon::create([], $is3D, $isMeasured, $srid); + return CurvePolygon::create([], $cs); } - return $this->readCurvePolygonText($parser, $is3D, $isMeasured, $srid); + return $this->readCurvePolygonText($parser, $cs); case 'MULTIPOINT': if ($isEmpty) { - return MultiPoint::create([], $is3D, $isMeasured, $srid); + return MultiPoint::create([], $cs); } - return $this->readMultiPointText($parser, $is3D, $isMeasured, $srid); + return $this->readMultiPointText($parser, $cs); case 'MULTILINESTRING': if ($isEmpty) { - return MultiLineString::create([], $is3D, $isMeasured, $srid); + return MultiLineString::create([], $cs); } - return $this->readMultiLineStringText($parser, $is3D, $isMeasured, $srid); + return $this->readMultiLineStringText($parser, $cs); case 'MULTIPOLYGON': if ($isEmpty) { - return MultiPolygon::create([], $is3D, $isMeasured, $srid); + return MultiPolygon::create([], $cs); } - return $this->readMultiPolygonText($parser, $is3D, $isMeasured, $srid); + return $this->readMultiPolygonText($parser, $cs); case 'GEOMETRYCOLLECTION': if ($isEmpty) { - return GeometryCollection::create([], $is3D, $isMeasured, $srid); + return GeometryCollection::create([], $cs); } - return $this->readGeometryCollectionText($parser, $is3D, $isMeasured, $srid); + return $this->readGeometryCollectionText($parser, $cs); case 'POLYHEDRALSURFACE': if ($isEmpty) { - return PolyhedralSurface::create([], $is3D, $isMeasured, $srid); + return PolyhedralSurface::create([], $cs); } - return $this->readPolyhedralSurfaceText($parser, $is3D, $isMeasured, $srid); + return $this->readPolyhedralSurfaceText($parser, $cs); case 'TIN': if ($isEmpty) { - return TIN::create([], $is3D, $isMeasured, $srid); + return TIN::create([], $cs); } - return $this->readTINText($parser, $is3D, $isMeasured, $srid); + return $this->readTINText($parser, $cs); case 'TRIANGLE': if ($isEmpty) { - return Triangle::create([], $is3D, $isMeasured, $srid); + return Triangle::create([], $cs); } - return $this->readTriangleText($parser, $is3D, $isMeasured, $srid); + return $this->readTriangleText($parser, $cs); } throw new GeometryException('Unknown geometry type: ' . $geometryType); @@ -163,57 +167,35 @@ protected function readGeometry(WKTParser $parser, $srid) /** * x y * - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\Point + * @return Point */ - private function readPoint(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readPoint(WKTParser $parser, CoordinateSystem $cs) { + $dim = $cs->coordinateDimension(); $coords = []; - $coords[] = $parser->getNextNumber(); - $coords[] = $parser->getNextNumber(); - - if ($is3D) { + for ($i = 0; $i < $dim; $i++) { $coords[] = $parser->getNextNumber(); } - if ($isMeasured) { - $coords[] = $parser->getNextNumber(); - } - - if ($is3D && $isMeasured) { - return Point::xyzm($coords[0], $coords[1], $coords[2], $coords[3], $srid); - } - - if ($is3D) { - return Point::xyz($coords[0], $coords[1], $coords[2], $srid); - } - - if ($isMeasured) { - return Point::xym($coords[0], $coords[1], $coords[2], $srid); - } - - return Point::xy($coords[0], $coords[1], $srid); + return Point::create($coords, $cs); } /** * (x y) * - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\Point + * @return Point */ - private function readPointText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readPointText(WKTParser $parser, CoordinateSystem $cs) { $parser->matchOpener(); - $point = $this->readPoint($parser, $is3D, $isMeasured, $srid); + $point = $this->readPoint($parser, $cs); $parser->matchCloser(); return $point; @@ -222,20 +204,18 @@ private function readPointText(WKTParser $parser, $is3D, $isMeasured, $srid) /** * (x y, ...) * - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\Point[] + * @return Point[] */ - private function readMultiPoint(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readMultiPoint(WKTParser $parser, CoordinateSystem $cs) { $parser->matchOpener(); $points = []; do { - $points[] = $this->readPoint($parser, $is3D, $isMeasured, $srid); + $points[] = $this->readPoint($parser, $cs); $nextToken = $parser->getNextCloserOrComma(); } while ($nextToken === ','); @@ -245,99 +225,89 @@ private function readMultiPoint(WKTParser $parser, $is3D, $isMeasured, $srid) /** * (x y, ...) * - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\LineString + * @return LineString */ - private function readLineStringText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readLineStringText(WKTParser $parser, CoordinateSystem $cs) { - $points = $this->readMultiPoint($parser, $is3D, $isMeasured, $srid); + $points = $this->readMultiPoint($parser, $cs); - return LineString::create($points, $is3D, $isMeasured, $srid); + return LineString::create($points, $cs); } /** * (x y, ...) * - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\LineString + * @return LineString */ - private function readCircularStringText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readCircularStringText(WKTParser $parser, CoordinateSystem $cs) { - $points = $this->readMultiPoint($parser, $is3D, $isMeasured, $srid); + $points = $this->readMultiPoint($parser, $cs); - return CircularString::create($points, $is3D, $isMeasured, $srid); + return CircularString::create($points, $cs); } /** - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\CompoundCurve + * @return CompoundCurve * * @throws GeometryException */ - private function readCompoundCurveText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readCompoundCurveText(WKTParser $parser, CoordinateSystem $cs) { $parser->matchOpener(); $curves = []; do { if ($parser->isNextOpenerOrWord()) { - $curves[] = $this->readLineStringText($parser, $is3D, $isMeasured, $srid); + $curves[] = $this->readLineStringText($parser, $cs); } else { - $curves[] = $this->readGeometry($parser, $srid); + $curves[] = $this->readGeometry($parser, $cs->SRID()); } $nextToken = $parser->getNextCloserOrComma(); } while ($nextToken === ','); - return CompoundCurve::create($curves, $is3D, $isMeasured, $srid); + return CompoundCurve::create($curves, $cs); } /** * (x y, ...) * - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\MultiPoint + * @return MultiPoint */ - private function readMultiPointText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readMultiPointText(WKTParser $parser, CoordinateSystem $cs) { - $points = $this->readMultiPoint($parser, $is3D, $isMeasured, $srid); + $points = $this->readMultiPoint($parser, $cs); - return MultiPoint::factory($points); + return MultiPoint::create($points, $cs); } /** * ((x y, ...), ...) * - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\LineString[] + * @return LineString[] */ - private function readMultiLineString(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readMultiLineString(WKTParser $parser, CoordinateSystem $cs) { $parser->matchOpener(); $lineStrings = []; do { - $lineStrings[] = $this->readLineStringText($parser, $is3D, $isMeasured, $srid); + $lineStrings[] = $this->readLineStringText($parser, $cs); $nextToken = $parser->getNextCloserOrComma(); } while ($nextToken === ','); @@ -347,169 +317,153 @@ private function readMultiLineString(WKTParser $parser, $is3D, $isMeasured, $sri /** * ((x y, ...), ...) * - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\Polygon + * @return Polygon */ - private function readPolygonText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readPolygonText(WKTParser $parser, CoordinateSystem $cs) { - $rings = $this->readMultiLineString($parser, $is3D, $isMeasured, $srid); + $rings = $this->readMultiLineString($parser, $cs); - return Polygon::create($rings, $is3D, $isMeasured, $srid); + return Polygon::create($rings, $cs); } /** - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\CurvePolygon + * @return CurvePolygon */ - private function readCurvePolygonText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readCurvePolygonText(WKTParser $parser, CoordinateSystem $cs) { $parser->matchOpener(); $curves = []; do { if ($parser->isNextOpenerOrWord()) { - $curves[] = $this->readLineStringText($parser, $is3D, $isMeasured, $srid); + $curves[] = $this->readLineStringText($parser, $cs); } else { - $curves[] = $this->readGeometry($parser, $srid); + $curves[] = $this->readGeometry($parser, $cs->SRID()); } $nextToken = $parser->getNextCloserOrComma(); } while ($nextToken === ','); - return CurvePolygon::create($curves, $is3D, $isMeasured, $srid); + return CurvePolygon::create($curves, $cs); } /** * ((x y, ...), ...) * - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\Polygon + * @return Polygon */ - private function readTriangleText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readTriangleText(WKTParser $parser, CoordinateSystem $cs) { - $rings = $this->readMultiLineString($parser, $is3D, $isMeasured, $srid); + $rings = $this->readMultiLineString($parser, $cs); - return Triangle::create($rings, $is3D, $isMeasured, $srid); + return Triangle::create($rings, $cs); } /** * ((x y, ...), ...) * - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\MultiLineString + * @return MultiLineString */ - private function readMultiLineStringText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readMultiLineStringText(WKTParser $parser, CoordinateSystem $cs) { - $rings = $this->readMultiLineString($parser, $is3D, $isMeasured, $srid); + $rings = $this->readMultiLineString($parser, $cs); - return MultiLineString::factory($rings); + return MultiLineString::create($rings, $cs); } /** * (((x y, ...), ...), ...) * - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\MultiPolygon + * @return MultiPolygon */ - private function readMultiPolygonText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readMultiPolygonText(WKTParser $parser, CoordinateSystem $cs) { $parser->matchOpener(); $polygons = []; do { - $polygons[] = $this->readPolygonText($parser, $is3D, $isMeasured, $srid); + $polygons[] = $this->readPolygonText($parser, $cs); $nextToken = $parser->getNextCloserOrComma(); } while ($nextToken === ','); - return MultiPolygon::factory($polygons); + return MultiPolygon::create($polygons, $cs); } /** - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\GeometryCollection + * @return GeometryCollection * * @throws GeometryException */ - private function readGeometryCollectionText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readGeometryCollectionText(WKTParser $parser, CoordinateSystem $cs) { $parser->matchOpener(); $geometries = []; do { - $geometries[] = $this->readGeometry($parser, $srid); + $geometries[] = $this->readGeometry($parser, $cs->SRID()); $nextToken = $parser->getNextCloserOrComma(); } while ($nextToken === ','); - return GeometryCollection::create($geometries, $is3D, $isMeasured, $srid); + return GeometryCollection::create($geometries, $cs); } /** - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\PolyhedralSurface + * @return PolyhedralSurface * * @throws GeometryException */ - private function readPolyhedralSurfaceText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readPolyhedralSurfaceText(WKTParser $parser, CoordinateSystem $cs) { $parser->matchOpener(); $patches = []; do { - $patches[] = $this->readPolygonText($parser, $is3D, $isMeasured, $srid); + $patches[] = $this->readPolygonText($parser, $cs); $nextToken = $parser->getNextCloserOrComma(); } while ($nextToken === ','); - return PolyhedralSurface::create($patches, $is3D, $isMeasured, $srid); + return PolyhedralSurface::create($patches, $cs); } /** - * @param WKTParser $parser - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param WKTParser $parser + * @param CoordinateSystem $cs * - * @return \Brick\Geo\TIN + * @return TIN * * @throws GeometryException */ - private function readTINText(WKTParser $parser, $is3D, $isMeasured, $srid) + private function readTINText(WKTParser $parser, CoordinateSystem $cs) { $parser->matchOpener(); $patches = []; do { - $patches[] = $this->readTriangleText($parser, $is3D, $isMeasured, $srid); + $patches[] = $this->readTriangleText($parser, $cs); $nextToken = $parser->getNextCloserOrComma(); } while ($nextToken === ','); - return TIN::create($patches, $is3D, $isMeasured, $srid); + return TIN::create($patches, $cs); } } diff --git a/src/LineString.php b/src/LineString.php index eedf1c2c..a16688b7 100644 --- a/src/LineString.php +++ b/src/LineString.php @@ -19,29 +19,22 @@ class LineString extends Curve implements \Countable, \IteratorAggregate protected $points = []; /** - * @param Point[] $points - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param Point[] $points The points that compose the LineString. + * @param CoordinateSystem|null $cs The coordinate system, optional if the point array is not empty. * * @return LineString * * @throws GeometryException */ - public static function create(array $points, $is3D, $isMeasured, $srid = 0) + public static function create(array $points, CoordinateSystem $cs = null) { - $is3D = (bool) $is3D; - $isMeasured = (bool) $isMeasured; - - $srid = (int) $srid; - - self::checkGeometries($points, Point::class, $is3D, $isMeasured, $srid); + $cs = self::checkGeometries($points, Point::class, $cs); if ($points && count($points) < 2) { throw new GeometryException('A LineString must be made of at least 2 points.'); } - $lineString = new LineString(! $points, $is3D, $isMeasured, $srid); + $lineString = new LineString($cs, ! $points); $lineString->points = array_values($points); return $lineString; @@ -50,6 +43,8 @@ public static function create(array $points, $is3D, $isMeasured, $srid = 0) /** * Creates a LineString from an array of Points. * + * @deprecated Use create() instead. + * * @param Point[] $points * * @return static The LineString instance. @@ -60,22 +55,7 @@ public static function create(array $points, $is3D, $isMeasured, $srid = 0) */ public static function factory(array $points) { - foreach ($points as $point) { - if (! $point instanceof Point) { - throw GeometryException::unexpectedGeometryType(Point::class, $point); - } - } - - self::getDimensions($points, $is3D, $isMeasured, $srid); - - if (count($points) < 2) { - throw new GeometryException('A LineString must have at least 2 points.'); - } - - $lineString = new LineString(false, $is3D, $isMeasured, $srid); - $lineString->points = array_values($points); - - return $lineString; + return static::create($points); } /** diff --git a/src/Point.php b/src/Point.php index 9c2400be..26a1e363 100644 --- a/src/Point.php +++ b/src/Point.php @@ -42,6 +42,52 @@ class Point extends Geometry */ private $m; + /** + * Creates a Point from an array of coordinates, and a Coordinate System. + * + * @param array $coords + * @param CoordinateSystem $cs + * + * @return Point + * + * @throws GeometryException + */ + public static function create(array $coords, CoordinateSystem $cs) + { + $point = new Point($cs, ! $coords); + + if ($coords) { + $dim = $cs->coordinateDimension(); + + for ($i = 0; $i < $dim; $i++) { + if (! isset($coords[$i])) { + echo "expected $dim coords for " . $cs->name() . "\n"; + print_r($coords); + echo "\n"; + throw new GeometryException('Not enough coordinates provided to Point::create().'); + } + } + + $point->x = (float) $coords[0]; + $point->y = (float) $coords[1]; + + $hasZ = $cs->hasZ(); + $hasM = $cs->hasM(); + + if ($hasZ) { + $point->z = (float) $coords[2]; + + if ($hasM) { + $point->m = (float) $coords[3]; + } + } elseif ($hasM) { + $point->m = (float) $coords[2]; + } + } + + return $point; + } + /** * Creates a point with X and Y coordinates. * @@ -53,7 +99,9 @@ class Point extends Geometry */ public static function xy($x, $y, $srid = 0) { - $point = new Point(false, false, false, (int) $srid); + $cs = CoordinateSystem::xy($srid); + + $point = new Point($cs, false); $point->x = (float) $x; $point->y = (float) $y; @@ -73,7 +121,9 @@ public static function xy($x, $y, $srid = 0) */ public static function xyz($x, $y, $z, $srid = 0) { - $point = new Point(false, true, false, (int) $srid); + $cs = CoordinateSystem::xyz($srid); + + $point = new Point($cs, false); $point->x = (float) $x; $point->y = (float) $y; @@ -94,7 +144,9 @@ public static function xyz($x, $y, $z, $srid = 0) */ public static function xym($x, $y, $m, $srid = 0) { - $point = new Point(false, false, true, (int) $srid); + $cs = CoordinateSystem::xym($srid); + + $point = new Point($cs, false); $point->x = (float) $x; $point->y = (float) $y; @@ -116,7 +168,9 @@ public static function xym($x, $y, $m, $srid = 0) */ public static function xyzm($x, $y, $z, $m, $srid = 0) { - $point = new Point(false, true, true, (int) $srid); + $cs = CoordinateSystem::xyzm($srid); + + $point = new Point($cs, false); $point->x = (float) $x; $point->y = (float) $y; @@ -135,7 +189,9 @@ public static function xyzm($x, $y, $z, $m, $srid = 0) */ public static function xyEmpty($srid = 0) { - return new Point(true, false, false, (int) $srid); + $cs = CoordinateSystem::xy($srid); + + return new Point($cs, true); } /** @@ -147,7 +203,9 @@ public static function xyEmpty($srid = 0) */ public static function xyzEmpty($srid = 0) { - return new Point(true, true, false, (int) $srid); + $cs = CoordinateSystem::xyz($srid); + + return new Point($cs, true); } /** @@ -159,7 +217,9 @@ public static function xyzEmpty($srid = 0) */ public static function xymEmpty($srid = 0) { - return new Point(true, false, true, (int) $srid); + $cs = CoordinateSystem::xym($srid); + + return new Point($cs, true); } /** @@ -171,19 +231,19 @@ public static function xymEmpty($srid = 0) */ public static function xyzmEmpty($srid = 0) { - return new Point(true, true, true, (int) $srid); + $cs = CoordinateSystem::xyzm($srid); + + return new Point($cs, true); } /** - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param CoordinateSystem $cs * * @return Point */ - public static function pointEmpty($is3D, $isMeasured, $srid) + public static function pointEmpty(CoordinateSystem $cs) { - return new Point(true, (bool) $is3D, (bool) $isMeasured, (int) $srid); + return new Point($cs, true); } /** @@ -203,7 +263,17 @@ public static function pointEmpty($is3D, $isMeasured, $srid) */ public static function factory($x, $y, $z = null, $m = null, $srid = 0) { - $point = new Point(false, $z !== null, $m !== null, (int) $srid); + if ($z !== null && $m !== null) { + $cs = CoordinateSystem::xyzm($srid); + } elseif ($z !== null) { + $cs = CoordinateSystem::xyz($srid); + } elseif ($m !== null) { + $cs = CoordinateSystem::xym($srid); + } else { + $cs = CoordinateSystem::xy($srid); + } + + $point = new Point($cs, false); $point->x = (float) $x; $point->y = (float) $y; diff --git a/src/Polygon.php b/src/Polygon.php index 101545ca..676ebe4c 100644 --- a/src/Polygon.php +++ b/src/Polygon.php @@ -40,31 +40,26 @@ class Polygon extends Surface implements \Countable, \IteratorAggregate protected $rings = []; /** - * @param LineString[] $rings - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param LineString[] $rings + * @param CoordinateSystem|null $cs * * @return static * * @throws GeometryException */ - public static function create(array $rings, $is3D, $isMeasured, $srid = 0) + public static function create(array $rings, CoordinateSystem $cs = null) { - $is3D = (bool) $is3D; - $isMeasured = (bool) $isMeasured; - - $srid = (int) $srid; - - self::checkGeometries($rings, LineString::class, $is3D, $isMeasured, $srid); + $cs = self::checkGeometries($rings, LineString::class, $cs); - $polygon = new static(! $rings, $is3D, $isMeasured, $srid); + $polygon = new static($cs, ! $rings); $polygon->rings = array_values($rings); return $polygon; } /** + * @deprecated Use create() instead. + * * @param LineString[] $rings * * @return Polygon @@ -73,27 +68,11 @@ public static function create(array $rings, $is3D, $isMeasured, $srid = 0) */ public static function factory(array $rings) { - foreach ($rings as $ring) { - if (! $ring instanceof LineString) { - throw GeometryException::unexpectedGeometryType(LineString::class, $ring); - } - } - - if (! $rings) { - throw new GeometryException('A Polygon must have at least 1 ring (the exterior ring).'); - } - - self::getDimensions($rings, $is3D, $isMeasured, $srid); - if (count($rings) === 1 && count(reset($rings)) === 3 + 1) { - $polygon = new Triangle(false, $is3D, $isMeasured, $srid); - } else { - $polygon = new Polygon(false, $is3D, $isMeasured, $srid); + return Triangle::create($rings); } - $polygon->rings = array_values($rings); - - return $polygon; + return Polygon::create($rings); } /** diff --git a/src/PolyhedralSurface.php b/src/PolyhedralSurface.php index 1a0985b3..be167927 100644 --- a/src/PolyhedralSurface.php +++ b/src/PolyhedralSurface.php @@ -35,25 +35,18 @@ class PolyhedralSurface extends Surface implements \Countable, \IteratorAggregat protected $patches = []; /** - * @param Polygon[] $patches - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param Polygon[] $patches + * @param CoordinateSystem|null $cs * * @return PolyhedralSurface * * @throws GeometryException */ - public static function create(array $patches, $is3D, $isMeasured, $srid = 0) + public static function create(array $patches, CoordinateSystem $cs = null) { - $is3D = (bool) $is3D; - $isMeasured = (bool) $isMeasured; - - $srid = (int) $srid; + $cs = self::checkGeometries($patches, Polygon::class, $cs); - self::checkGeometries($patches, Polygon::class, $is3D, $isMeasured, $srid); - - $polyhedralSurface = new static(! $patches, $is3D, $isMeasured, $srid); + $polyhedralSurface = new static($cs, ! $patches); $polyhedralSurface->patches = array_values($patches); return $polyhedralSurface; @@ -62,6 +55,8 @@ public static function create(array $patches, $is3D, $isMeasured, $srid = 0) /** * Factory method to create a new PolyhedralSurface. * + * @deprecated Use create() instead. + * * @param Polygon[] $patches * * @return PolyhedralSurface @@ -70,24 +65,7 @@ public static function create(array $patches, $is3D, $isMeasured, $srid = 0) */ public static function factory(array $patches) { - if (! $patches) { - throw new GeometryException('A PolyhedralSurface must be constructed with at least one patch.'); - } - - $geometryType = static::containedGeometryType(); - - foreach ($patches as $patch) { - if (! $patch instanceof $geometryType) { - throw GeometryException::unexpectedGeometryType($geometryType, $patch); - } - } - - self::getDimensions($patches, $is3D, $isMeasured, $srid); - - $polyhedralSurface = new static(false, $is3D, $isMeasured, $srid); - $polyhedralSurface->patches = array_values($patches); - - return $polyhedralSurface; + return static::create($patches); } /** diff --git a/src/Triangle.php b/src/Triangle.php index 8de2188e..bf2f5130 100644 --- a/src/Triangle.php +++ b/src/Triangle.php @@ -10,18 +10,11 @@ class Triangle extends Polygon { /** - * @param LineString[] $rings - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid - * - * @return static - * - * @throws GeometryException + * {@inheritdoc} */ - public static function create(array $rings, $is3D, $isMeasured, $srid = 0) + public static function create(array $rings, CoordinateSystem $cs = null) { - $triangle = parent::create($rings, $is3D, $isMeasured, $srid); + $triangle = parent::create($rings, $cs); if (! $triangle->isEmpty()) { if ($triangle->exteriorRing()->numPoints() !== 4) { diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index c9260cb7..7f398540 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -2,6 +2,7 @@ namespace Brick\Geo\Tests; +use Brick\Geo\CoordinateSystem; use Brick\Geo\Engine\GeometryEngineRegistry; use Brick\Geo\Engine\GEOSEngine; use Brick\Geo\Engine\PDOEngine; @@ -321,82 +322,48 @@ final protected function assertMultiPolygonEquals(array $coords, $is3D, $isMeasu } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * * @return Point */ - final protected function createPoint(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createPoint(array $coords, CoordinateSystem $cs) { - if (! $coords) { - if ($is3D && $isMeasured) { - return Point::xyzmEmpty($srid); - } - - if ($is3D) { - return Point::xyzEmpty($srid); - } - - if ($isMeasured) { - return Point::xymEmpty($srid); - } - - return Point::xyEmpty($srid); - } - - if ($is3D && $isMeasured) { - return Point::xyzm($coords[0], $coords[1], $coords[2], $coords[3], $srid); - } - - if ($is3D) { - return Point::xyz($coords[0], $coords[1], $coords[2], $srid); - } - - if ($isMeasured) { - return Point::xym($coords[0], $coords[1], $coords[2], $srid); - } - - return Point::xy($coords[0], $coords[1], $srid); + return Point::create($coords, $cs); } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * * @return LineString */ - final protected function createLineString(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createLineString(array $coords, CoordinateSystem $cs) { $points = []; foreach ($coords as $point) { - $points[] = $this->createPoint($point, $is3D, $isMeasured, $srid); + $points[] = $this->createPoint($point, $cs); } - return LineString::create($points, $is3D, $isMeasured, $srid); + return LineString::create($points, $cs); } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * - * @return LineString + * @return CircularString */ - final protected function createCircularString(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createCircularString(array $coords, CoordinateSystem $cs) { $points = []; foreach ($coords as $point) { - $points[] = $this->createPoint($point, $is3D, $isMeasured, $srid); + $points[] = $this->createPoint($point,$cs); } - return CircularString::create($points, $is3D, $isMeasured, $srid); + return CircularString::create($points, $cs); } /** @@ -405,197 +372,177 @@ final protected function createCircularString(array $coords, $is3D, $isMeasured, * For the purpose of these tests, it is assumed that a curve with an even number of points is * a LineString, and a curve with an odd number of points is a CircularString. * - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * * @return Curve */ - final protected function createLineStringOrCircularString(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createLineStringOrCircularString(array $coords, CoordinateSystem $cs) { if (count($coords) % 2 == 0) { - return $this->createLineString($coords, $is3D, $isMeasured, $srid); + return $this->createLineString($coords, $cs); } else { - return $this->createCircularString($coords, $is3D, $isMeasured, $srid); + return $this->createCircularString($coords, $cs); } } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * - * @return LineString + * @return CompoundCurve */ - final protected function createCompoundCurve(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createCompoundCurve(array $coords, CoordinateSystem $cs) { $curves = []; foreach ($coords as $curve) { - $curves[] = $this->createLineStringOrCircularString($curve, $is3D, $isMeasured, $srid); + $curves[] = $this->createLineStringOrCircularString($curve, $cs); } - return CompoundCurve::create($curves, $is3D, $isMeasured, $srid); + return CompoundCurve::create($curves, $cs); } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * * @return Polygon */ - final protected function createPolygon(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createPolygon(array $coords, CoordinateSystem $cs) { $rings = []; foreach ($coords as $ring) { - $rings[] = $this->createLineString($ring, $is3D, $isMeasured, $srid); + $rings[] = $this->createLineString($ring, $cs); } - return Polygon::create($rings, $is3D, $isMeasured, $srid); + return Polygon::create($rings, $cs); } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * * @return Triangle */ - final protected function createTriangle(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createTriangle(array $coords, CoordinateSystem $cs) { $rings = []; foreach ($coords as $ring) { - $rings[] = $this->createLineString($ring, $is3D, $isMeasured, $srid); + $rings[] = $this->createLineString($ring, $cs); } - return Triangle::create($rings, $is3D, $isMeasured, $srid); + return Triangle::create($rings, $cs); } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * * @return CurvePolygon */ - final protected function createCurvePolygon(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createCurvePolygon(array $coords, CoordinateSystem $cs) { $rings = []; foreach ($coords as $ring) { if (is_array($ring[0][0])) { // CompoundCurve - $rings[] = $this->createCompoundCurve($ring, $is3D, $isMeasured, $srid); + $rings[] = $this->createCompoundCurve($ring, $cs); } else { // LineString or CircularString - $rings[] = $this->createLineStringOrCircularString($ring, $is3D, $isMeasured, $srid); + $rings[] = $this->createLineStringOrCircularString($ring, $cs); } } - return CurvePolygon::create($rings, $is3D, $isMeasured, $srid); + return CurvePolygon::create($rings, $cs); } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * * @return MultiPoint */ - final protected function createMultiPoint(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createMultiPoint(array $coords, CoordinateSystem $cs) { $points = []; foreach ($coords as $point) { - $points[] = $this->createPoint($point, $is3D, $isMeasured, $srid); + $points[] = $this->createPoint($point, $cs); } - return MultiPoint::create($points, $is3D, $isMeasured, $srid); + return MultiPoint::create($points, $cs); } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * * @return MultiLineString */ - final protected function createMultiLineString(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createMultiLineString(array $coords, CoordinateSystem $cs) { $lineStrings = []; foreach ($coords as $lineString) { - $lineStrings[] = $this->createLineString($lineString, $is3D, $isMeasured, $srid); + $lineStrings[] = $this->createLineString($lineString, $cs); } - return MultiLineString::create($lineStrings, $is3D, $isMeasured, $srid); + return MultiLineString::create($lineStrings, $cs); } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * * @return MultiPolygon */ - final protected function createMultiPolygon(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createMultiPolygon(array $coords, CoordinateSystem $cs) { $polygons = []; foreach ($coords as $polygon) { - $polygons[] = $this->createPolygon($polygon, $is3D, $isMeasured, $srid); + $polygons[] = $this->createPolygon($polygon, $cs); } - return MultiPolygon::create($polygons, $is3D, $isMeasured, $srid); + return MultiPolygon::create($polygons, $cs); } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * * @return PolyhedralSurface */ - final protected function createPolyhedralSurface(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createPolyhedralSurface(array $coords, CoordinateSystem $cs) { $patches = []; foreach ($coords as $patch) { - $patches[] = $this->createPolygon($patch, $is3D, $isMeasured, $srid); + $patches[] = $this->createPolygon($patch, $cs); } - return PolyhedralSurface::create($patches, $is3D, $isMeasured, $srid); + return PolyhedralSurface::create($patches, $cs); } /** - * @param array $coords - * @param boolean $is3D - * @param boolean $isMeasured - * @param integer $srid + * @param array $coords + * @param CoordinateSystem $cs * * @return TIN */ - final protected function createTIN(array $coords, $is3D, $isMeasured, $srid = 0) + final protected function createTIN(array $coords, CoordinateSystem $cs) { $patches = []; foreach ($coords as $patch) { - $patches[] = $this->createTriangle($patch, $is3D, $isMeasured, $srid); + $patches[] = $this->createTriangle($patch, $cs); } - return TIN::create($patches, $is3D, $isMeasured, $srid); + return TIN::create($patches, $cs); } /** diff --git a/tests/CircularStringTest.php b/tests/CircularStringTest.php index 97e09136..f2850224 100644 --- a/tests/CircularStringTest.php +++ b/tests/CircularStringTest.php @@ -3,6 +3,7 @@ namespace Brick\Geo\Tests; use Brick\Geo\CircularString; +use Brick\Geo\CoordinateSystem; use Brick\Geo\Point; /** @@ -13,20 +14,21 @@ class CircularStringTest extends AbstractTestCase /** * @dataProvider providerCreate * - * @param string[] $points The WKT of the Points that compose the CircularString. - * @param boolean $is3D Whether the points have Z coordinates. - * @param boolean $isMeasured Whether the points have M coordinates. - * @param string $circularString The WKT of the expected CircularString. + * @param string[] $pointsWKT The WKT of the Points that compose the CircularString. + * @param boolean $is3D Whether the points have Z coordinates. + * @param boolean $isMeasured Whether the points have M coordinates. + * @param string $circularStringWKT The WKT of the expected CircularString. */ - public function testCreate(array $points, $is3D, $isMeasured, $circularString) + public function testCreate(array $pointsWKT, $is3D, $isMeasured, $circularStringWKT) { foreach ([0, 1] as $srid) { $instantiatePoint = function ($point) use ($srid) { return Point::fromText($point, $srid); }; - $cs = CircularString::create(array_map($instantiatePoint, $points), $is3D, $isMeasured, $srid); - $this->assertWktEquals($cs, $circularString, $srid); + $cs = CoordinateSystem::create($is3D, $isMeasured, $srid); + $circularString = CircularString::create(array_map($instantiatePoint, $pointsWKT), $cs); + $this->assertWktEquals($circularString, $circularStringWKT, $srid); } } diff --git a/tests/CompoundCurveTest.php b/tests/CompoundCurveTest.php index 8807c9ae..449cfa8b 100644 --- a/tests/CompoundCurveTest.php +++ b/tests/CompoundCurveTest.php @@ -3,6 +3,7 @@ namespace Brick\Geo\Tests; use Brick\Geo\CompoundCurve; +use Brick\Geo\CoordinateSystem; use Brick\Geo\Curve; use Brick\Geo\Exception\GeometryException; @@ -14,20 +15,21 @@ class CompoundCurveTest extends AbstractTestCase /** * @dataProvider providerCreate * - * @param string[] $curves The WKT of the Curves that compose the CompoundCurve. - * @param boolean $is3D Whether the curves have Z coordinates. - * @param boolean $isMeasured Whether the curves have M coordinates. - * @param string $compoundCurve The WKT of the expected CompoundCurve. + * @param string[] $curvesWKT The WKT of the Curves that compose the CompoundCurve. + * @param boolean $is3D Whether the curves have Z coordinates. + * @param boolean $isMeasured Whether the curves have M coordinates. + * @param string $compoundCurveWKT The WKT of the expected CompoundCurve. */ - public function testCreate(array $curves, $is3D, $isMeasured, $compoundCurve) + public function testCreate(array $curvesWKT, $is3D, $isMeasured, $compoundCurveWKT) { foreach ([0, 1] as $srid) { $instantiateCurve = function ($curve) use ($srid) { return Curve::fromText($curve, $srid); }; - $cs = CompoundCurve::create(array_map($instantiateCurve, $curves), $is3D, $isMeasured, $srid); - $this->assertWktEquals($cs, $compoundCurve, $srid); + $cs = CoordinateSystem::create($is3D, $isMeasured, $srid); + $compoundCurve = CompoundCurve::create(array_map($instantiateCurve, $curvesWKT), $cs); + $this->assertWktEquals($compoundCurve, $compoundCurveWKT, $srid); } } diff --git a/tests/CurvePolygonTest.php b/tests/CurvePolygonTest.php index 9cf5adb4..452a7e2d 100644 --- a/tests/CurvePolygonTest.php +++ b/tests/CurvePolygonTest.php @@ -2,6 +2,7 @@ namespace Brick\Geo\Tests; +use Brick\Geo\CoordinateSystem; use Brick\Geo\CurvePolygon; use Brick\Geo\Exception\GeometryException; @@ -19,7 +20,8 @@ class CurvePolygonTest extends AbstractTestCase */ public function testEmptyFactoryMethod($is3D, $isMeasured, $srid) { - $polygon = CurvePolygon::create([], $is3D, $isMeasured, $srid); + $cs = CoordinateSystem::create($is3D, $isMeasured, $srid); + $polygon = CurvePolygon::create([], $cs); $this->assertTrue($polygon->isEmpty()); $this->assertSame($is3D, $polygon->is3D()); diff --git a/tests/IO/EWKTWriterTest.php b/tests/IO/EWKTWriterTest.php index 5082c9ad..8a77cb34 100644 --- a/tests/IO/EWKTWriterTest.php +++ b/tests/IO/EWKTWriterTest.php @@ -2,6 +2,7 @@ namespace Brick\Geo\Tests\IO; +use Brick\Geo\CoordinateSystem; use Brick\Geo\GeometryCollection; use Brick\Geo\IO\EWKTWriter; @@ -21,7 +22,7 @@ public function testPrettyPrint($prettyPrint, $ewkt) $writer = new EWKTWriter(); $writer->setPrettyPrint($prettyPrint); - $lineString = $this->createLineString([[1, 2, 3, 4], [5, 6, 7, 8]], true, true, 4326); + $lineString = $this->createLineString([[1, 2, 3, 4], [5, 6, 7, 8]], CoordinateSystem::xyzm(4326)); $this->assertSame($ewkt, $writer->write($lineString)); } @@ -50,7 +51,9 @@ public function testWritePoint($wkt, array $coords, $is3D, $isMeasured) $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $point = $this->createPoint($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $point = $this->createPoint($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($point)); } @@ -67,7 +70,9 @@ public function testWriteLineString($wkt, array $coords, $is3D, $isMeasured) $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $lineString = $this->createLineString($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $lineString = $this->createLineString($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($lineString)); } @@ -84,7 +89,9 @@ public function testWriteCircularString($wkt, array $coords, $is3D, $isMeasured) $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $lineString = $this->createCircularString($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $lineString = $this->createCircularString($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($lineString)); } @@ -101,7 +108,9 @@ public function testWriteCompoundCurve($wkt, array $coords, $is3D, $isMeasured) $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $compoundCurve = $this->createCompoundCurve($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $compoundCurve = $this->createCompoundCurve($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($compoundCurve)); } @@ -118,7 +127,9 @@ public function testWritePolygon($wkt, array $coords, $is3D, $isMeasured) $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $polygon = $this->createPolygon($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $polygon = $this->createPolygon($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($polygon)); } @@ -135,7 +146,9 @@ public function testWriteTriangle($wkt, array $coords, $is3D, $isMeasured) $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $triangle = $this->createTriangle($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $triangle = $this->createTriangle($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($triangle)); } @@ -152,7 +165,9 @@ public function testWriteCurvePolygon($wkt, array $coords, $is3D, $isMeasured) $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $polygon = $this->createCurvePolygon($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $polygon = $this->createCurvePolygon($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($polygon)); } @@ -169,7 +184,9 @@ public function testWritePolyhedralSurface($wkt, array $coords, $is3D, $isMeasur $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $polyhedralSurface = $this->createPolyhedralSurface($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $polyhedralSurface = $this->createPolyhedralSurface($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($polyhedralSurface)); } @@ -186,7 +203,9 @@ public function testWriteTIN($wkt, array $coords, $is3D, $isMeasured) $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $tin = $this->createTIN($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $tin = $this->createTIN($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($tin)); } @@ -203,7 +222,9 @@ public function testWriteMultiPoint($wkt, array $coords, $is3D, $isMeasured) $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $multiPoint = $this->createMultiPoint($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $multiPoint = $this->createMultiPoint($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($multiPoint)); } @@ -220,7 +241,9 @@ public function testWriteMultiLineString($wkt, array $coords, $is3D, $isMeasured $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $multiLineString = $this->createMultiLineString($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $multiLineString = $this->createMultiLineString($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($multiLineString)); } @@ -237,7 +260,9 @@ public function testWriteMultiPolygon($wkt, array $coords, $is3D, $isMeasured) $writer = new EWKTWriter(); $writer->setPrettyPrint(false); - $multiPolygon = $this->createMultiPolygon($coords, $is3D, $isMeasured, 4326); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + $multiPolygon = $this->createMultiPolygon($coords, $cs); + $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($multiPolygon)); } @@ -254,15 +279,17 @@ public function testWriteGeometryCollection($wkt, array $coords, $is3D, $isMeasu $writer = new EWKTWriter(); $writer->setPrettyPrint(false); + $cs = CoordinateSystem::create($is3D, $isMeasured, 4326); + if ($coords) { - $point = $this->createPoint($coords[0], $is3D, $isMeasured, 4326); - $lineString = $this->createLineString($coords[1], $is3D, $isMeasured, 4326); + $point = $this->createPoint($coords[0], $cs); + $lineString = $this->createLineString($coords[1], $cs); $geometries = [$point, $lineString]; } else { $geometries = []; } - $geometryCollection = GeometryCollection::create($geometries, $is3D, $isMeasured, 4326); + $geometryCollection = GeometryCollection::create($geometries, $cs); $this->assertSame($this->toEWKT($wkt, 4326), $writer->write($geometryCollection)); } } diff --git a/tests/IO/WKTWriterTest.php b/tests/IO/WKTWriterTest.php index f2f74f50..4662be9c 100644 --- a/tests/IO/WKTWriterTest.php +++ b/tests/IO/WKTWriterTest.php @@ -2,6 +2,7 @@ namespace Brick\Geo\Tests\IO; +use Brick\Geo\CoordinateSystem; use Brick\Geo\GeometryCollection; use Brick\Geo\IO\WKTWriter; use Brick\Geo\MultiLineString; @@ -23,9 +24,11 @@ public function testPrettyPrint($is3D, $prettyPrint, $wkt) $writer = new WKTWriter(); $writer->setPrettyPrint($prettyPrint); - $point = $this->createPoint([1, 2, 3], $is3D, false); - $lineString1 = $this->createLineString([[1, 2, 3], [4, 5, 6]], $is3D, false); - $lineString2 = $this->createLineString([[2, 3, 4], [5, 6, 7]], $is3D, false); + $cs = CoordinateSystem::create($is3D, false); + + $point = $this->createPoint([1, 2, 3], $cs); + $lineString1 = $this->createLineString([[1, 2, 3], [4, 5, 6]], $cs); + $lineString2 = $this->createLineString([[2, 3, 4], [5, 6, 7]], $cs); $multiLineString = MultiLineString::factory([$lineString1, $lineString2]); $geometryCollection = GeometryCollection::factory([$point, $multiLineString]); @@ -59,7 +62,9 @@ public function testWritePoint($wkt, array $coords, $is3D, $isMeasured) $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $point = $this->createPoint($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $point = $this->createPoint($coords, $cs); + $this->assertSame($wkt, $writer->write($point)); } @@ -76,7 +81,9 @@ public function testWriteLineString($wkt, array $coords, $is3D, $isMeasured) $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $lineString = $this->createLineString($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $lineString = $this->createLineString($coords, $cs); + $this->assertSame($wkt, $writer->write($lineString)); } @@ -93,7 +100,9 @@ public function testWriteCircularString($wkt, array $coords, $is3D, $isMeasured) $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $lineString = $this->createCircularString($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $lineString = $this->createCircularString($coords, $cs); + $this->assertSame($wkt, $writer->write($lineString)); } @@ -110,7 +119,9 @@ public function testWriteCompoundCurve($wkt, array $coords, $is3D, $isMeasured) $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $compoundCurve = $this->createCompoundCurve($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $compoundCurve = $this->createCompoundCurve($coords, $cs); + $this->assertSame($wkt, $writer->write($compoundCurve)); } @@ -127,7 +138,9 @@ public function testWritePolygon($wkt, array $coords, $is3D, $isMeasured) $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $polygon = $this->createPolygon($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $polygon = $this->createPolygon($coords, $cs); + $this->assertSame($wkt, $writer->write($polygon)); } @@ -144,7 +157,9 @@ public function testWriteTriangle($wkt, array $coords, $is3D, $isMeasured) $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $triangle = $this->createTriangle($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $triangle = $this->createTriangle($coords, $cs); + $this->assertSame($wkt, $writer->write($triangle)); } @@ -161,7 +176,9 @@ public function testWriteCurvePolygon($wkt, array $coords, $is3D, $isMeasured) $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $polygon = $this->createCurvePolygon($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $polygon = $this->createCurvePolygon($coords, $cs); + $this->assertSame($wkt, $writer->write($polygon)); } @@ -178,7 +195,9 @@ public function testWritePolyhedralSurface($wkt, array $coords, $is3D, $isMeasur $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $polyhedralSurface = $this->createPolyhedralSurface($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $polyhedralSurface = $this->createPolyhedralSurface($coords, $cs); + $this->assertSame($wkt, $writer->write($polyhedralSurface)); } @@ -195,7 +214,9 @@ public function testWriteTIN($wkt, array $coords, $is3D, $isMeasured) $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $tin = $this->createTIN($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $tin = $this->createTIN($coords, $cs); + $this->assertSame($wkt, $writer->write($tin)); } @@ -212,7 +233,9 @@ public function testWriteMultiPoint($wkt, array $coords, $is3D, $isMeasured) $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $multiPoint = $this->createMultiPoint($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $multiPoint = $this->createMultiPoint($coords, $cs); + $this->assertSame($wkt, $writer->write($multiPoint)); } @@ -229,7 +252,9 @@ public function testWriteMultiLineString($wkt, array $coords, $is3D, $isMeasured $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $multiLineString = $this->createMultiLineString($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $multiLineString = $this->createMultiLineString($coords, $cs); + $this->assertSame($wkt, $writer->write($multiLineString)); } @@ -246,7 +271,9 @@ public function testWriteMultiPolygon($wkt, array $coords, $is3D, $isMeasured) $writer = new WKTWriter(); $writer->setPrettyPrint(false); - $multiPolygon = $this->createMultiPolygon($coords, $is3D, $isMeasured); + $cs = CoordinateSystem::create($is3D, $isMeasured); + $multiPolygon = $this->createMultiPolygon($coords, $cs); + $this->assertSame($wkt, $writer->write($multiPolygon)); } @@ -263,15 +290,17 @@ public function testWriteGeometryCollection($wkt, array $coords, $is3D, $isMeasu $writer = new WKTWriter(); $writer->setPrettyPrint(false); + $cs = CoordinateSystem::create($is3D, $isMeasured); + if ($coords) { - $point = $this->createPoint($coords[0], $is3D, $isMeasured); - $lineString = $this->createLineString($coords[1], $is3D, $isMeasured); + $point = $this->createPoint($coords[0], $cs); + $lineString = $this->createLineString($coords[1], $cs); $geometries = [$point, $lineString]; } else { $geometries = []; } - $geometryCollection = GeometryCollection::create($geometries, $is3D, $isMeasured); + $geometryCollection = GeometryCollection::create($geometries, $cs); $this->assertSame($wkt, $writer->write($geometryCollection)); } diff --git a/tests/MultiCurveTest.php b/tests/MultiCurveTest.php index cd8938f4..b99e8817 100644 --- a/tests/MultiCurveTest.php +++ b/tests/MultiCurveTest.php @@ -65,7 +65,7 @@ public function providerInvalidFromBinary() */ public function testCreateWithNonCurveContentsThrowsException() { - MultiCurve::create([Point::xyEmpty()], false, false); + MultiCurve::create([Point::xyEmpty()]); } /** diff --git a/tests/MultiSurfaceTest.php b/tests/MultiSurfaceTest.php index ef8ff77b..da9a9526 100644 --- a/tests/MultiSurfaceTest.php +++ b/tests/MultiSurfaceTest.php @@ -65,7 +65,7 @@ public function providerInvalidFromBinary() */ public function testCreateWithNonSurfaceContentsThrowsException() { - MultiSurface::create([Point::xyEmpty()], false, false); + MultiSurface::create([Point::xyEmpty()]); } /** diff --git a/tests/PointTest.php b/tests/PointTest.php index 8be02bfb..8085ce16 100644 --- a/tests/PointTest.php +++ b/tests/PointTest.php @@ -82,202 +82,4 @@ public function providerEmptyFactoryMethods() [Point::xyzmEmpty(4326), true, true, 4326] ]; } - - /** - * @dataProvider providerWithX - * - * @param string $point The WKT of the point to alter. - * @param string $result The WKT of the expected result. - */ - public function testWithX($point, $result) - { - $this->assertWktEquals(Point::fromText($point)->withX(9), $result); - $this->assertWktEquals(Point::fromText($point, 4326)->withX(9), $result, 4326); - } - - /** - * @return array - */ - public function providerWithX() - { - return [ - ['POINT (1 2)', 'POINT (9 2)'], - ['POINT Z (1 2 3)', 'POINT Z (9 2 3)'], - ['POINT M (1 2 3)', 'POINT M (9 2 3)'], - ['POINT ZM (1 2 3 4)', 'POINT ZM (9 2 3 4)'] - ]; - } - - /** - * @dataProvider providerWithY - * - * @param string $point The WKT of the point to alter. - * @param string $result The WKT of the expected result. - */ - public function testWithY($point, $result) - { - $this->assertWktEquals(Point::fromText($point)->withY(9), $result); - $this->assertWktEquals(Point::fromText($point, 4326)->withY(9), $result, 4326); - } - - /** - * @return array - */ - public function providerWithY() - { - return [ - ['POINT (1 2)', 'POINT (1 9)'], - ['POINT Z (1 2 3)', 'POINT Z (1 9 3)'], - ['POINT M (1 2 3)', 'POINT M (1 9 3)'], - ['POINT ZM (1 2 3 4)', 'POINT ZM (1 9 3 4)'] - ]; - } - - /** - * @dataProvider providerWithZ - * - * @param string $point The WKT of the point to alter. - * @param string $result The WKT of the expected result. - */ - public function testWithZ($point, $result) - { - $this->assertWktEquals(Point::fromText($point)->withZ(9), $result); - $this->assertWktEquals(Point::fromText($point, 4326)->withZ(9), $result, 4326); - } - - /** - * @return array - */ - public function providerWithZ() - { - return [ - ['POINT (1 2)', 'POINT Z (1 2 9)'], - ['POINT Z (1 2 3)', 'POINT Z (1 2 9)'], - ['POINT M (1 2 3)', 'POINT ZM (1 2 9 3)'], - ['POINT ZM (1 2 3 4)', 'POINT ZM (1 2 9 4)'] - ]; - } - - /** - * @dataProvider providerWithM - * - * @param string $point The WKT of the point to alter. - * @param string $result The WKT of the expected result. - */ - public function testWithM($point, $result) - { - $this->assertWktEquals(Point::fromText($point)->withM(9), $result); - $this->assertWktEquals(Point::fromText($point, 4326)->withM(9), $result, 4326); - } - - /** - * @return array - */ - public function providerWithM() - { - return [ - ['POINT (1 2)', 'POINT M (1 2 9)'], - ['POINT Z (1 2 3)', 'POINT ZM (1 2 3 9)'], - ['POINT M (1 2 3)', 'POINT M (1 2 9)'], - ['POINT ZM (1 2 3 4)', 'POINT ZM (1 2 3 9)'] - ]; - } - - /** - * @dataProvider providerWithoutZ - * - * @param string $point The WKT of the point to alter. - * @param string $result The WKT of the expected result. - */ - public function testWithoutZ($point, $result) - { - $this->assertWktEquals(Point::fromText($point)->withoutZ(), $result); - $this->assertWktEquals(Point::fromText($point, 4326)->withoutZ(), $result, 4326); - } - - /** - * @return array - */ - public function providerWithoutZ() - { - return [ - ['POINT (1 2)', 'POINT (1 2)'], - ['POINT Z (1 2 3)', 'POINT (1 2)'], - ['POINT M (1 2 3)', 'POINT M (1 2 3)'], - ['POINT ZM (1 2 3 4)', 'POINT M (1 2 4)'] - ]; - } - - /** - * @dataProvider providerWithoutM - * - * @param string $point The WKT of the point to alter. - * @param string $result The WKT of the expected result. - */ - public function testWithoutM($point, $result) - { - $this->assertWktEquals(Point::fromText($point)->withoutM(), $result); - $this->assertWktEquals(Point::fromText($point, 4326)->withoutM(), $result, 4326); - } - - /** - * @return array - */ - public function providerWithoutM() - { - return [ - ['POINT (1 2)', 'POINT (1 2)'], - ['POINT Z (1 2 3)', 'POINT Z (1 2 3)'], - ['POINT M (1 2 3)', 'POINT (1 2)'], - ['POINT ZM (1 2 3 4)', 'POINT Z (1 2 3)'] - ]; - } - - /** - * @dataProvider providerWithoutZM - * - * @param string $point The WKT of the point to alter. - * @param string $result The WKT of the expected result. - */ - public function testWithoutZM($point, $result) - { - $this->assertWktEquals(Point::fromText($point)->withoutZM(), $result); - $this->assertWktEquals(Point::fromText($point, 4326)->withoutZM(), $result, 4326); - } - - /** - * @return array - */ - public function providerWithoutZM() - { - return [ - ['POINT (1 2)', 'POINT (1 2)'], - ['POINT Z (1 2 3)', 'POINT (1 2)'], - ['POINT M (1 2 3)', 'POINT (1 2)'], - ['POINT ZM (1 2 3 4)', 'POINT (1 2)'] - ]; - } - - /** - * @dataProvider providerWithSRID - * - * @param string $point The WKT of the point to alter. - */ - public function testWithSRID($point) - { - $this->assertWktEquals(Point::fromText($point, 4326)->withSRID(4327), $point, 4327); - } - - /** - * @return array - */ - public function providerWithSRID() - { - return [ - ['POINT (1 2)'], - ['POINT Z (1 2 3)'], - ['POINT M (1 2 3)'], - ['POINT ZM (1 2 3 4)'] - ]; - } } diff --git a/tests/PolygonTest.php b/tests/PolygonTest.php index 3da68a79..81813784 100644 --- a/tests/PolygonTest.php +++ b/tests/PolygonTest.php @@ -2,6 +2,7 @@ namespace Brick\Geo\Tests; +use Brick\Geo\CoordinateSystem; use Brick\Geo\Exception\GeometryException; use Brick\Geo\Polygon; @@ -19,7 +20,8 @@ class PolygonTest extends AbstractTestCase */ public function testEmptyFactoryMethod($is3D, $isMeasured, $srid) { - $polygon = Polygon::create([], $is3D, $isMeasured, $srid); + $cs = CoordinateSystem::create($is3D, $isMeasured, $srid); + $polygon = Polygon::create([], $cs); $this->assertTrue($polygon->isEmpty()); $this->assertSame($is3D, $polygon->is3D()); diff --git a/tests/PolyhedralSurfaceTest.php b/tests/PolyhedralSurfaceTest.php index 3c751e6d..731f06d9 100644 --- a/tests/PolyhedralSurfaceTest.php +++ b/tests/PolyhedralSurfaceTest.php @@ -2,6 +2,7 @@ namespace Brick\Geo\Tests; +use Brick\Geo\CoordinateSystem; use Brick\Geo\Polygon; use Brick\Geo\PolyhedralSurface; use Brick\Geo\Exception\GeometryException; @@ -14,20 +15,21 @@ class PolyhedralSurfaceTest extends AbstractTestCase /** * @dataProvider providerCreate * - * @param string[] $patches The WKT of the patches (polygons) that compose the PolyhedralSurface. - * @param boolean $is3D Whether the patches have Z coordinates. - * @param boolean $isMeasured Whether the patches have M coordinates. - * @param string $polyhedralSurface The WKT of the expected PolyhedralSurface. + * @param string[] $patchesWKT The WKT of the patches (polygons) that compose the PolyhedralSurface. + * @param boolean $is3D Whether the patches have Z coordinates. + * @param boolean $isMeasured Whether the patches have M coordinates. + * @param string $polyhedralSurfaceWKT The WKT of the expected PolyhedralSurface. */ - public function testCreate(array $patches, $is3D, $isMeasured, $polyhedralSurface) + public function testCreate(array $patchesWKT, $is3D, $isMeasured, $polyhedralSurfaceWKT) { foreach ([0, 1] as $srid) { $instantiatePolygon = function ($patch) use ($srid) { return Polygon::fromText($patch, $srid); }; - $ps = PolyhedralSurface::create(array_map($instantiatePolygon, $patches), $is3D, $isMeasured, $srid); - $this->assertWktEquals($ps, $polyhedralSurface, $srid); + $cs = CoordinateSystem::create($is3D, $isMeasured, $srid); + $polyhedralSurface = PolyhedralSurface::create(array_map($instantiatePolygon, $patchesWKT), $cs); + $this->assertWktEquals($polyhedralSurface, $polyhedralSurfaceWKT, $srid); } } diff --git a/tests/TINTest.php b/tests/TINTest.php index 02890770..ac6a5c43 100644 --- a/tests/TINTest.php +++ b/tests/TINTest.php @@ -15,7 +15,7 @@ public function testCreate() $triangle1 = Triangle::fromText('TRIANGLE ((1 1, 1 2, 2 2, 1 1))'); $triangle2 = Triangle::fromText('TRIANGLE ((1 1, 2 2, 2 1, 1 1))'); - $tin = TIN::create([$triangle1, $triangle2], false, false); + $tin = TIN::create([$triangle1, $triangle2]); $this->assertWktEquals($tin, 'TIN (((1 1, 1 2, 2 2, 1 1)), ((1 1, 2 2, 2 1, 1 1)))'); } } diff --git a/tests/TriangleTest.php b/tests/TriangleTest.php index 0734c872..0831e0f5 100644 --- a/tests/TriangleTest.php +++ b/tests/TriangleTest.php @@ -2,6 +2,7 @@ namespace Brick\Geo\Tests; +use Brick\Geo\CoordinateSystem; use Brick\Geo\LineString; use Brick\Geo\Triangle; @@ -13,7 +14,7 @@ class TriangleTest extends AbstractTestCase public function testCreate() { $ring = LineString::fromText('LINESTRING (1 1, 1 2, 2 2, 1 1)'); - $triangle = Triangle::create([$ring], false, false); + $triangle = Triangle::create([$ring]); $this->assertWktEquals($triangle, 'TRIANGLE ((1 1, 1 2, 2 2, 1 1))'); } @@ -24,7 +25,7 @@ public function testCreateWithInvalidNumberOfPoints() { $ring = LineString::fromText('LINESTRING (1 1, 1 2, 2 2, 2 1, 1 1)'); - Triangle::create([$ring], false, false); + Triangle::create([$ring]); } /** @@ -35,6 +36,6 @@ public function testCreateWithInteriorRings() $exteriorRing = LineString::fromText('LINESTRING (0 0, 0 3, 3 3, 0 0)'); $interiorRing = LineString::fromText('LINESTRING (1 1, 1 2, 2 2, 1 1)'); - Triangle::create([$exteriorRing, $interiorRing], false, false); + Triangle::create([$exteriorRing, $interiorRing]); } }