diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php index 04e6a561..06fbaffe 100644 --- a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistance.php @@ -32,11 +32,10 @@ * @author luca capra * @license http://dlambert.mit-license.org MIT */ -class STDistance extends AbstractSpatialDQLFunction { - +class STDistance extends AbstractSpatialDQLFunction +{ protected $platforms = array('mysql'); protected $functionName = 'ST_Distance'; protected $minGeomExpr = 2; protected $maxGeomExpr = 2; - } 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..8f11089e --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php @@ -0,0 +1,41 @@ + + * @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..d6fa8662 --- /dev/null +++ b/tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php @@ -0,0 +1,95 @@ + + * @license http://dlambert.mit-license.org MIT + * + * @group dql + */ +class STDistanceSphereTest extends OrmTestCase +{ + protected function setUp() + { + $this->usesEntity(self::POINT_ENTITY); + $this->supportsPlatform('mysql'); + + 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]); + } +}