Class: Armg::WktSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/armg/wkt_serializer.rb

Constant Summary collapse

DEFAULT_WKB_GENERATOR_OPTIONS =
{
  type_format: :ewkb,
  little_endian: true
}.freeze
DEFAULT_WKT_PARSER_OPTIONS =
{
  support_ewkt: true
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(factory: nil, wkb_generator_options: {}, wkt_parser_options: {}) ⇒ WktSerializer

Returns a new instance of WktSerializer.



14
15
16
17
18
19
20
21
22
# File 'lib/armg/wkt_serializer.rb', line 14

def initialize(factory: nil, wkb_generator_options: {}, wkt_parser_options: {})
  @wkb_generator = RGeo::WKRep::WKBGenerator.new(
    DEFAULT_WKB_GENERATOR_OPTIONS.merge(wkb_generator_options)
  )
  @wkt_parser = RGeo::WKRep::WKTParser.new(
    factory,
    DEFAULT_WKT_PARSER_OPTIONS.merge(wkt_parser_options)
  )
end

Instance Method Details

#serialize(wkt) ⇒ Object



24
25
26
27
28
# File 'lib/armg/wkt_serializer.rb', line 24

def serialize(wkt)
  obj = @wkt_parser.parse(wkt)
  srid = Armg::Utils.pack_srid(obj.srid)
  srid + @wkb_generator.generate(obj)
end