在CakePHP中保存空间数据 [英] Saving spatial data in CakePHP

查看:184
本文介绍了在CakePHP中保存空间数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用saveAll()保存CakePHP中的空间数据时遇到问题。我真的不想手动写入查询(在CakePHP中处理空间数据),因为有是要保存的模型数。



此外,我阅读了这篇 CakePHP和MySQL Spatial Extension ,但是当我尝试这样做时, $ db-> expression()返回一个stdClass。



这是打印出的返回对象:

  stdClass对象
b [type] => expression
[value] => GeomFromText('POINT(48.18879 18.527579999999944)')

如果我使用这个对象的方式在 CakePHP和MySQL Spatial扩展,并尝试保存它saveAll()我得到这个错误:



错误 :不能将类型为stdClass的对象用作数组

文件:/www/s/t/u47728/public_html/lib/Cake/Model/Model.php

行:2221

如果我使用value属性,它在查询中被转义,所以它只是一个字符串。然后,我收到此错误:



错误:SQLSTATE [22003]:数值超出范围:1416无法从您发送的数据到GEOMETRY字段



UPDATE

/ p>

显然,这同样适用于save()函数和其他....同样saveField()

解决方案

转换此行:

  $ this-> data ['Report' '] = $ db-> expression(GeomFromText('POINT(。
$ this-> data ['Report'] ['lat']。。$ this-& Report'] ['lng']。)'));

到:

 code> $ this-> data ['Report'] ['position'] =(object)$ db-> expression(GeomFromText('POINT(。
$ this-> data ['Report'] ['lat']。。$ this-> data ['Report'] ['lng']。)'));

它应该可以工作。


I have a problem saving spatial data in CakePHP with saveAll(). I really dont want to write the query manually (Handling spatial data in CakePHP) because there are number of models being saved.

Also I read this CakePHP and MySQL Spatial Extension but when I try to do the same, $db->expression() returns an stdClass.

This is the returned object printed out:

stdClass Object
(
    [type] => expression
    [value] => GeomFromText('POINT(48.18879 18.527579999999944)')
)

If I use this object the way it is used in CakePHP and MySQL Spatial Extension and try to save it with saveAll() I get this error:

Error: Cannot use object of type stdClass as array
File: /www/s/t/u47728/public_html/lib/Cake/Model/Model.php
Line: 2221

If I use the value property, it gets escaped in the query so it becomes just a string. Then I get this error:

Error: SQLSTATE[22003]: Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field

Does saveAll() suport expressions?

UPDATE

Apparently the same applies to save() function and others.... Also saveField()

解决方案

convert this line :

$this->data['Report']['position'] = $db->expression("GeomFromText('POINT(" . 
    $this->data['Report']['lat'] . " " . $this->data['Report']['lng'] . ")')");

to :

$this->data['Report']['position'] = (object) $db->expression("GeomFromText('POINT(" .
     $this->data['Report']['lat'] . " " . $this->data['Report']['lng'] . ")')");

It should work.

这篇关于在CakePHP中保存空间数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆