/** * {@inheritdoc} */ public function coordinateSystem() { if ($this->proxyGeometry === null) { $this->load(); } return $this->proxyGeometry->coordinateSystem(); }
/** * @param Geometry $geometry The geometry to export as WKT. * * @return string The WKT representation of the given geometry. * * @throws GeometryIOException If the given geometry cannot be exported as WKT. */ protected function doWrite(Geometry $geometry) { $type = strtoupper($geometry->geometryType()); $cs = $geometry->coordinateSystem(); $hasZ = $cs->hasZ(); $hasM = $cs->hasM(); $dimensionality = ''; if ($hasZ || $hasM) { $dimensionality .= ' '; if ($hasZ) { $dimensionality .= 'Z'; } if ($hasM) { $dimensionality .= 'M'; } } if ($geometry instanceof GeometryCollection) { $isEmpty = $geometry->numGeometries() === 0; } else { $isEmpty = $geometry->isEmpty(); } if ($isEmpty) { return $type . $dimensionality . ' EMPTY'; } if ($geometry instanceof Point) { $data = $this->writePoint($geometry); } elseif ($geometry instanceof LineString) { $data = $this->writeLineString($geometry); } elseif ($geometry instanceof CircularString) { $data = $this->writeCircularString($geometry); } elseif ($geometry instanceof CompoundCurve) { $data = $this->writeCompoundCurve($geometry); } elseif ($geometry instanceof Triangle) { $data = $this->writePolygon($geometry); } elseif ($geometry instanceof Polygon) { $data = $this->writePolygon($geometry); } elseif ($geometry instanceof CurvePolygon) { $data = $this->writeCurvePolygon($geometry); } elseif ($geometry instanceof MultiPoint) { $data = $this->writeMultiPoint($geometry); } elseif ($geometry instanceof MultiLineString) { $data = $this->writeMultiLineString($geometry); } elseif ($geometry instanceof MultiPolygon) { $data = $this->writeMultiPolygon($geometry); } elseif ($geometry instanceof GeometryCollection) { $data = $this->writeGeometryCollection($geometry); } elseif ($geometry instanceof TIN) { $data = $this->writePolyhedralSurface($geometry); } elseif ($geometry instanceof PolyhedralSurface) { $data = $this->writePolyhedralSurface($geometry); } else { throw GeometryIOException::unsupportedGeometryType($geometry->geometryType()); } return $type . $dimensionality . $this->prettyPrintSpace . '(' . $data . ')'; }
/** * {@inheritdoc} */ protected function packHeader(Geometry $geometry, $outer) { $geometryType = $geometry->geometryTypeBinary(); $cs = $geometry->coordinateSystem(); if ($cs->hasZ()) { $geometryType += 1000; } if ($cs->hasM()) { $geometryType += 2000; } return $this->packUnsignedInteger($geometryType); }
/** * {@inheritdoc} */ protected function packHeader(Geometry $geometry, $outer) { $geometryType = $geometry->geometryTypeBinary(); $cs = $geometry->coordinateSystem(); if ($cs->hasZ()) { $geometryType |= EWKBTools::Z; } if ($cs->hasM()) { $geometryType |= EWKBTools::M; } $srid = $cs->SRID(); if ($srid !== 0 && $outer) { $geometryType |= EWKBTools::S; } $header = $this->packUnsignedInteger($geometryType); if ($srid !== 0 && $outer) { $header .= $this->packUnsignedInteger($srid); } return $header; }
/** * Creates a non-empty GeometryCollection composed of the given geometries. * * @param Geometry $geometry1 The first geometry. * @param Geometry ...$geometryN The subsequent geometries, if any. * * @return static * * @throws CoordinateSystemException If the geometries use different coordinate systems. * @throws UnexpectedGeometryException If a geometry is not a valid type for a sub-class of GeometryCollection. */ public static function of(Geometry $geometry1, Geometry ...$geometryN) { return new static($geometry1->coordinateSystem(), $geometry1, ...$geometryN); }
/** * @param Geometry $reference * @param Geometry $culprit * * @return CoordinateSystemException */ public static function dimensionalityMix(Geometry $reference, Geometry $culprit) { return new CoordinateSystemException(sprintf('Dimensionality mix: %s %s cannot contain %s %s.', $reference->geometryType(), $reference->coordinateSystem()->coordinateName(), $culprit->geometryType(), $culprit->coordinateSystem()->coordinateName())); }
/** * @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); } }