ruby on rails - Postgis latitude/longitude read out reversed -


i have class, geocoordinateable, gives models useful methods dealing geo-coordinates. included in "geocoordinates=" accepts array.

https://gist.github.com/mboyle/58dd3add830bbdeef316

you can call "geocoordinates" coordinates in array:

irb(main):056:0> b.geocoordinates => [-118.25, 34.197] 

when assign coordinates so:

irb(main):058:0> b.geocoordinates = [34.197, -118.25]    (1.8ms)    update users  set geocoordinates = 'srid=4326;point(' || 34.197 || ' ' || -118.25 || ')'  id = 347708     (0.7ms)    update activities  set geocoordinates = users.geocoordinates  users  activities.user_id = users.id  , users.id = 347708  , not postgis.st_equals(activities.geocoordinates, users.geocoordinates)  => [34.197, -118.25] 

things seem save , come out correctly. if query model again, however, , read geocoordinates, lat/long reversed:

irb(main):059:0> b = user.find(b.id) irb(main):060:0> b.geocoordinates    (0.7ms)    select postgis.st_y(geocoordinates) latitude, postgis.st_x(geocoordinates) longitude  users  id = 347708  => [-118.25, 34.197] 

i cannot life of me understand why happening. have clue?

in postgis coordinates set in (x, y) order, or (longitude, latitude) geographic coordinate pairs. should do:

update users set geocoordinates = 'srid=4326;point(' || -118.25 || ' ' || 34.197 || ')' id = 347708 

and too:

irb(main):058:0> b.geocoordinates = [-118.25, 34.197] 

note postgis ingests text data in well-known text (wkt) format specified ogc. standard prescribes (x,y) or (lon,lat) order. not of choice, required enable postgis ingest wkt files produced other ogc-compliant software. after wkt ingested, postgis stores data in internal format, in fact modified ogc well-known binary (wkb) format, in column postgis-defined geometry or geography data type, , data can analyzed , presented in form desired end user.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -