如何在rails中使用PostGIS功能?

[英]How can I use PostGIS functions in rails?


The query I'd like to run is:

我想运行的查询是:

SELECT zcta.geoid10, ST_AsGeoJSON(ST_simplify(zcta.geom,500)) FROM zcta WHERE zcta.geoid10 = '90210'

However in the Rails console when I enter this:

但是在Rails控制台当我输入这个:

testquery = "SELECT zcta.geoid10, ST_AsGeoJSON(ST_simplify(zcta.geom,500)) FROM zcta WHERE zcta.geoid10 = '90210'"
Zcta.find_by_sql testquery

I get the following returned:

我得到以下回复:

 => [#<Zcta >]

If I do a basic query asking for the result of any column I get the response I expect. This only happens with PostGIS functions. Any idea what to do?

如果我做一个基本的查询,询问任何列的结果,我都会得到预期的响应。这只发生在PostGIS函数中。知道怎么做吗?

1 个解决方案

#1


3  

Alias the calculated column and you will get a method added to the returned objects.

为计算列别名,您将获得添加到返回对象的方法。

Zcta.
  select("*, ST_AsGeoJSON(ST_simplify(geom,500)) as my_geo").
  where(geoid10: '90210').each do |result|
    puts result.my_geo
  end

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/04/05/4b3e3a1a162ba5c4c48cd05cacc1f434.html



 
  © 2014-2022 ITdaan.com 联系我们: