Ejemplo n.º 1
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 . ')';
 }