Пример #1
0
 /**
  * Creates a rectangle out of two 2D corner points.
  *
  * The result is a linear ring (closed and simple).
  *
  * @param Point $a
  * @param Point $b
  *
  * @return LineString
  *
  * @throws CoordinateSystemException If the points use different coordinate systems, or are not 2D.
  */
 public static function rectangle(Point $a, Point $b)
 {
     $cs = $a->coordinateSystem();
     if ($cs != $b->coordinateSystem()) {
         // by-value comparison.
         throw CoordinateSystemException::dimensionalityMix($a, $b);
     }
     if ($cs->coordinateDimension() != 2) {
         throw new CoordinateSystemException(__METHOD__ . ' expects 2D points.');
     }
     $x1 = min($a->x(), $b->x());
     $x2 = max($a->x(), $b->x());
     $y1 = min($a->y(), $b->y());
     $y2 = max($a->y(), $b->y());
     $p1 = new Point($cs, $x1, $y1);
     $p2 = new Point($cs, $x2, $y1);
     $p3 = new Point($cs, $x2, $y2);
     $p4 = new Point($cs, $x1, $y2);
     return new LineString($cs, $p1, $p2, $p3, $p4, $p1);
 }
Пример #2
0
 /**
  * @param Geometry    $reference  The geometry holding the reference coordinate system.
  * @param Geometry ...$geometries The geometries to check against this coordinate system.
  *
  * @return void
  *
  * @throws CoordinateSystemException If the coordinate systems differ.
  */
 public static function check(Geometry $reference, Geometry ...$geometries)
 {
     $referenceCS = $reference->coordinateSystem();
     foreach ($geometries as $geometry) {
         $geometryCS = $geometry->coordinateSystem();
         if ($geometryCS == $referenceCS) {
             // by-value comparison.
             continue;
         }
         if ($geometryCS->srid !== $referenceCS->srid) {
             throw CoordinateSystemException::sridMix($reference, $geometry);
         }
         throw CoordinateSystemException::dimensionalityMix($reference, $geometry);
     }
 }