/** * {@inheritdoc} */ function load(ObjectManager $manager) { $point1 = new GeometryEntity(); $point1->setGeometry(Point::xy(0, 0)); $manager->persist($point1); $manager->flush(); }
/** * {@inheritdoc} */ public function coordinateSystem() { if ($this->proxyGeometry === null) { $this->load(); } return $this->proxyGeometry->coordinateSystem(); }
/** * {@inheritdoc} */ function load(ObjectManager $manager) { $point1 = Point::xy(0, 0); $point2 = Point::xy(1, 0); $point3 = Point::xy(1, 1); $lineString1 = new LineStringEntity(); $lineString1->setLineString(LineString::of($point1, $point2, $point3)); $manager->persist($lineString1); $manager->flush(); }
/** * {@inheritdoc} */ function load(ObjectManager $manager) { $point1 = Point::xy(0, 0); $point2 = Point::xy(1, 0); $point3 = Point::xy(1, 1); $multiPoint1 = new MultiPointEntity(); $multiPoint1->setMultiPoint(MultiPoint::of($point1, $point2, $point3)); $manager->persist($multiPoint1); $manager->flush(); }
/** * Tests Countable and Traversable interfaces. */ public function testInterfaces() { $point = Point::fromText('POINT (1 2)'); $lineString = LineString::fromText('LINESTRING (1 2, 3 4)'); $geometryCollection = GeometryCollection::of($point, $lineString); $this->assertInstanceOf(\Countable::class, $geometryCollection); $this->assertSame(2, count($geometryCollection)); $this->assertInstanceOf(\Traversable::class, $geometryCollection); $this->assertSame([$point, $lineString], iterator_to_array($geometryCollection)); }
/** * @dataProvider providerCreate * * @param string[] $pointsWKT The WKT of the Points that compose the CircularString. * @param boolean $is3D Whether the points have Z coordinates. * @param boolean $isMeasured Whether the points have M coordinates. * @param string $circularStringWKT The WKT of the expected CircularString. */ public function testCreate(array $pointsWKT, $is3D, $isMeasured, $circularStringWKT) { foreach ([0, 1] as $srid) { $instantiatePoint = function ($point) use($srid) { return Point::fromText($point, $srid); }; $cs = new CoordinateSystem($is3D, $isMeasured, $srid); $circularString = new CircularString($cs, ...array_map($instantiatePoint, $pointsWKT)); $this->assertWktEquals($circularString, $circularStringWKT, $srid); } }
/** * Creates a rectangle out of two 2D corner points. * * The result is a linear ring (closed and simple). * * @param Point $a * @param Point $b * * @return LineString * * @throws CoordinateSystemException If the points use different coordinate systems, or are not 2D. */ public static function rectangle(Point $a, Point $b) { $cs = $a->coordinateSystem(); if ($cs != $b->coordinateSystem()) { // by-value comparison. throw CoordinateSystemException::dimensionalityMix($a, $b); } if ($cs->coordinateDimension() != 2) { throw new CoordinateSystemException(__METHOD__ . ' expects 2D points.'); } $x1 = min($a->x(), $b->x()); $x2 = max($a->x(), $b->x()); $y1 = min($a->y(), $b->y()); $y2 = max($a->y(), $b->y()); $p1 = new Point($cs, $x1, $y1); $p2 = new Point($cs, $x2, $y1); $p3 = new Point($cs, $x2, $y2); $p4 = new Point($cs, $x1, $y2); return new LineString($cs, $p1, $p2, $p3, $p4, $p1); }
/** * {@inheritdoc} */ function load(ObjectManager $manager) { $point1 = Point::xy(0, 0); $point2 = Point::xy(1, 0); $point3 = Point::xy(1, 1); $point4 = Point::xy(0, 1); $point5 = Point::xy(0, 0); $ring = LineString::of($point1, $point2, $point3, $point4, $point5); $poly1 = new PolygonEntity(); $poly1->setPolygon(Polygon::of($ring)); $manager->persist($poly1); $manager->flush(); }
/** * @dataProvider providerEarthDistanceFunction * * @param string $pointA The WKT of the first point, with Lon/Lat coordinates. * @param string $pointB The WKT of the second point, with Lon/Lat coordinates. * @param float $expectedDistance The expected distance in meters. */ public function testEarthDistanceFunction($pointA, $pointB, $expectedDistance) { $pointA = Point::fromText($pointA, 4326); $pointB = Point::fromText($pointB, 4326); $em = $this->getEntityManager(); $em->beginTransaction(); $em->createQueryBuilder()->delete()->from(PointEntity::class, 'p')->getQuery()->execute(); $pointEntity = new PointEntity(); $pointEntity->setPoint($pointA); $em->persist($pointEntity); $em->flush($pointEntity); $actualDistance = $em->createQueryBuilder()->select('EarthDistance(p.point, :point)')->from(PointEntity::class, 'p')->setParameter('point', $pointB, 'point')->getQuery()->getSingleScalarResult(); $em->rollback(); $this->assertEquals($expectedDistance, $actualDistance, '', 100.0); }
/** * {@inheritdoc} */ function load(ObjectManager $manager) { $point1 = Point::xy(0, 0); $point2 = Point::xy(1, 0); $point3 = Point::xy(1, 1); $lineString1 = LineString::of($point1, $point2, $point3); $point4 = Point::xy(2, 2); $point5 = Point::xy(3, 2); $point6 = Point::xy(3, 3); $lineString2 = LineString::of($point4, $point5, $point6); $multilineString1 = new MultiLineStringEntity(); $multilineString1->setMultiLineString(MultiLineString::of($lineString1, $lineString2)); $manager->persist($multilineString1); $manager->flush(); }
/** * {@inheritdoc} */ function load(ObjectManager $manager) { $point1 = Point::xy(0, 0); $point2 = Point::xy(1, 0); $point3 = Point::xy(1, 1); $point4 = Point::xy(0, 1); $point5 = Point::xy(0, 0); $ring1 = LineString::of($point1, $point2, $point3, $point4, $point5); $poly1 = Polygon::of($ring1); $point6 = Point::xy(2, 2); $point7 = Point::xy(3, 2); $point8 = Point::xy(3, 3); $point9 = Point::xy(2, 3); $point10 = Point::xy(2, 2); $ring2 = LineString::of($point6, $point7, $point8, $point9, $point10); $poly2 = Polygon::of($ring2); $multiPoly1 = new MultiPolygonEntity(); $multiPoly1->setMultiPolygon(MultiPolygon::of($poly1, $poly2)); $manager->persist($multiPoly1); $manager->flush(); }
/** * @dataProvider providerProxy * * @param string $data * @param boolean $isBinary * @param boolean $is3D * @param boolean $isMeasured * @param array $coords */ public function testProxy($data, $isBinary, $is3D, $isMeasured, array $coords) { if ($isBinary) { $data = hex2bin($data); } $this->castToFloat($coords); $x = $coords ? $coords[0] : null; $y = $coords ? $coords[1] : null; $z = $coords && $is3D ? $coords[2] : null; $m = $coords && $isMeasured ? $coords[$is3D ? 3 : 2] : null; $spatialDimension = $is3D ? 3 : 2; $coordinateDimension = $spatialDimension + ($isMeasured ? 1 : 0); foreach ([0, 1] as $srid) { $pointProxy = new PointProxy($data, $isBinary, $srid); $this->assertInstanceOf(Point::class, $pointProxy); $this->assertSame($is3D, $pointProxy->is3D()); $this->assertSame($isMeasured, $pointProxy->is3D()); $this->assertSame(!$coords, $pointProxy->isEmpty()); $this->assertSame($x, $pointProxy->x()); $this->assertSame($y, $pointProxy->y()); $this->assertSame($z, $pointProxy->z()); $this->assertSame($m, $pointProxy->m()); $this->assertSame('Point', $pointProxy->geometryType()); $this->assertSame($coords, $pointProxy->toArray()); $this->assertSame($srid, $pointProxy->SRID()); $this->assertSame(0, $pointProxy->dimension()); $this->assertSame($spatialDimension, $pointProxy->spatialDimension()); $this->assertSame($coordinateDimension, $pointProxy->coordinateDimension()); $asText = $isBinary ? Point::fromBinary($data)->asText() : $data; $this->assertSame($asText, (string) $pointProxy); $this->assertSame($asText, $pointProxy->asText()); if ($coords) { $asBinary = $isBinary ? $data : Point::fromText($data)->asBinary(); $this->assertSame($asBinary, $pointProxy->asBinary()); } } }
/** * @expectedException \Brick\Geo\Exception\UnexpectedGeometryException */ public function testFromTextOnWrongSubclassThrowsException() { Point::fromText('LINESTRING (1 2, 3 4)'); }
/** * @return array */ public function providerWriteEmptyPointThrowsException() { return [[Point::xyEmpty()], [Point::xyzEmpty()], [Point::xymEmpty()], [Point::xyzmEmpty()]]; }
/** * @dataProvider providerToArrayAndInterfaces * * @param string $point The WKT of the point to test. * @param array $coordinates The expected coordinates. */ public function testToArrayAndInterfaces($point, array $coordinates) { $point = Point::fromText($point); $this->assertSame($coordinates, $point->toArray()); $this->assertSame($coordinates, iterator_to_array($point)); $this->assertSame(count($coordinates), count($point)); }
/** * @param Point $point * * @return string */ private function writePoint(Point $point) { $result = $point->x() . ' ' . $point->y(); if (null !== ($z = $point->z())) { $result .= ' ' . $z; } if (null !== ($m = $point->m())) { $result .= ' ' . $m; } return $result; }
/** * @param Point $point * * @return string * * @throws GeometryIOException */ private function packPoint(Point $point) { if ($point->isEmpty()) { throw new GeometryIOException('Empty points have no WKB representation.'); } $binary = $this->packDouble($point->x()) . $this->packDouble($point->y()); if (null !== ($z = $point->z())) { $binary .= $this->packDouble($z); } if (null !== ($m = $point->m())) { $binary .= $this->packDouble($m); } return $binary; }
/** * Creates a non-empty CircularString composed of the given points. * * @param Point $point1 The first point. * @param Point ...$pointN The subsequent points. * * @return CircularString * * @throws InvalidGeometryException If the number of points is invalid. * @throws CoordinateSystemException If the points use different coordinate systems. */ public static function of(Point $point1, Point ...$pointN) { return new CircularString($point1->coordinateSystem(), $point1, ...$pointN); }
/** * @dataProvider providerRectangleWithInvalidPoints * @expectedException \Brick\Geo\Exception\CoordinateSystemException * * @param string $point1 * @param string $point2 * @param int $srid1 * @param int $srid2 */ public function testRectangleWithInvalidPoints($point1, $point2, $srid1 = 0, $srid2 = 0) { $point1 = Point::fromText($point1, $srid1); $point2 = Point::fromText($point2, $srid2); LineString::rectangle($point1, $point2); }
/** * @param array $coords The expected coordinates of the Point as returned by toArray(). * @param boolean $is3D Whether the Point is expected to contain a Z coordinate. * @param boolean $isMeasured Whether the Point is expected to contain a M coordinate. * @param integer $srid The expected SRID. * @param Point $point The Point to test. */ protected final function assertPointEquals(array $coords, $is3D, $isMeasured, $srid, Point $point) { $this->castToFloat($coords); $this->assertSame($coords, $point->toArray()); $this->assertSame($is3D, $point->is3D()); $this->assertSame($isMeasured, $point->isMeasured()); $this->assertSame($srid, $point->SRID()); }