Spatial point - mysql

Hi guys. Does anyone has an idea of how can i save a field as a spatial point using the built in ORM ? With plain sql i would just set it as GeomFromText('Point(LAT LON)'). But it seems this does not work. Maybe to set the field before saving and using the equivalent php function ?



83.4k

Try using a raw-value:

$p = new Point();
$p->point = new Phalcon\Db\RawValue('Point(LAT LON)');
$p->save();


32.7k

Thnks @Phalcon. It's working. Now, how can i get the point values. As X(point), Y(point) ? Should i use phql ?



32.7k

I am using raw sql as suggested http://docs.phalconphp.com/en/latest/reference/phql.html . Can you please confirm that this is the right approach ? Wouldn't be more natural to allow defining the columns in the native find method ? like Robots::find('*','id=1') || Robots::find('name,type','id=1') that in plain sql would be select name, type from robots where id=1.



83.4k

You can pass a set of columns this way:

$robots = Robots::find(['id=1',  'columns' => 'name, type']);

http://docs.phalconphp.com/en/latest/reference/models.html#finding-records



32.7k

:) thank you. it's working just fine