Skip to content

Commit

Permalink
Merge pull request #172 from dragosprotung/stoverlaps
Browse files Browse the repository at this point in the history
Implemented ST_Overlaps
  • Loading branch information
sadortun committed Jan 6, 2017
2 parents dc28144 + 3e040af commit f354743
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 1 deletion.
3 changes: 2 additions & 1 deletion INSTALL.md
Expand Up @@ -27,8 +27,10 @@ doctrine:
string_functions:
# for postgresql
geometry: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\Geometry
stbuffer: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STBuffer
stcollect: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCollect
stsnaptogrid: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSnapToGrid
stoverlaps: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STOverlaps
numeric_functions:
# for postgresql
starea: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea
Expand All @@ -37,7 +39,6 @@ doctrine:
stastext: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsText
stazimuth: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAzimuth
stboundary: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STBoundary
STBuffer: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STBuffer
stcentroid: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCentroid
stclosestpoint: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STClosestPoint
stcontains: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContains
Expand Down
@@ -0,0 +1,44 @@
<?php

/**
* Copyright (C) 2017 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\PostgreSql;

use CrEOF\Spatial\ORM\Query\AST\Functions\AbstractSpatialDQLFunction;

/**
* ST_Overlaps DQL function.
*
* @author Dragos Protung
* @license http://mit-license.org MIT
*/
class STOverlaps extends AbstractSpatialDQLFunction
{
protected $platforms = array('postgresql');

protected $functionName = 'ST_Overlaps';

protected $minGeomExpr = 2;

protected $maxGeomExpr = 2;
}
@@ -0,0 +1,94 @@
<?php

/**
* Copyright (C) 2017 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\Geometry\LineString;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use CrEOF\Spatial\PHP\Types\Geometry\Polygon;
use CrEOF\Spatial\Tests\Fixtures\PolygonEntity;
use CrEOF\Spatial\Tests\OrmTestCase;

/**
* ST_Overlaps DQL function tests
*
* @author Dragos Protung
* @license http://dlambert.mit-license.org MIT
*
* @group dql
*/
class STOverlapsTest extends OrmTestCase
{
protected function setUp()
{
$this->usesEntity(self::POLYGON_ENTITY);
$this->supportsPlatform('postgresql');

parent::setUp();
}

/**
* @group geometry
*/
public function testSelectSTMakeEnvelope()
{
$lineString1 = new LineString(array(
new Point(0, 0),
new Point(2, 0),
new Point(2, 2),
new Point(0, 2),
new Point(0, 0)
));
$lineString2 = new LineString(array(
new Point(2, 2),
new Point(7, 2),
new Point(7, 7),
new Point(2, 7),
new Point(2, 2)
));
$entity1 = new PolygonEntity();

$entity1->setPolygon(new Polygon(array($lineString1)));
$this->getEntityManager()->persist($entity1);

$entity2 = new PolygonEntity();

$entity2->setPolygon(new Polygon(array($lineString2)));
$this->getEntityManager()->persist($entity2);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();

$query = $this->getEntityManager()->createQuery(
'SELECT p as point, ST_Overlaps(p.polygon, ST_Buffer(ST_GeomFromText(:p1), 3)) as overlap FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p'
);
$query->setParameter('p1', 'POINT(0 0)', 'string');
$result = $query->getResult();

$this->assertCount(2, $result);
$this->assertEquals($entity1, $result[0]['point']);
$this->assertFalse($result[0]['overlap']);
$this->assertEquals($entity2, $result[1]['point']);
$this->assertTrue($result[1]['overlap']);
}
}
2 changes: 2 additions & 0 deletions tests/CrEOF/Spatial/Tests/OrmTestCase.php
Expand Up @@ -317,6 +317,7 @@ protected function setUpFunctions()
$configuration->addCustomStringFunction('st_asbinary', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsBinary');
$configuration->addCustomStringFunction('st_astext', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STAsText');
$configuration->addCustomNumericFunction('st_area', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea');
$configuration->addCustomNumericFunction('st_buffer', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STBuffer');
$configuration->addCustomStringFunction('st_centroid', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCentroid');
$configuration->addCustomStringFunction('st_closestpoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STClosestPoint');
$configuration->addCustomStringFunction('st_collect', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCollect');
Expand All @@ -335,6 +336,7 @@ protected function setUpFunctions()
$configuration->addCustomNumericFunction('st_length', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLength');
$configuration->addCustomNumericFunction('st_linecrossingdirection', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STLineCrossingDirection');
$configuration->addCustomStringFunction('st_makeenvelope', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STMakeEnvelope');
$configuration->addCustomStringFunction('st_overlaps', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STOverlaps');
$configuration->addCustomStringFunction('st_snaptogrid', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSnapToGrid');
$configuration->addCustomStringFunction('st_startpoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STStartPoint');
$configuration->addCustomStringFunction('st_summary', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSummary');
Expand Down

0 comments on commit f354743

Please sign in to comment.