This class provides the functionality of parsing a geometry from WKB (well-known binary) format. You may also customize the parser to recognize PostGIS EWKB extensions to the input, or 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 parse method.
You must provide each parser with an RGeo::Feature::FactoryGenerator.
It should understand the configuration options :srid
,
:has_z_coordinate
, and :has_m_coordinate
. You may
also pass a specific RGeo::Feature::Factory, or nil to
specify the default Cartesian
FactoryGenerator.
The following additional options are recognized. These can be passed to the constructor, or set on the object afterwards.
:support_ewkb
Activate support for PostGIS EWKB type codes, which use high order bits in the type code to signal the presence of Z, M, and SRID values in the data. Default is false.
:support_wkb12
Activate support for SFS 1.2 extensions to the type codes, which use values greater than 1000 to signal the presence of Z and M values in the data. SFS 1.2 types such as triangle, tin, and polyhedralsurface are NOT yet supported. Default is false.
:ignore_extra_bytes
If true, extra bytes at the end of the data are ignored. If false (the default), extra bytes will trigger a parse error.
:default_srid
A SRID to pass to the factory generator if no SRID is present in the input. Defaults to nil (i.e. don’t specify a SRID).
Create and configure a WKB parser. See the WKBParser documentation for the options that can be passed.
# File lib/rgeo/wkrep/wkb_parser.rb, line 83 def initialize(factory_generator_=nil, opts_={}) if factory_generator_.kind_of?(Feature::Factory::Instance) @factory_generator = Feature::FactoryGenerator.single(factory_generator_) @exact_factory = factory_generator_ elsif factory_generator_.respond_to?(:call) @factory_generator = factory_generator_ @exact_factory = nil else @factory_generator = Cartesian.method(:preferred_factory) @exact_factory = nil end @support_ewkb = opts_[:support_ewkb] ? true : false @support_wkb12 = opts_[:support_wkb12] ? true : false @ignore_extra_bytes = opts_[:ignore_extra_bytes] ? true : false @default_srid = opts_[:default_srid] end
If this parser was given an exact factory, returns it; otherwise returns nil.
# File lib/rgeo/wkrep/wkb_parser.rb, line 108 def exact_factory @exact_factory end
Returns the factory generator. See WKBParser for details.
# File lib/rgeo/wkrep/wkb_parser.rb, line 102 def factory_generator @factory_generator end
Returns true if this parser ignores extra bytes. See WKBParser for details.
# File lib/rgeo/wkrep/wkb_parser.rb, line 126 def ignore_extra_bytes? @ignore_extra_bytes end
Parse the given binary data or hexadecimal string, and return a geometry object.
The parse_hex method is a synonym, present for historical reasons but deprecated. Use parse instead.
# File lib/rgeo/wkrep/wkb_parser.rb, line 147 def parse(data_) if data_[0,1] =~ %r[0-9a-fA-F]/ data_ = [data_].pack('H*') end @cur_has_z = nil @cur_has_m = nil @cur_srid = nil @cur_dims = 2 @cur_factory = nil begin _start_scanner(data_) obj_ = _parse_object(false) unless @ignore_extra_bytes bytes_ = _bytes_remaining if bytes_ > 0 raise Error::ParseError, "Found #{bytes_} extra bytes at the end of the stream." end end ensure _clean_scanner end obj_ end
Returns true if this parser supports EWKB. See WKBParser for details.
# File lib/rgeo/wkrep/wkb_parser.rb, line 114 def support_ewkb? @support_ewkb end
Returns true if this parser supports SFS 1.2 extensions. See WKBParser for details.
# File lib/rgeo/wkrep/wkb_parser.rb, line 120 def support_wkb12? @support_wkb12 end