From 0cdad1072842d3968b93afece14fa3de567846ee Mon Sep 17 00:00:00 2001 From: Dragos Protung Date: Wed, 23 Dec 2015 15:46:57 +0100 Subject: [PATCH] Added support for PostgreSQL ST_MakeEnvelope --- CHANGELOG.md | 1 + .../Functions/PostgreSql/STMakeEnvelope.php | 49 +++++++++++ .../PostgreSql/STMakeEnvelopeTest.php | 86 +++++++++++++++++++ tests/CrEOF/Spatial/Tests/OrmTestCase.php | 1 + 4 files changed, 137 insertions(+) create mode 100644 lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelope.php create mode 100644 tests/CrEOF/Spatial/Tests/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelopeTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 031270b4..486f18da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added +- Added support for PostgreSql ST_MakeEnvelope function. ### Changed ### Removed diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelope.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelope.php new file mode 100644 index 00000000..e1854f45 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STMakeEnvelope.php @@ -0,0 +1,49 @@ +usesEntity(self::POLYGON_ENTITY); + $this->supportsPlatform('postgresql'); + + parent::setUp(); + } + + /** + * @group geometry + */ + public function testSelectSTMakeEnvelope() + { + $entity = new PolygonEntity(); + $rings = array( + new LineString( + array( + new Point(0, 0), + new Point(10, 0), + new Point(10, 10), + new Point(0, 10), + new Point(0, 0), + ) + ), + ); + + $entity->setPolygon(new Polygon($rings)); + $this->getEntityManager()->persist($entity); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + $query = $this->getEntityManager()->createQuery( + 'SELECT ST_AsText(ST_MakeEnvelope(5,5, 10, 10)) FROM CrEOF\Spatial\Tests\Fixtures\PolygonEntity p' + ); + $result = $query->getResult(); + + $expected = array( + array(1 => 'POLYGON((5 5,5 10,10 10,10 5,5 5))'), + ); + + $this->assertEquals($expected, $result); + } +} diff --git a/tests/CrEOF/Spatial/Tests/OrmTestCase.php b/tests/CrEOF/Spatial/Tests/OrmTestCase.php index eb95a771..dd3f99f0 100644 --- a/tests/CrEOF/Spatial/Tests/OrmTestCase.php +++ b/tests/CrEOF/Spatial/Tests/OrmTestCase.php @@ -332,6 +332,7 @@ protected function setUpFunctions() $configuration->addCustomStringFunction('st_geomfromtext', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STGeomFromText'); $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_startpoint', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STStartPoint'); $configuration->addCustomStringFunction('st_summary', 'CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STSummary'); }