【发布时间】:2017-03-07 12:46:50
【问题描述】:
我的桌子是
create_table :infomaps do |t|
t.string :name_station
t.string :name_location
t.integer :waterlevel
t.integer :rain
t.integer :water_sealevel
t.integer :tropical_level
t.integer :bank_level
t.string :river_name
t.string :place
t.st_point :lonlat, geographic: true
t.integer :time
t.timestamps null: false
end
我想使用以下示例代码:
SELECT name FROM nyc_streets WHERE ST_DWithin(
geom,
ST_GeomFromText('POINT(583571 4506714)',26918),
10
);
预期结果:
name:Wall St, Broad St and Nassau St
但是当尝试在 ruby on rails 中这样做时,像这样:
@result = Infomap.find_by_sql("SELECT name_station FROM infomaps WHERE ST_DWithin(lonlat,
ST_GeomFromText('POINT(20 100)',26918),
100); ")
我收到此错误:
PG::InvalidParameterValue: ERROR: Only lon/lat coordinate systems are supported in geography. : SELECT name_station FROM infomaps WHERE ST_DWithin(lonlat, ST_GeomFromText('POINT(20 100)',26918), 100);
如何解决 ST_DWithin 的 InvalidParameterValue 错误?
【问题讨论】:
-
您的示例查询和ruby 代码中的查询完全不同。使用相同的查询,它会工作
-
EPSG:26918 是投影坐标系,而不是经纬度,
geography类型应使用该坐标系。
标签: ruby-on-rails ruby postgresql postgis