From c2894a0800f7812b8c0e257f1298a9da29a32fdc Mon Sep 17 00:00:00 2001 From: Rene Ramirez Date: Thu, 9 Jun 2016 12:56:55 -0400 Subject: [PATCH] add STDistanceSphere and Test to MySql --- .../AST/Functions/MySql/STDistanceSphere.php | 43 +++++++++ .../Functions/MySql/STDistanceSphereTest.php | 91 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php create mode 100644 tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php new file mode 100644 index 00000000..2a5eb9d1 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php @@ -0,0 +1,43 @@ + + * @license http://dlambert.mit-license.org MIT + */ +class STDistanceSphere extends AbstractSpatialDQLFunction +{ + protected $platforms = array('mysql'); + + protected $functionName = 'ST_Distance_Sphere'; + + protected $minGeomExpr = 2; + + protected $maxGeomExpr = 2; +} diff --git a/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php new file mode 100644 index 00000000..09afa0e5 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php @@ -0,0 +1,91 @@ + + * @license http://dlambert.mit-license.org MIT + * + * @group dql + */ +class STDistanceSphereTest extends OrmTestCase +{ + protected function setUp() + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * @group geometry + */ + public function testSelectSTDistanceSphereGeometry() + { + $newYork = new Point(-73.938611, 40.664167); + $losAngles = new Point(-118.2430, 34.0522); + $dallas = new Point(-96.803889, 32.782778); + + $entity1 = new PointEntity(); + + $entity1->setPoint($newYork); + $this->getEntityManager()->persist($entity1); + + $entity2 = new PointEntity(); + + $entity2->setPoint($losAngles); + $this->getEntityManager()->persist($entity2); + + $entity3 = new PointEntity(); + + $entity3->setPoint($dallas); + $this->getEntityManager()->persist($entity3); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery('SELECT p, ST_Distance_Sphere(p.point, ST_GeomFromText(:p1)) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p'); + + $query->setParameter('p1', 'POINT(-89.4 43.066667)', 'string'); + + $result = $query->getResult(); + + $this->assertCount(3, $result); + $this->assertEquals($entity1, $result[0][0]); + $this->assertEquals(1305895.94823465, $result[0][1]); + $this->assertEquals($entity2, $result[1][0]); + $this->assertEquals(2684082.08249337, $result[1][1]); + $this->assertEquals($entity3, $result[2][0]); + $this->assertEquals(1313754.60684762, $result[2][1]); + } +}