【问题标题】:How to fill a geographical column (PostGIS) with Ruby?如何用 Ruby 填充地理列(PostGIS)?
【发布时间】:2016-09-01 07:34:58
【问题描述】:

我有这个正常工作的 SQL 查询:

UPDATE my_table SET geography = ST_SetSRID(ST_MakePoint(my_table.longitude, my_table.latitude), 4326)::geography;

但我想知道一种在 Ruby 方法中执行此操作的方法(用 lon/lat 数据填充我的地理类型列(lon/lat 是另外 2 个列)。

提前致谢。

【问题讨论】:

  • 刚刚在 Ruby 中找到了一种方法,但我觉得它有点脏:ActiveRecord::Base.connection.execute("UPDATE my_table SET geography = ST_SetSRID(ST_MakePoint(my_table.longitude, my_table.latitude), 4326)::geography")

标签: ruby-on-rails ruby database postgresql postgis


【解决方案1】:

你可以使用这个api activerecord-postgis-adapter;它使用 activerecord 管理所有字段。

https://github.com/rgeo/activerecord-postgis-adapter

或者,如果您不使用 rails,您可以使用未超过 activerecord 的另一个。

https://github.com/sabman/postgis_adapter

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    • 2014-02-08
    • 1970-01-01
    • 2019-09-29
    • 2011-06-03
    相关资源
    最近更新 更多