ActiveRecord 将字段设置为 SQL 表达式
我正在使用 Ruby 1.8.7 和 Rails 2.3.8,并且有许多由纬度和经度表示的位置。我正在使用 SQLite SpatiaLite 扩展将坐标转换为众所周知的二进制 (WKB) 格式。我关心的是如何让 ActiveRecord 执行插入或更新,调用适当的 SpatiaLite 转换方法。我想做这样的事情:
obj.geometry = "AsBinary(MakePoint(4, 51))"
obj.save
# ActiveRecord would now do something like:
# INSERT INTO objects (geometry) VALUES (AsBinary(MakePoint(4, 51)))
Is this possible with ActiveRecord?
我已经尝试过 GeoRuby,但虽然它能够正确读取 WKB blob,但无法将它们保存为 SpatiaLite 所用的相同格式。
谢谢!
I am using Ruby 1.8.7 and Rails 2.3.8 and have a number of locations represented by a latitude and a longitude. I am using the SQLite SpatiaLite extension to convert the coordinates to the well-known binary (WKB) format. My concern is how to have ActiveRecord perform the insert or update, calling the appropriate SpatiaLite conversion methods. I am looking to do something like this:
obj.geometry = "AsBinary(MakePoint(4, 51))"
obj.save
# ActiveRecord would now do something like:
# INSERT INTO objects (geometry) VALUES (AsBinary(MakePoint(4, 51)))
Is this possible with ActiveRecord?
I have already tried GeoRuby but while its able to properly read WKB blobs, it is unable to save them to the same format SpatiaLite does.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还没有使用GeoRuby,但是对于空间数据,我使用了thinking-sphinx和@geodist函数,使用工具非常好。
您可以阅读有关它的一些资源:
I didn't use GeoRuby yet, but for spatial data I used thinking-sphinx with @geodist function, and it's quite nice to use tool.
Some resources you can read about it:
经过几天的搜索并没有找到解决方案后,我决定简单地利用原始连接来执行实际的插入:
After days of searching and coming up with no solution, I decided to simply leverage the raw connection to perform the actual insert: