1

我在启用 PostGIS 的 Postgre 数据库上使用 Symfony 和 Doctrine2。我有两张桌子 - 具有以下结构的财产和社区:

class Property  {

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string")
 */
protected $address;

/**
 * @var Point $geom
 * @ORM\Column(type="Point", nullable=true)
 */
protected $geom;
}

class Neighborhood  {

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
 protected $gid;

 /**
 * @ORM\Column(type="string")
 */
 protected $name;

 /**
 * @ORM\Column(type="string")
 */     
 protected $description;

 /**
 * @var Polygon $geom
 *
 * @ORM\Column(type="Polygon", nullable=true)
 */
 protected $geom;
 }

在 pgAdminIII 中,我可以编写以下运行良好的查询:

SELECT address, neighborhood.name
FROM property
JOIN neighborhood
ON ST_Contains(neighborhood.geom, property.geom)

我怎样才能用 DQL 写这个?我了解连接的基础知识并为 Doctrine2 映射添加注释,但我不确定如何进行连接,因为这两个字段不相等。我需要使用 ST_Contains 函数来创建连接。我正在使用 djlambert / dictionary2-spatial 包进行空间数据类型和映射。我能够单独查询每个表并在每个表上创建了地图,但不确定如何选择给定社区中的所有属性。

4

2 回答 2

3

我想出了这一点,并想发布以防其他人有类似的问题。我需要使 ST_Contains 成为条件的一部分,而不仅仅是函数。

使用 createQueryBuilder,语法如下:

 $qb = $this->createQueryBuilder('n')              
            ->select("p.address as address, n.ntaname, ST_AsText(p.geom) as function")                
            ->join('Bundle\Entity\Property', 'p', 'WITH', 'ST_Contains(n.geom4326,p.geom)=true');        


    return $qb->getQuery()
                    ->getResult();
于 2014-01-16T01:56:21.937 回答
0

这不是一个真正的答案,而只是对@George 代码的评论。

对我来说,使用creof/doctrine2-spatial:0.0.1and symfony/symfony:2.3.*,注释需要是小写的模式才能验证 with php app/console doctrine:schema:validate,如下所示:

/**
 * @var Point $geom
 * @ORM\Column(type="point", nullable=true)
 */
protected $geom;

在大写的情况下,我不断收到此错误消息:

  [Doctrine\DBALDBALException]                                                                                                 
  Unknown column type "Point" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). [...]
于 2014-11-03T22:44:48.187 回答