/** * 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); } }
/** * @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); }
/** * @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()); } } }
/** * @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)); }
/** * @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); }
/** * Loads the underlying geometry. * * @return void * * @throws GeometryIOException If the proxy data is not valid. * @throws CoordinateSystemException If the resulting geometry contains mixed coordinate systems. * @throws InvalidGeometryException If the resulting geometry is not valid. * @throws UnexpectedGeometryException If the resulting geometry is not an instance of the proxied class. */ private function load() { $this->proxyGeometry = $this->proxyIsBinary ? Point::fromBinary($this->proxyData, $this->proxySRID) : Point::fromText($this->proxyData, $this->proxySRID); }
/** * @expectedException \Brick\Geo\Exception\UnexpectedGeometryException */ public function testFromTextOnWrongSubclassThrowsException() { Point::fromText('LINESTRING (1 2, 3 4)'); }