如何在 Rails 3 中进行批量地理编码
我有大约 100,000 条记录,我需要查找纬度和经度。目前我正在使用 geokit-rails 进行地理编码。
我现在所做的就是逐一循环记录来查找纬度和经度。但这非常耗时。有没有办法批量执行此操作?任何批处理方法或类似的方法。
请帮忙!
I have about 100,000 records, that I need to find latitude and longitude. Currently I am using geokit-rails
for geo-coding.
What I am doing now is looping the records one by one to find latitude and longitude. But it's very time consuming. Is there a way to do this in bulk? Any batch processing methods or something like that.
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能想到的唯一改进是使用
find_each
它将一次加载 500 个对象并循环访问它们。我认为你不能做得比这更好,即使有一种本机方法可以做到这一点,我认为性能也会是相同的。
The only improvement I can think of is using
find_each
It will load 500 objects at a time and loop through them. I don't think you can do a lot better than that, even if there was a native method to do it, the performances would be the same, I think.
我不认为有更快的方法。我同意@Robin,也许你可以做一点改进,但你不能提高很多性能。
我建议,为了改进系统,插入几行代码来自动检测记录的经度和纬度,就像我之前在 Rails 2 上所做的那样,给定记录的地址和城市,一旦你有创建一个新记录。这样就不会像你写的那样做一个耗时的循环了!
纬度和经度现在通过城市和地址进行地理编码。记录的城市和地址通过表格插入。考虑这是 Rails 2,也许您应该做一些编辑才能使其在 Rails 3 上运行!
I don't think there is a faster way to do it. I agree with @Robin, maybe you can do this little improvement, but you can't improve a lot the performance.
I suggest, to improve the system, to insert, as I have done time ago on Rails 2, few lines of code to automatically detect the longitude and the latitude of a record, given the address and the city of the record, once you have to create a new record. In this way, you won't do a time-consuming loop like you wrote!
Latitude and longitude are now geo-coded through city and address. City and address of the record are inserted with a form. Consider this is Rails 2, and maybe there are some edits you should do to get this working on Rails 3!