예제 #1
0
 /**
  * @param WKBBuffer $buffer
  * @param integer   $srid
  *
  * @return Geometry
  *
  * @throws GeometryIOException
  */
 protected function readGeometry(WKBBuffer $buffer, $srid)
 {
     $buffer->readByteOrder();
     $this->readGeometryHeader($buffer, $geometryType, $hasZ, $hasM, $srid);
     $cs = new CoordinateSystem($hasZ, $hasM, $srid);
     switch ($geometryType) {
         case Geometry::POINT:
             return $this->readPoint($buffer, $cs);
         case Geometry::LINESTRING:
             return $this->readLineString($buffer, $cs);
         case Geometry::CIRCULARSTRING:
             return $this->readCircularString($buffer, $cs);
         case Geometry::COMPOUNDCURVE:
             return $this->readCompoundCurve($buffer, $cs);
         case Geometry::POLYGON:
             return $this->readPolygon($buffer, $cs);
         case Geometry::CURVEPOLYGON:
             return $this->readCurvePolygon($buffer, $cs);
         case Geometry::MULTIPOINT:
             return $this->readMultiPoint($buffer, $cs);
         case Geometry::MULTILINESTRING:
             return $this->readMultiLineString($buffer, $cs);
         case Geometry::MULTIPOLYGON:
             return $this->readMultiPolygon($buffer, $cs);
         case Geometry::GEOMETRYCOLLECTION:
             return $this->readGeometryCollection($buffer, $cs);
         case Geometry::POLYHEDRALSURFACE:
             return $this->readPolyhedralSurface($buffer, $cs);
         case Geometry::TIN:
             return $this->readTIN($buffer, $cs);
         case Geometry::TRIANGLE:
             return $this->readTriangle($buffer, $cs);
     }
     throw GeometryIOException::unsupportedGeometryType($geometryType);
 }
예제 #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
 /**
  * @param Geometry $geometry The geometry export as WKB write.
  * @param boolean  $outer    False if the geometry is nested in another geometry, true otherwise.
  *
  * @return string The WKB representation of the given geometry.
  *
  * @throws GeometryIOException If the given geometry cannot be exported as WKT.
  */
 protected function doWrite(Geometry $geometry, $outer)
 {
     if ($geometry instanceof Point) {
         return $this->writePoint($geometry, $outer);
     }
     if ($geometry instanceof LineString) {
         return $this->writeCurve($geometry, $outer);
     }
     if ($geometry instanceof CircularString) {
         return $this->writeCurve($geometry, $outer);
     }
     if ($geometry instanceof Polygon) {
         return $this->writePolygon($geometry, $outer);
     }
     if ($geometry instanceof CompoundCurve) {
         return $this->writeComposedGeometry($geometry, $outer);
     }
     if ($geometry instanceof CurvePolygon) {
         return $this->writeComposedGeometry($geometry, $outer);
     }
     if ($geometry instanceof GeometryCollection) {
         return $this->writeComposedGeometry($geometry, $outer);
     }
     if ($geometry instanceof PolyhedralSurface) {
         return $this->writeComposedGeometry($geometry, $outer);
     }
     throw GeometryIOException::unsupportedGeometryType($geometry->geometryType());
 }