class RGeo::WKRep::WKBGenerator

This class provides the functionality of serializing a geometry as WKB (well-known binary) format. You may also customize the serializer to generate PostGIS EWKB extensions to the output, or to follow the Simple Features Specification 1.2 extensions for Z and M coordinates.

To use this class, create an instance with the desired settings and customizations, and call the generate method.

Configuration options

The following options are recognized. These can be passed to the constructor, or set on the object afterwards.

:type_format

The format for type codes. Possible values are :wkb11, indicating SFS 1.1 WKB (i.e. no Z or M values); :ewkb, indicating the PostGIS EWKB extensions (i.e. Z and M presence flagged by the two high bits of the type code, and support for embedded SRID); or :wkb12 (indicating SFS 1.2 WKB (i.e. Z and M presence flagged by adding 1000 and/or 2000 to the type code.) Default is :wkb11.

:emit_ewkb_srid

If true, embed the SRID in the toplevel geometry. Available only if :type_format is :ewkb. Default is false.

:hex_format

If true, output a hex string instead of a byte string. Default is false.

:little_endian

If true, output little endian (NDR) byte order. If false, output big endian (XDR), or network byte order. Default is false.

Public Class Methods

new(opts_={}) click to toggle source

Create and configure a WKB generator. See the WKBGenerator documentation for the options that can be passed.

# File lib/rgeo/wkrep/wkb_generator.rb, line 95
def initialize(opts_={})
  @type_format = opts_[:type_format] || :wkb11
  @emit_ewkb_srid = @type_format == :ewkb ?
    (opts_[:emit_ewkb_srid] ? true : false) : nil
  @hex_format = opts_[:hex_format] ? true : false
  @little_endian = opts_[:little_endian] ? true : false
end

Public Instance Methods

emit_ewkb_srid?() click to toggle source

Returns whether SRID is embedded. See WKBGenerator for details.

# File lib/rgeo/wkrep/wkb_generator.rb, line 110
def emit_ewkb_srid?
  @emit_ewkb_srid
end
generate(obj_) click to toggle source

Generate and return the WKB format for the given geometry object, according to the current settings.

# File lib/rgeo/wkrep/wkb_generator.rb, line 140
def generate(obj_)
  factory_ = obj_.factory
  if @type_format == :ewkb || @type_format == :wkb12
    @cur_has_z = factory_.property(:has_z_coordinate)
    @cur_has_m = factory_.property(:has_m_coordinate)
  else
    @cur_has_z = nil
    @cur_has_m = nil
  end
  @cur_dims = 2 + (@cur_has_z ? 1 : 0) + (@cur_has_m ? 1 : 0)
  _start_emitter
  _generate_feature(obj_, true)
  _finish_emitter
end
hex_format?() click to toggle source

Returns whether output is converted to hex. See WKBGenerator for details.

# File lib/rgeo/wkrep/wkb_generator.rb, line 116
def hex_format?
  @hex_format
end
little_endian?() click to toggle source

Returns whether output is little-endian (NDR). See WKBGenerator for details.

# File lib/rgeo/wkrep/wkb_generator.rb, line 122
def little_endian?
  @little_endian
end
type_format() click to toggle source

Returns the format for type codes. See WKBGenerator for details.

# File lib/rgeo/wkrep/wkb_generator.rb, line 105
def type_format
  @type_format
end