Class: RGeo::WKRep::WKBGenerator
- Inherits:
-
Object
- Object
- RGeo::WKRep::WKBGenerator
- Defined in:
- lib/rgeo/wkrep/wkb_generator.rb
Overview
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.
Constant Summary collapse
- TYPE_CODES =
:stopdoc:
{ Feature::Point => 1, Feature::LineString => 2, Feature::LinearRing => 2, Feature::Line => 2, Feature::Polygon => 3, Feature::MultiPoint => 4, Feature::MultiLineString => 5, Feature::MultiPolygon => 6, Feature::GeometryCollection => 7 }.freeze
Instance Attribute Summary collapse
-
#type_format ⇒ Object
readonly
Returns the format for type codes.
Instance Method Summary collapse
-
#emit_ewkb_srid? ⇒ Boolean
Returns whether SRID is embedded.
-
#generate(obj) ⇒ Object
Generate and return the WKB format for the given geometry object, according to the current settings.
-
#hex_format? ⇒ Boolean
Returns whether output is converted to hex.
-
#initialize(opts = {}) ⇒ WKBGenerator
constructor
Create and configure a WKB generator.
-
#little_endian? ⇒ Boolean
Returns whether output is little-endian (NDR).
- #properties ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ WKBGenerator
Create and configure a WKB generator. See the WKBGenerator documentation for the options that can be passed.
60 61 62 63 64 65 |
# File 'lib/rgeo/wkrep/wkb_generator.rb', line 60 def initialize(opts = {}) @type_format = opts[:type_format] || :wkb11 @emit_ewkb_srid = @type_format == :ewkb && opts[:emit_ewkb_srid] @hex_format = opts[:hex_format] ? true : false @little_endian = opts[:little_endian] ? true : false end |
Instance Attribute Details
#type_format ⇒ Object (readonly)
Returns the format for type codes. See WKBGenerator for details.
68 69 70 |
# File 'lib/rgeo/wkrep/wkb_generator.rb', line 68 def type_format @type_format end |
Instance Method Details
#emit_ewkb_srid? ⇒ Boolean
Returns whether SRID is embedded. See WKBGenerator for details.
71 72 73 |
# File 'lib/rgeo/wkrep/wkb_generator.rb', line 71 def emit_ewkb_srid? @emit_ewkb_srid end |
#generate(obj) ⇒ Object
Generate and return the WKB format for the given geometry object, according to the current settings.
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rgeo/wkrep/wkb_generator.rb', line 99 def generate(obj) factory = obj.factory if @type_format == :ewkb || @type_format == :wkb12 has_z = factory.property(:has_z_coordinate) has_m = factory.property(:has_m_coordinate) else has_z = false has_m = false end result = Result.new(has_z, has_m) generate_feature(obj, result, toplevel: true) result.emit(@hex_format) end |
#hex_format? ⇒ Boolean
Returns whether output is converted to hex. See WKBGenerator for details.
77 78 79 |
# File 'lib/rgeo/wkrep/wkb_generator.rb', line 77 def hex_format? @hex_format end |
#little_endian? ⇒ Boolean
Returns whether output is little-endian (NDR). See WKBGenerator for details.
83 84 85 |
# File 'lib/rgeo/wkrep/wkb_generator.rb', line 83 def little_endian? @little_endian end |
#properties ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/rgeo/wkrep/wkb_generator.rb', line 87 def properties { "type_format" => @type_format.to_s, "emit_ewkb_srid" => @emit_ewkb_srid, "hex_format" => @hex_format, "little_endian" => @little_endian } end |