Beispiel #1
0
 /**
  * @dataProvider providerWrite
  *
  * @param string  $wkt       The WKT to read.
  * @param string  $wkb       The expected WKB output, hex-encoded.
  * @param integer $byteOrder The byte order to use.
  */
 public function testWrite($wkt, $wkb, $byteOrder)
 {
     $writer = new WKBWriter();
     $writer->setByteOrder($byteOrder);
     $reader = new WKTReader();
     $geometry = $reader->read($wkt);
     $output = $writer->write($geometry);
     $this->assertSame($wkb, bin2hex($output));
 }
Beispiel #2
0
 /**
  * Builds a Geometry from a WKT representation.
  *
  * If the resulting geometry is valid but is not an instance of the class this method is called on,
  * for example passing a Polygon WKT to Point::fromText(), an exception is thrown.
  *
  * @param string  $wkt  The Well-Known Text representation.
  * @param integer $srid The optional SRID to use.
  *
  * @return static
  *
  * @throws GeometryIOException         If the given string is not a valid WKT representation.
  * @throws CoordinateSystemException   If the WKT contains mixed coordinate systems.
  * @throws InvalidGeometryException    If the WKT represents an invalid geometry.
  * @throws UnexpectedGeometryException If the resulting geometry is not an instance of the current class.
  */
 public static function fromText($wkt, $srid = 0)
 {
     static $wktReader;
     if ($wktReader === null) {
         $wktReader = new WKTReader();
     }
     $geometry = $wktReader->read($wkt, $srid);
     if (!$geometry instanceof static) {
         throw UnexpectedGeometryException::unexpectedGeometryType(static::class, $geometry);
     }
     return $geometry;
 }