-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add STDistanceSphere and Test to MySql #158
Open
reneszabo
wants to merge
1
commit into
creof:develop
Choose a base branch
from
reneszabo:master
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STDistanceSphere.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Copyright (C) 2012 Derek J. Lambert | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
namespace CrEOF\Spatial\ORM\Query\AST\Functions\MySql; | ||
|
||
use CrEOF\Spatial\ORM\Query\AST\Functions\AbstractSpatialDQLFunction; | ||
|
||
/** | ||
* ST_Distance_Sphere DQL function | ||
* | ||
* @author Rene Ramirez <[email protected]> | ||
* @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; | ||
} |
91 changes: 91 additions & 0 deletions
91
tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/MySql/STDistanceSphereTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/** | ||
* Copyright (C) 2015 Derek J. Lambert | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
namespace CrEOF\Spatial\Tests\ORM\Query\AST\Functions\PostgreSql; | ||
|
||
use CrEOF\Spatial\PHP\Types\Geography\Point as GeographyPoint; | ||
use CrEOF\Spatial\PHP\Types\Geometry\Point; | ||
use CrEOF\Spatial\Tests\Fixtures\PointEntity; | ||
use CrEOF\Spatial\Tests\Fixtures\GeographyEntity; | ||
use CrEOF\Spatial\Tests\OrmTestCase; | ||
use Doctrine\ORM\Query; | ||
|
||
/** | ||
* ST_Distance_Sphere DQL function tests | ||
* | ||
* @author Derek J. Lambert <[email protected]> | ||
* @license http://dlambert.mit-license.org MIT | ||
* | ||
* @group dql | ||
*/ | ||
class STDistanceSphereTest extends OrmTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
$this->usesEntity(self::POINT_ENTITY); | ||
$this->supportsPlatform('postgresql'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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]); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong namespace shoud be
namespace CrEOF\Spatial\Tests\ORM\Query\AST\Functions\MySql;