ruby - rails math query inside where clause -
i using ror sqlite3 , trying results locations table satisfy math status containing square terms of attributes. "locations" table contains latitude:float , longitude:float field. here's line of code search :
@results = location.where('latitude > ? , latitude < ? , elevation > ? , elevation < ? , ((latitude-?)**2 +(longitude - ?)**2 <= (?)**2)',@latitude_range_start,@latitude_range_end,@elevation_range_start, @elevation_range_end,@latitude_mycity.to_f, @longitude_mycity.to_f, @rad_range.to_f)
rails displaying error:
sqlite3::sqlexception: near "*": syntax error: select "locations".* "locations" (latitude > 20.7333148 , latitude < 40.7333148 , elevation > -651.3542785644531 , elevation < 1348.6457214355469 , ((latitude-30.7333148)**2 + (longitude - 76.7794179)**2 <= (1111.0)**2))
how query status in clause. seems squaring terms within problem. how do that?
sqlite not have **
operator.
unless have created user-defined function, have compute squares manually:
...where('latitude between ? , ? , elevation between ? , ? , (latitude - ?) * (latitude - ?) + (longitude - ?) * (longitude - ?) <= ? * ?', ...
(please note formula assumes earth flat.)
ruby-on-rails ruby sqlite3
No comments:
Post a Comment