Example #1
0
 /**
  * @group geometry
  */
 public function testTypeWrappingSelect()
 {
     $lineString = new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0)));
     $entity = new PolygonEntity();
     $entity->setPolygon(new Polygon(array($lineString)));
     $this->getEntityManager()->persist($entity);
     $this->getEntityManager()->flush();
     $this->getEntityManager()->clear();
     $dql = 'SELECT p, %s(p.polygon, :geometry) FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p';
     switch ($this->getPlatform()->getName()) {
         case 'postgresql':
             $function = 'ST_Contains';
             break;
         case 'mysql':
             $function = 'Contains';
             break;
         default:
             throw UnsupportedPlatformException::unsupportedPlatform($this->getPlatform()->getName());
     }
     $dql = sprintf($dql, $function);
     $query = $this->getEntityManager()->createQuery($dql);
     $query->setParameter('geometry', new Point(2, 2), 'point');
     $query->processParameterValue('geometry');
     $result = $query->getSQL();
     $parameter = '?';
     if (Version::compare('2.5') <= 0) {
         $parameter = Type::getType('point')->convertToDatabaseValueSQL($parameter, $this->getPlatform());
     }
     $regex = preg_quote(sprintf('/.polygon, %s)/', $parameter));
     $this->assertRegExp($regex, $result);
 }
Example #2
0
 /**
  * @group geometry
  */
 public function testContainsWhereParameter()
 {
     $lineString1 = new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0)));
     $lineString2 = new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5)));
     $entity1 = new PolygonEntity();
     $entity1->setPolygon(new Polygon(array($lineString1)));
     $this->getEntityManager()->persist($entity1);
     $entity2 = new PolygonEntity();
     $entity2->setPolygon(new Polygon(array($lineString1, $lineString2)));
     $this->getEntityManager()->persist($entity2);
     $this->getEntityManager()->flush();
     $this->getEntityManager()->clear();
     $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE Contains(p.polygon, GeomFromText(:p1)) = 1');
     $query->setParameter('p1', 'POINT(6 6)', 'string');
     $result = $query->getResult();
     $this->assertCount(2, $result);
     $this->assertEquals($entity1, $result[0]);
     $this->assertEquals($entity2, $result[1]);
     $this->getEntityManager()->clear();
     $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE Contains(p.polygon, GeomFromText(:p1)) = 1');
     $query->setParameter('p1', 'POINT(2 2)', 'string');
     $result = $query->getResult();
     $this->assertCount(2, $result);
     $this->assertEquals($entity1, $result[0]);
     $this->assertEquals($entity2, $result[1]);
 }
 public function testSTContainsWhereParameter()
 {
     if ($this->getPlatform()->getName() == 'mysql') {
         $this->markTestSkipped('Function not supported on mssql.');
     }
     $lineString1 = new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0)));
     $lineString2 = new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5)));
     $entity1 = new PolygonEntity();
     $entity1->setPolygon(new Polygon(array($lineString1)));
     $this->_em->persist($entity1);
     $entity2 = new PolygonEntity();
     $entity2->setPolygon(new Polygon(array($lineString1, $lineString2)));
     $this->_em->persist($entity2);
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE ST_Contains(p.polygon, ST_GeomFromText(:p1)) = true');
     $query->setParameter('p1', new Point(6, 6), 'point');
     $result = $query->getResult();
     $this->assertCount(1, $result);
     $this->assertEquals($entity1, $result[0]);
     $this->_em->clear();
     $query = $this->_em->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE ST_Contains(p.polygon, ST_GeomFromText(:p1)) = true');
     $query->setParameter('p1', new Point(2, 2), 'point');
     $result = $query->getResult();
     $this->assertCount(2, $result);
     $this->assertEquals($entity1, $result[0]);
     $this->assertEquals($entity2, $result[1]);
 }
 public function testFindByPolygon()
 {
     $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 = new PolygonEntity();
     $entity->setPolygon(new Polygon($rings));
     $this->_em->persist($entity);
     $this->_em->flush();
     $this->_em->clear();
     $result = $this->_em->getRepository(self::POLYGON_ENTITY)->findByPolygon(new Polygon($rings));
     $this->assertEquals($entity, $result[0]);
 }
 /**
  * @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);
 }
 /**
  * @group geometry
  */
 public function testSTEnvelopeWhereParameter()
 {
     $entity1 = new PolygonEntity();
     $rings1 = array(new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0))), new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5))));
     $entity1->setPolygon(new Polygon($rings1));
     $this->getEntityManager()->persist($entity1);
     $entity2 = new PolygonEntity();
     $rings2 = array(new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5))));
     $entity2->setPolygon(new Polygon($rings2));
     $this->getEntityManager()->persist($entity2);
     $this->getEntityManager()->flush();
     $this->getEntityManager()->clear();
     $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE ST_Envelope(p.polygon) = ST_GeomFromText(:p1)');
     $query->setParameter('p1', 'POLYGON((0 0,10 0,10 10,0 10,0 0))', 'string');
     $result = $query->getResult();
     $this->assertCount(1, $result);
     $this->assertEquals($entity1, $result[0]);
 }
 /**
  * @group geometry
  */
 public function testSTCoveredByWhereParameter()
 {
     $lineString1 = new LineString(array(new Point(6, 6), new Point(10, 6), new Point(10, 10), new Point(6, 10), new Point(6, 6)));
     $lineString2 = new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5)));
     $entity1 = new PolygonEntity();
     $entity1->setPolygon(new Polygon(array($lineString1)));
     $this->_em->persist($entity1);
     $entity2 = new PolygonEntity();
     $entity2->setPolygon(new Polygon(array($lineString2)));
     $this->_em->persist($entity2);
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE ST_CoveredBy(p.polygon, ST_GeomFromText(:p1)) = true');
     $query->setParameter('p1', new Polygon(array($lineString2)), 'polygon');
     $result = $query->getResult();
     $this->assertCount(1, $result);
     $this->assertEquals($entity2, $result[0]);
 }
 /**
  * @group geometry
  */
 public function testSTContainsProperlyWhereParameter()
 {
     $lineString1 = new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0)));
     $lineString2 = new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5)));
     $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 FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE ST_ContainsProperly(p.polygon, ST_GeomFromText(:p1)) = true');
     $query->setParameter('p1', 'LINESTRING(5 5,7 5,7 7,5 7,5 5)', 'string');
     $result = $query->getResult();
     $this->assertCount(1, $result);
     $this->assertEquals($entity1, $result[0]);
 }
 /**
  * @group geometry
  */
 public function testSelectSTCentroid()
 {
     $lineString1 = new LineString(array(new Point(6, 6), new Point(10, 6), new Point(10, 10), new Point(6, 10), new Point(6, 6)));
     $lineString2 = new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5)));
     $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, ST_AsText(ST_Centroid(p.polygon)) FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p');
     $result = $query->getResult();
     $this->assertCount(2, $result);
     $this->assertEquals($entity1, $result[0][0]);
     $this->assertEquals('POINT(8 8)', $result[0][1]);
     $this->assertEquals($entity2, $result[1][0]);
     $this->assertEquals('POINT(6 6)', $result[1][1]);
 }
 /**
  * @group geometry
  */
 public function testSelectSTClosestPoint()
 {
     $ring1 = new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0)));
     $ring2 = new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5)));
     $entity1 = new PolygonEntity();
     $entity1->setPolygon(new Polygon(array($ring1)));
     $this->getEntityManager()->persist($entity1);
     $entity2 = new PolygonEntity();
     $entity2->setPolygon(new Polygon(array($ring2)));
     $this->getEntityManager()->persist($entity2);
     $this->getEntityManager()->flush();
     $this->getEntityManager()->clear();
     $query = $this->getEntityManager()->createQuery('SELECT p, ST_AsText(ST_ClosestPoint(p.polygon, ST_GeomFromText(:p1))) FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p');
     $query->setParameter('p1', 'POINT(2 2)', 'string');
     $result = $query->getResult();
     $this->assertCount(2, $result);
     $this->assertEquals($entity1, $result[0][0]);
     $this->assertEquals('POINT(2 2)', $result[0][1]);
     $this->assertEquals($entity2, $result[1][0]);
     $this->assertEquals('POINT(5 5)', $result[1][1]);
 }
 public function testSelectSTCentroid()
 {
     if ($this->getPlatform()->getName() == 'mysql') {
         $this->markTestSkipped('Function not supported on mssql.');
     }
     $lineString1 = new LineString(array(new Point(6, 6), new Point(10, 6), new Point(10, 10), new Point(6, 10), new Point(6, 6)));
     $lineString2 = new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5)));
     $entity1 = new PolygonEntity();
     $entity1->setPolygon(new Polygon(array($lineString1)));
     $this->_em->persist($entity1);
     $entity2 = new PolygonEntity();
     $entity2->setPolygon(new Polygon(array($lineString2)));
     $this->_em->persist($entity2);
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery('SELECT p, ST_AsText(ST_Centroid(p.polygon)) FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p');
     $result = $query->getResult();
     $this->assertCount(2, $result);
     $this->assertEquals($entity1, $result[0][0]);
     $this->assertEquals('POINT(8 8)', $result[0][1]);
     $this->assertEquals($entity2, $result[1][0]);
     $this->assertEquals('POINT(6 6)', $result[1][1]);
 }
 public function testEnvelopeWhereParameter()
 {
     if ($this->getPlatform()->getName() == 'postgresql') {
         $this->markTestSkipped('Function not supported on postgresql.');
     }
     $entity1 = new PolygonEntity();
     $rings1 = array(new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0))), new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5))));
     $entity1->setPolygon(new Polygon($rings1));
     $this->_em->persist($entity1);
     $entity2 = new PolygonEntity();
     $rings2 = array(new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5))));
     $entity2->setPolygon(new Polygon($rings2));
     $this->_em->persist($entity2);
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE Envelope(p.polygon) = GeomFromText(:p1)');
     $envelopeRing = new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0)));
     $envelope = new Polygon(array($envelopeRing));
     $query->setParameter('p1', $envelope, 'polygon');
     $result = $query->getResult();
     $this->assertCount(1, $result);
     $this->assertEquals($entity1, $result[0]);
 }
Example #13
0
 /**
  * @group geometry
  */
 public function testSTAreaWhere()
 {
     $entity1 = new PolygonEntity();
     $rings1 = array(new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0))));
     $entity1->setPolygon(new Polygon($rings1));
     $this->getEntityManager()->persist($entity1);
     $entity2 = new PolygonEntity();
     $rings2 = array(new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0))), new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5))));
     $entity2->setPolygon(new Polygon($rings2));
     $this->getEntityManager()->persist($entity2);
     $entity3 = new PolygonEntity();
     $rings3 = array(new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 20), new Point(0, 20), new Point(10, 10), new Point(0, 0))));
     $entity3->setPolygon(new Polygon($rings3));
     $this->getEntityManager()->persist($entity3);
     $entity4 = new PolygonEntity();
     $rings4 = array(new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5))));
     $entity4->setPolygon(new Polygon($rings4));
     $this->getEntityManager()->persist($entity4);
     $this->getEntityManager()->flush();
     $this->getEntityManager()->clear();
     $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE ST_Area(p.polygon) < 50');
     $result = $query->getResult();
     $this->assertCount(1, $result);
     $this->assertEquals($entity4, $result[0]);
 }
 /**
  * @group geometry
  */
 public function testSTDisjointWhereParameter()
 {
     $lineString1 = new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0)));
     $lineString2 = new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5)));
     $lineString3 = new LineString(array(new Point(15, 15), new Point(17, 15), new Point(17, 17), new Point(15, 17), new Point(15, 15)));
     $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();
     $entity3 = new PolygonEntity();
     $entity3->setPolygon(new Polygon(array($lineString3)));
     $this->getEntityManager()->persist($entity3);
     $this->getEntityManager()->flush();
     $this->getEntityManager()->clear();
     $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE ST_Disjoint(p.polygon, ST_GeomFromText(:p1)) = true');
     $query->setParameter('p1', 'POLYGON((5 5,7 5,7 7,5 7,5 5))', 'string');
     $result = $query->getResult();
     $this->assertCount(1, $result);
     $this->assertEquals($entity3, $result[0]);
     $this->getEntityManager()->clear();
     $query = $this->getEntityManager()->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE ST_Disjoint(p.polygon, ST_GeomFromText(:p1)) = true');
     $query->setParameter('p1', 'POLYGON((15 15,17 15,17 17,15 17,15 15))', 'string');
     $result = $query->getResult();
     $this->assertCount(2, $result);
     $this->assertEquals($entity1, $result[0]);
     $this->assertEquals($entity2, $result[1]);
 }
Example #15
0
 public function testAreaWhereParameter()
 {
     if ($this->getPlatform()->getName() == 'postgresql') {
         $this->markTestSkipped('Function not supported on postgresql.');
     }
     $entity1 = new PolygonEntity();
     $rings1 = array(new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0))));
     $entity1->setPolygon(new Polygon($rings1));
     $this->_em->persist($entity1);
     $entity2 = new PolygonEntity();
     $rings2 = array(new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0))), new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5))));
     $entity2->setPolygon(new Polygon($rings2));
     $this->_em->persist($entity2);
     $entity3 = new PolygonEntity();
     $rings3 = array(new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 20), new Point(0, 20), new Point(10, 10), new Point(0, 0))));
     $entity3->setPolygon(new Polygon($rings3));
     $this->_em->persist($entity3);
     $entity4 = new PolygonEntity();
     $rings4 = array(new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5))));
     $entity4->setPolygon(new Polygon($rings4));
     $this->_em->persist($entity4);
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE Area(p.polygon) < 50');
     $result = $query->getResult();
     $this->assertCount(1, $result);
     $this->assertEquals($entity4, $result[0]);
 }
 /**
  * @group geometry
  */
 public function testMBRDisjointWhereParameter()
 {
     $lineString1 = new LineString(array(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0)));
     $lineString2 = new LineString(array(new Point(5, 5), new Point(7, 5), new Point(7, 7), new Point(5, 7), new Point(5, 5)));
     $lineString3 = new LineString(array(new Point(15, 15), new Point(17, 15), new Point(17, 17), new Point(15, 17), new Point(15, 15)));
     $entity1 = new PolygonEntity();
     $entity1->setPolygon(new Polygon(array($lineString1)));
     $this->_em->persist($entity1);
     $entity2 = new PolygonEntity();
     $entity2->setPolygon(new Polygon(array($lineString2)));
     $this->_em->persist($entity2);
     $this->_em->flush();
     $entity3 = new PolygonEntity();
     $entity3->setPolygon(new Polygon(array($lineString3)));
     $this->_em->persist($entity3);
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE MBRDisjoint(p.polygon, GeomFromText(:p1)) = 1');
     $query->setParameter('p1', new Polygon(array($lineString2)), 'polygon');
     $result = $query->getResult();
     $this->assertCount(1, $result);
     $this->assertEquals($entity3, $result[0]);
     $this->_em->clear();
     $query = $this->_em->createQuery('SELECT p FROM CrEOF\\Spatial\\Tests\\Fixtures\\PolygonEntity p WHERE MBRDisjoint(p.polygon, GeomFromText(:p1)) = 1');
     $query->setParameter('p1', new Polygon(array($lineString3)), 'polygon');
     $result = $query->getResult();
     $this->assertCount(2, $result);
     $this->assertEquals($entity1, $result[0]);
     $this->assertEquals($entity2, $result[1]);
 }