Skip to content

Commit 065686e

Browse files
authored
Merge pull request #168 from dragosprotung/stcollect
Added support for ST_Collect function
2 parents caa84a2 + 23e47b9 commit 065686e

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

INSTALL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ doctrine:
2727
string_functions:
2828
# for postgresql
2929
geometry: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\Geometry
30+
stcollect: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCollect
3031
numeric_functions:
3132
# for postgresql
3233
starea: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright (C) 2016 Derek J. Lambert
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
namespace CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql;
25+
26+
use CrEOF\Spatial\ORM\Query\AST\Functions\AbstractSpatialDQLFunction;
27+
28+
/**
29+
* ST_Collect DQL function
30+
*
31+
* @author Derek J. Lambert <[email protected]>
32+
* @license http://dlambert.mit-license.org MIT
33+
*/
34+
class STCollect extends AbstractSpatialDQLFunction
35+
{
36+
protected $platforms = array('postgresql');
37+
38+
protected $functionName = 'ST_Collect';
39+
40+
protected $minGeomExpr = 1;
41+
42+
protected $maxGeomExpr = 2;
43+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright (C) 2016 Derek J. Lambert
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
namespace CrEOF\Spatial\Tests\ORM\Query\AST\Functions\PostgreSql;
25+
26+
use CrEOF\Spatial\PHP\Types\Geometry\Point;
27+
use CrEOF\Spatial\Tests\Fixtures\PointEntity;
28+
use CrEOF\Spatial\Tests\OrmTestCase;
29+
30+
/**
31+
* ST_Collect DQL function tests
32+
*
33+
* @author Derek J. Lambert <[email protected]>
34+
* @license http://dlambert.mit-license.org MIT
35+
*
36+
* @group dql
37+
*/
38+
class STCollectTest extends OrmTestCase
39+
{
40+
protected function setUp()
41+
{
42+
$this->usesEntity(self::POINT_ENTITY);
43+
$this->supportsPlatform('postgresql');
44+
45+
parent::setUp();
46+
}
47+
48+
/**
49+
* @group geometry
50+
*/
51+
public function testSelectSTCollect()
52+
{
53+
$entity = new PointEntity();
54+
$entity->setPoint(new Point(1, 2));
55+
$this->getEntityManager()->persist($entity);
56+
57+
$this->getEntityManager()->flush();
58+
$this->getEntityManager()->clear();
59+
60+
$query = $this->getEntityManager()->createQuery('SELECT ST_AsText(ST_Collect(geometry(p.point), ST_GeomFromText(\'POINT(-2 3)\'))) FROM CrEOF\Spatial\Tests\Fixtures\PointEntity p');
61+
$result = $query->getResult();
62+
63+
$expected = array(
64+
array(1 => 'MULTIPOINT(1 2,-2 3)'),
65+
);
66+
67+
$this->assertEquals($expected, $result);
68+
}
69+
}

tests/CrEOF/Spatial/Tests/OrmTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ protected function setUpFunctions()
319319
$configuration->addCustomNumericFunction('st_area', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea');
320320
$configuration->addCustomStringFunction('st_centroid', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCentroid');
321321
$configuration->addCustomStringFunction('st_closestpoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STClosestPoint');
322+
$configuration->addCustomStringFunction('st_collect', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCollect');
322323
$configuration->addCustomNumericFunction('st_contains', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContains');
323324
$configuration->addCustomNumericFunction('st_containsproperly', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContainsProperly');
324325
$configuration->addCustomNumericFunction('st_covers', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STCovers');

0 commit comments

Comments
 (0)