0

我正在使用地理空间坐标并在 rails 控制台中测试我的编码

看起来它正在将我的经度更改为 -90.0 而不是应该是 -93.291557312011719

任何帮助将不胜感激..尝试过

“点(#{lng} #{lat})”

“点(#{lng.to_f} #{lat.to_f})”

服务器信息

CentOS 6.4
PostgreSQL 9.3
PostGIS 2.1  With Extensions of adminpack, fuzzystrmatch, pg_trgm, plpgsql

IRB 控制台

1.9.3-p547 :001 > city = "springfield"                                                                                                                            
 => "springfield" 
1.9.3-p547 :002 > state = "mo"                                                                                                
 => "mo" 
1.9.3-p547 :003 > lng = "37.208969116210938"                                                                                                
 => "37.208969116210938" 
1.9.3-p547 :004 > lat = "-93.291557312011719"                                                                                                
 => "-93.291557312011719" 
1.9.3-p547 :005 > l = Location.new({:city => city, :state => state, :coords => "POINT(#{lng.to_f} #{lat.to_f})", :cs => "#{city}, #{state}"})
2014-07-25 08:31:02 DEBUG --    (18.5ms)  SELECT * FROM geometry_columns WHERE f_table_name='locations'
 => #<Location id: nil, coords: #<RGeo::Geographic::SphericalPointImpl:0x56eb2f2 "POINT (37.20896911621094 -90.0)">, city: "springfield", state: "mo", zip: nil, created_at: nil, updated_at: nil, cs: "springfield, mo", alt: nil> 

但如果我不想保存到数据库,我会得到这个

l = "POINT(#{lng.to_f} #{lat.to_f})"                              
 => "POINT(37.20896911621094 -93.291557312011719)" 

这是我的位置表

 create_table "locations", :force => true do |t|
    t.spatial  "coords",     :limit => {:srid=>4326, :type=>"point", :geographic=>true}
    t.string   "city"
    t.string   "state"
    t.string   "zip"
    t.datetime "created_at",                                                             :null => false
    t.datetime "updated_at",                                                             :null => false
    t.string   "cs"
    t.text     "alt"
  end
4

1 回答 1

0

因为在您的示例代码中,您已将 -93.29 分配给纬度,而不是经度,它已向下舍入为 -90,这是纬度的可能下限。据推测,RGeo 足够聪明,可以四舍五入到最接近的可接受值,而不是抛出错误。

于 2014-07-25T15:37:33.240 回答