Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling lat/long and mysql spatial points in rails
    primarykey
    data
    text
    <p>There have been a decent amount of questions about mysql spatial datatypes, however mine is more specific to how <strong>best</strong> to deal with them within a rails MVC architecture. </p> <p>I have an input form where an admin user can create a new point of interest, let's say, a restaurant and input some information. They can also input a human-readable latitude and longitude in decimal format. </p> <p>However, for distance calculations, etc... I am storing the location data as a spatial point in the database. </p> <p>My question therefore, is how to best handle this in the MVC architecture in rails?</p> <p>Here are some ideas I had, but nothing really seems clean:</p> <ul> <li><p>Call :after_filter method that takes the new instance of the object and does a raw SQL update that handles the "GeomFromText('POINT(lat long)' ))" goodness. The issue with this is that "lat/long" would be text fields in my create form, although this disrupts the clean form_for :object architecture that rails provides since lat/long aren't really attributes, they're just there to let a human input values that aren't mysql spatials. </p></li> <li><p>Maybe creating a trigger in the db to run after a row insert that updates that row? I have no idea and it doesn't seem like these triggers would have access to the lat/long, unless I stored the lat/long as well as the spatial point, and then created the row in the db with the lat/long decimals, and then ran the trigger after creation to update the spatial. I guess i could also do that with an after_filter if I added the lat/long columns to the model. </p></li> </ul> <p>Any other ideas? I think storing the lat/long is redundant since I'll really be using the spatial point for distance calculations, etc... but it might be necessary if I'm allowing for human editing. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload