I am working with Geo Spatial coordinates and was testing my coding in rails console
Looks like it is changing my longitude to -90.0 instead of what it should be -93.291557312011719
Any help would be appreciated.. tried it with just
"POINT(#{lng} #{lat})"
And
"POINT(#{lng.to_f} #{lat.to_f})"
Server info
CentOS 6.4
PostgreSQL 9.3
PostGIS 2.1 With Extensions of adminpack, fuzzystrmatch, pg_trgm, plpgsql
IRB console
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>
But if I am not tring to save to DB I get this
l = "POINT(#{lng.to_f} #{lat.to_f})"
=> "POINT(37.20896911621094 -93.291557312011719)"
Here is my table for locations
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
Because in your example code you have assigned -93.29 to latitude, not longitude, which has been rounded down to -90, the lower possible bound for latitude. Presumably, RGeo is intelligent enough to round to the nearest acceptable value, rather than throwing an error.