Sha256: 6abdf1ded45eec1914f87cae59630ccf5faf01e331e86e33b3f1714c19208863

Contents?: true

Size: 762 Bytes

Versions: 5

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

module Armg
  class WktSerializer
    DEFAULT_WKB_GENERATOR_OPTIONS = {
      type_format: :ewkb,
      little_endian: true
    }.freeze

    DEFAULT_WKT_PARSER_OPTIONS = {
      support_ewkt: true
    }.freeze

    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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
armg-0.11.0 lib/armg/wkt_serializer.rb
armg-0.10.0 lib/armg/wkt_serializer.rb
armg-0.9.0 lib/armg/wkt_serializer.rb
armg-0.8.1 lib/armg/wkt_serializer.rb
armg-0.8.0 lib/armg/wkt_serializer.rb