如何配置和使用学说扩展? (doctrine2空间)

时间:2016-02-03 12:12:36

标签: doctrine symfony

我想在教义中使用postrepgis。我找到了creof/doctrine2-spatial,我尝试使用它。我有这个错误:

  

[语义错误]第0行,第15行附近'ST_Contains(v.geopoint':错误:类'ST_Contains'未定义。

我不知道为什么,我已经阅读了文档,我尝试了很多不同的配置,但是时间问题一样。

我的config.yml

doctrine:
  dbal:
    driver:   pdo_pgsql
    host:     "%database_host%"
    port:     "%database_port%"
    dbname:   "%database_name%"
    user:     "%database_user%"
    password: "%database_password%"
    charset:  UTF8
    types:
        geometry:   CrEOF\Spatial\DBAL\Types\GeometryType
        point:      CrEOF\Spatial\DBAL\Types\Geometry\PointType
        polygon:    CrEOF\Spatial\DBAL\Types\Geometry\PolygonType
        linestring: CrEOF\Spatial\DBAL\Types\Geometry\LineStringType

    mapping_types:
        _text: string
  orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    #naming_strategy: doctrine.orm.naming_strategy.underscore
    entity_managers:
        default:
            dql:
                numeric_functions:
                    ST_Contains:     CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContains
                    Contains:     CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContains
                    st_area:         CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea
                    st_geomfromtext: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\GeomFromText
                    st_intersects:     CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STIntersects
                    st_buffer:     CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STBuffer
                    point: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STPoint
            auto_mapping: true

我的资料库

 public function findPointIn(){
    $queryBuilder = $this->_em->createQueryBuilder();
    $queryBuilder =  $queryBuilder->select('v')
                            ->where(
                                $queryBuilder->expr()->eq(
                                    sprintf("ST_Contains(v.geopoint  , v.geopoint)"),
                                    $queryBuilder->expr()->literal(true)
                                )
                            );

    return $queryBuilder->getQuery()->getResult();
}

1 个答案:

答案 0 :(得分:2)

根据文档,config.yml中的numeric_functions名称必须小写。改为:

numeric_functions:
    st_contains:     CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STContains
    contains:     CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains
    st_area:         CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Area
    st_geomfromtext: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeomFromText
    st_intersects:     CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STIntersects
    st_buffer:     CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STBuffer
    point: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Point