教义问题:无法从发送到GEOMETRY字段的数据中获取几何对象

时间:2019-05-22 15:30:37

标签: symfony geometry doctrine geospatial symfony4

我跟随this guidedocument.body.addEventListener( 'click', function(e){ var target = e.target; if( target.id ){ console.log( target.id ); } }); 类型添加到学说。

这是我在实体中定义坐标字段的方式:

point

这就是我要保存实体的方式:

/**
 * @ORM\Column(type="point", nullable=true)
 */
private $coordinates;

我的配置:

$obj = new GeoPoint();
$obj->setAddress('Test');
$obj->setCoordinates(new Point(40.7603807, -73.9766831));
$manager->persist($obj);
$manager->flush();

结果数据库列定义:

doctrine:
    dbal:
        types:
            point: Viny\PointType
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci
        url: '%env(resolve:DATABASE_URL)%'
        mapping_types:
            point: point
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        quote_strategy: backend_lib.orm.quote_strategy
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

结果我得到:

  

使用参数[“ Test”,“ POINT(-73.976683 40.760381)执行'INSERT INTO `coordinates` point DEFAULT NULL, geo_pointaddress)值(?,?)'时发生异常“]:

     

SQLSTATE [22003]:数值超出范围:1416无法获取几何   从您发送到GEOMETRY字段的数据中提取对象

最终查询:

  

插入coordinatesgeo_pointaddress)值('Test','POINT(-73.976683 40.760381)');

1 个答案:

答案 0 :(得分:1)

您发布的Here is a working example是错误的。应该是:

#doctrine.yaml
doctrine:
    dbal:
        types: ### Use types instead of mapping_types
            point: App\...\GeoPointType

您可以判断出映射是有问题的,因为您生成了sql:

INSERT INTO geo_point (address, coordinates) VALUES ('Test', 'POINT(-73.976683 40.760381)');

mysql本身不理解POINT。它需要包装在PointFromText中。包装是通过以下方式完成的:

    // class GeoPointType
    public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
    {
        return sprintf('PointFromText(%s)', $sqlExpr);
    }

它显然没有被调用。

first example in the dataset, with 13 columns and 43 rows