Exemple #1
0
 /**
  * @dataProvider providerPrettyPrint
  *
  * @param boolean $prettyPrint Whether to set the prettyPrint parameter.
  * @param string  $ewkt        The expected result EWKT.
  */
 public function testPrettyPrint($prettyPrint, $ewkt)
 {
     $writer = new EWKTWriter();
     $writer->setPrettyPrint($prettyPrint);
     $lineString = $this->createLineString([[1, 2, 3, 4], [5, 6, 7, 8]], CoordinateSystem::xyzm(4326));
     $this->assertSame($ewkt, $writer->write($lineString));
 }
Exemple #2
0
 /**
  * Class constructor.
  *
  * The coordinate system of each of the rings must match the one of the Polygon.
  *
  * @param CoordinateSystem $cs       The coordinate system of the Polygon.
  * @param LineString       ...$rings The rings that compose the Polygon, the first one being the exterior ring.
  *
  * @throws InvalidGeometryException  If the resulting geometry is not valid for a sub-type of Polygon.
  * @throws CoordinateSystemException If different coordinate systems are used.
  */
 public function __construct(CoordinateSystem $cs, LineString ...$rings)
 {
     parent::__construct($cs, !$rings);
     if (!$rings) {
         return;
     }
     CoordinateSystem::check($this, ...$rings);
     $this->rings = $rings;
 }
Exemple #3
0
 /**
  * Class constructor.
  *
  * The coordinate system of each of the patches must match the one of the PolyhedralSurface.
  *
  * @param CoordinateSystem $cs         The coordinate system of the PolyhedralSurface.
  * @param Polygon          ...$patches The patches that compose the PolyhedralSurface.
  *
  * @throws CoordinateSystemException If different coordinate systems are used.
  */
 public function __construct(CoordinateSystem $cs, Polygon ...$patches)
 {
     parent::__construct($cs, !$patches);
     if (!$patches) {
         return;
     }
     CoordinateSystem::check($this, ...$patches);
     $this->patches = $patches;
 }
Exemple #4
0
 /**
  * Class constructor.
  *
  * A LineString must be composed of 2 points or more, or 0 points for an empty LineString.
  * A LineString with exactly 1 point is not allowed.
  *
  * The coordinate system of each of the points must match the one of the LineString.
  *
  * @param CoordinateSystem $cs        The coordinate system of the LineString.
  * @param Point            ...$points The points that compose the LineString.
  *
  * @throws InvalidGeometryException  If only one point was given.
  * @throws CoordinateSystemException If different coordinate systems are used.
  */
 public function __construct(CoordinateSystem $cs, Point ...$points)
 {
     parent::__construct($cs, !$points);
     if (!$points) {
         return;
     }
     CoordinateSystem::check($this, ...$points);
     if (count($points) < 2) {
         throw new InvalidGeometryException('A LineString must be composed of at least 2 points.');
     }
     $this->points = $points;
 }
Exemple #5
0
 /**
  * @param CoordinateSystem $cs
  * @param Point            ...$points
  *
  * @return CircularString
  *
  * @throws InvalidGeometryException  If the number of points is invalid.
  * @throws CoordinateSystemException If different coordinate systems are used.
  */
 public function __construct(CoordinateSystem $cs, Point ...$points)
 {
     parent::__construct($cs, !$points);
     if (!$points) {
         return;
     }
     CoordinateSystem::check($this, ...$points);
     $numPoints = count($points);
     if ($numPoints < 3) {
         throw new InvalidGeometryException('A CircularString must be made of at least 3 points.');
     }
     if ($numPoints % 2 === 0) {
         throw new InvalidGeometryException('A CircularString must have an odd number of points.');
     }
     $this->points = $points;
 }
Exemple #6
0
 /**
  * Class constructor.
  *
  * @param CoordinateSystem $cs
  * @param Geometry         ...$geometries
  *
  * @throws CoordinateSystemException   If different coordinate systems are used.
  * @throws UnexpectedGeometryException If a geometry is not a valid type for a sub-class of GeometryCollection.
  */
 public function __construct(CoordinateSystem $cs, Geometry ...$geometries)
 {
     $isEmpty = true;
     foreach ($geometries as $geometry) {
         if (!$geometry->isEmpty()) {
             $isEmpty = false;
             break;
         }
     }
     parent::__construct($cs, $isEmpty);
     if (!$geometries) {
         return;
     }
     CoordinateSystem::check($this, ...$geometries);
     $containedGeometryType = $this->containedGeometryType();
     foreach ($geometries as $geometry) {
         if (!$geometry instanceof $containedGeometryType) {
             throw new UnexpectedGeometryException(sprintf('%s expects instance of %s, instance of %s given.', static::class, $containedGeometryType, get_class($geometry)));
         }
     }
     $this->geometries = $geometries;
 }
Exemple #7
0
 /**
  * Class constructor.
  *
  * The coordinate system of each of the curves must match the one of the CompoundCurve.
  *
  * @param CoordinateSystem $cs        The coordinate system of the CompoundCurve.
  * @param Curve            ...$curves The curves that compose the CompoundCurve.
  *
  * @throws EmptyGeometryException    If any of the input curves is empty.
  * @throws InvalidGeometryException  If the compound curve is not continuous.
  * @throws CoordinateSystemException If different coordinate systems are used.
  */
 public function __construct(CoordinateSystem $cs, Curve ...$curves)
 {
     parent::__construct($cs, !$curves);
     if (!$curves) {
         return;
     }
     CoordinateSystem::check($this, ...$curves);
     /** @var Curve|null $previousCurve */
     $previousCurve = null;
     foreach ($curves as $curve) {
         if ($previousCurve) {
             $endPoint = $previousCurve->endPoint();
             $startPoint = $curve->startPoint();
             if ($endPoint != $startPoint) {
                 // on purpose by-value comparison!
                 throw new InvalidGeometryException('Incontinuous compound curve.');
             }
         }
         $previousCurve = $curve;
     }
     $this->curves = $curves;
 }
Exemple #8
0
 /**
  * Returns whether this geometry has m coordinate values.
  *
  * @return boolean
  */
 public function isMeasured()
 {
     return $this->coordinateSystem->hasM();
 }
Exemple #9
0
 /**
  * @param WKBBuffer        $buffer
  * @param CoordinateSystem $cs
  *
  * @return TIN
  */
 private function readTIN(WKBBuffer $buffer, CoordinateSystem $cs)
 {
     $numPatches = $buffer->readUnsignedLong();
     $patches = [];
     for ($i = 0; $i < $numPatches; $i++) {
         $patches[] = $this->readGeometry($buffer, $cs->SRID());
     }
     return new TIN($cs, ...$patches);
 }
Exemple #10
0
 /**
  * Creates an empty Point with XYZM dimensionality.
  *
  * @param integer $srid An optional SRID.
  *
  * @return Point
  */
 public static function xyzmEmpty($srid = 0)
 {
     return new Point(CoordinateSystem::xyzm($srid));
 }
Exemple #11
0
 /**
  * @param WKTParser        $parser
  * @param CoordinateSystem $cs
  *
  * @return GeometryCollection
  */
 private function readGeometryCollectionText(WKTParser $parser, CoordinateSystem $cs)
 {
     $parser->matchOpener();
     $geometries = [];
     do {
         $geometries[] = $this->readGeometry($parser, $cs->SRID());
         $nextToken = $parser->getNextCloserOrComma();
     } while ($nextToken === ',');
     return new GeometryCollection($cs, ...$geometries);
 }