postgis - formatting/parsing form values in Ruby on Rails -
i working rgeo (postgis) , ruby on rails, total newbie both. i've got model contains coordinates attribute (latitude & longitude). using text input field when binding form that attribute, wanted format value human readable form. being 'rendered' raw db value, i.e., '0101000020e61000009468c9e3698c5ec065fed13769d64740'. i'd format '-122.193963, 47.675086' user. conversely, if user updates value, need parse format postgis can understand.
i've been searching , reading can find binding data forms in ror, can't find useful.
you seeing hex-encoded representation of well-known binary (wkb). there many geometry accessors coordinate information in different formats or representations. example:
select st_astext(geom) wkt, st_y(geom) latitude, st_x(geom) longitude ( select '0101000020e61000009468c9e3698c5ec065fed13769d64740'::geometry geom ) f; wkt | latitude | longitude ------------------------------+-----------+------------- point(-122.193963 47.675086) | 47.675086 | -122.193963 on ruby rgeo side, similar information can obtained using wkbparser. example, in tc_wkb_parser.rb similar:
parser_ = ::rgeo::wkrep::wkbparser.new obj_ = parser_.parse('0101000020e61000009468c9e3698c5ec065fed13769d64740') print [obj_.y, obj_.x] # [-122.193963, 47.675086]
Comments
Post a Comment