Handling spatial data in CakePHP
Asked Answered
M

1

0

I have a database with a field for spatial data and a cakephp interface for it. In MySQL I can save the data by doing:

INSERT INTO nodes (Location) VALUES (GeomFromText('POINT(42.450071 -76.487664)'))

How can I make Cake take the latitude and longitude from a web form and insert it in this manner? I made a model that reads spatial data but I can't figure out how to make it write in spatial format.

Thanks for any insight.

-Andrew

Mule answered 4/1, 2011 at 21:52 Comment(0)
A
0

It's a little tricky to find in the manual unless you know what to look for, but this should help you: http://book.cakephp.org/view/1027/query

e.g. something along the lines of:

$gLat = 42.450071;
$gLong = -76.487664;
$this->Node->query("INSERT INTO nodes (Location) VALUES (GeomFromText('POINT({$gLat} {$gLong})'))");
Anisometric answered 5/1, 2011 at 14:34 Comment(2)
Aha - looks good. So I must make a field in the view that uploads the variables to $gLat and $gLong. Just doing echo $form->input('gLat'); won't do it though. I looked in the book but is there a way to make the form input go to a variable readable by the controller rather than automatically entered into the db?Mule
$this->data will contain all of the form data. Try debug($this->data); in your controller.Anisometric

© 2022 - 2024 — McMap. All rights reserved.