Пример #1
0
 public function testSelectSTSummaryGeometry()
 {
     if ($this->getPlatform()->getName() == 'mysql') {
         $this->markTestSkipped('Function not supported on mssql.');
     }
     $entity1 = new GeometryEntity();
     $point1 = new Point(5, 5);
     $entity1->setGeometry($point1);
     $this->_em->persist($entity1);
     $entity2 = new GeometryEntity();
     $lineString2 = new LineString(array(array(1, 1), array(2, 2), array(3, 3)));
     $entity2->setGeometry($lineString2);
     $this->_em->persist($entity2);
     $entity3 = new GeometryEntity();
     $polygon3 = new Polygon(array(array(array(0, 0), array(10, 0), array(10, 10), array(0, 10), array(0, 0))));
     $entity3->setGeometry($polygon3);
     $this->_em->persist($entity3);
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery('SELECT g, ST_Summary(g.geometry) FROM CrEOF\\Spatial\\Tests\\Fixtures\\GeometryEntity g');
     $result = $query->getResult();
     $this->assertCount(3, $result);
     $this->assertEquals($entity1, $result[0][0]);
     $this->assertRegExp('/^Point\\[[^G]*\\]/', $result[0][1]);
     $this->assertEquals($entity2, $result[1][0]);
     $this->assertRegExp('/^LineString\\[[^G]*\\]/', $result[1][1]);
     $this->assertEquals($entity3, $result[2][0]);
     $this->assertRegExp('/^Polygon\\[[^G]*\\]/', $result[2][1]);
 }
 /**
  * @group geometry
  */
 public function testLineString()
 {
     $value = array(new Point(0, 0), new Point(5, 5), new Point(10, 10));
     $entity1 = new GeometryEntity();
     $entity1->setGeometry(new LineString($value));
     $this->getEntityManager()->persist($entity1);
     $this->getEntityManager()->flush();
     $this->getEntityManager()->clear();
     $query = $this->getEntityManager()->createQuery('SELECT g FROM CrEOF\\Spatial\\Tests\\Fixtures\\GeometryEntity g WHERE g.geometry = ST_GeomFromText(:geometry)');
     $query->setParameter('geometry', 'LINESTRING(0 0,5 5,10 10)', 'string');
     $result = $query->getResult();
     $this->assertCount(1, $result);
     $this->assertEquals($entity1, $result[0]);
 }
 public function testLineString()
 {
     if ($this->getPlatform()->getName() == 'mysql') {
         $this->markTestSkipped('Function not supported on mssql.');
     }
     $value = array(new Point(0, 0), new Point(5, 5), new Point(10, 10));
     $entity1 = new GeometryEntity();
     $entity1->setGeometry(new LineString($value));
     $this->_em->persist($entity1);
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery('SELECT g FROM CrEOF\\Spatial\\Tests\\Fixtures\\GeometryEntity g WHERE g.geometry = ST_GeomFromText(:geometry)');
     $query->setParameter('geometry', new LineString($value), 'linestring');
     $result = $query->getResult();
     $this->assertCount(1, $result);
     $this->assertEquals($entity1, $result[0]);
 }
 /**
  * @group common
  */
 public function testPolygonGeometry()
 {
     $entity = new GeometryEntity();
     $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->setGeometry(new Polygon($rings));
     $this->_em->persist($entity);
     $this->_em->flush();
     $id = $entity->getId();
     $this->_em->clear();
     $queryEntity = $this->_em->getRepository(self::GEOMETRY_ENTITY)->find($id);
     $this->assertEquals($entity, $queryEntity);
 }
Пример #5
0
 /**
  * @group geometry
  */
 public function testTypeWrappingWhere()
 {
     $entity = new GeometryEntity();
     $entity->setGeometry(new Point(5, 5));
     $this->getEntityManager()->persist($entity);
     $this->getEntityManager()->flush();
     $this->getEntityManager()->clear();
     $query = $this->getEntityManager()->createQuery('SELECT g FROM CrEOF\\Spatial\\Tests\\Fixtures\\GeometryEntity g WHERE g.geometry = :geometry');
     $query->setParameter('geometry', new Point(5, 5), '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('/geometry = %s/', $parameter));
     $this->assertRegExp($regex, $result);
 }