예제 #1
0
파일: GeometryProxy.php 프로젝트: brick/geo
 /**
  * {@inheritdoc}
  */
 public function isEmpty()
 {
     if ($this->proxyGeometry === null) {
         $this->load();
     }
     return $this->proxyGeometry->isEmpty();
 }
예제 #2
0
 /**
  * @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 . ')';
 }
예제 #3
0
파일: GEOSEngine.php 프로젝트: brick/geo
 /**
  * @param Geometry $geometry
  *
  * @return \GEOSGeometry
  */
 private function toGEOS(Geometry $geometry)
 {
     if ($geometry->isEmpty()) {
         $geosGeometry = $this->wktReader->read($geometry->asText());
         $geosGeometry->setSRID($geometry->SRID());
         return $geosGeometry;
     }
     if ($this->hasBinaryReadWrite) {
         return $this->wkbReader->read($this->ewkbWriter->write($geometry));
     }
     return $this->wkbReader->readHEX(bin2hex($this->ewkbWriter->write($geometry)));
 }
예제 #4
0
 /**
  * @param Geometry $geometry
  */
 protected final function skipIfUnsupportedGeometry(Geometry $geometry)
 {
     if ($geometry->is3D() || $geometry->isMeasured()) {
         if ($this->isMySQL() || $this->isMariaDB()) {
             // MySQL and MariaDB do not support Z and M coordinates.
             $this->setExpectedException(GeometryEngineException::class);
         }
     }
     if ($geometry->isMeasured()) {
         if ($this->isGEOS()) {
             $this->markTestSkipped('GEOS does not support M coordinates in WKB.');
         }
     }
     if ($geometry->isEmpty() && !$geometry instanceof GeometryCollection) {
         if ($this->isMySQL() || $this->isMariaDB()) {
             // MySQL and MariaDB do not correctly handle empty geometries, apart from collections.
             $this->setExpectedException(GeometryEngineException::class);
         }
         if ($this->isSpatiaLite()) {
             $this->markTestSkipped('SpatiaLite does not correctly handle empty geometries.');
         }
     }
     if ($geometry instanceof CircularString || $geometry instanceof CompoundCurve || $geometry instanceof CurvePolygon) {
         if ($this->isGEOS() || $this->isSpatiaLite() || $this->isMySQL() || $this->isMariaDB()) {
             // GEOS, SpatiaLite, MySQL and MariaDB do not support these geometries.
             // Only PostGIS currently supports these.
             $this->setExpectedException(GeometryEngineException::class);
         }
     }
 }