Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
postgis-rgeo-point.rb
require 'rgeo'
# RGeo factory for spherical latlong points
rgeo_factory = RGeo::Geographic.spherical_factory(:srid => 4326)
coord = rgeo_factory.point(-111.500244140625, 40.84706035607122)
# => RGeo point "Point (-111.500244140625 40.84706035607122)"
point_text = RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true).generate(coord)
# => "0020000001000010e6c05be0040000000040446c6c79478831" # this is what is stored in Postgres
new_coord = RGeo::WKRep::WKBParser.new(rgeo_factory, support_ewkb: true, default_srid: 4326).parse(point_text)
# => RGeo point "Point (-111.500244140625 40.84706035607122)"
new_coord == coord # => true
class PointSerializer
FACTORY = RGeo::Geographic.spherical_factory(:srid => 4326)
def dump(point)
RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true).generate(point)
end
def self.load(value)
RGeo::WKRep::WKBParser.new(FACTORY, support_ewkb: true, default_srid: 4326).parse(value)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.