Class: GeoRuby::SimpleFeatures::UnpackStructure

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_ruby/ewk/ewkb_parser.rb

Overview

:nodoc:

Constant Summary collapse

NDR =
1
XDR =
0

Instance Method Summary collapse

Constructor Details

#initialize(ewkb) ⇒ UnpackStructure

Returns a new instance of UnpackStructure.



158
159
160
161
# File 'lib/geo_ruby/ewk/ewkb_parser.rb', line 158

def initialize(ewkb)
  @position = 0
  @ewkb = ewkb
end

Instance Method Details

#doneObject



163
164
165
# File 'lib/geo_ruby/ewk/ewkb_parser.rb', line 163

def done
  fail EWKBFormatError.new('Trailing data') if @position != @ewkb.length
end

#endianness=(byte_order) ⇒ Object



195
196
197
198
199
200
201
202
203
# File 'lib/geo_ruby/ewk/ewkb_parser.rb', line 195

def endianness=(byte_order)
  if (byte_order == NDR)
    @uint_mark = 'V'
    @double_mark = 'E'
  elsif (byte_order == XDR)
    @uint_mark = 'N'
    @double_mark = 'G'
  end
end

#read_byteObject



188
189
190
191
192
193
# File 'lib/geo_ruby/ewk/ewkb_parser.rb', line 188

def read_byte
  i = @position
  @position += 1
  fail EWKBFormatError.new('Truncated data') if @ewkb.length < @position
  @ewkb.unpack("@#{i}C@*").first
end

#read_doubleObject



174
175
176
177
178
179
# File 'lib/geo_ruby/ewk/ewkb_parser.rb', line 174

def read_double
  i = @position
  @position += 8
  fail EWKBFormatError.new('Truncated data') if @ewkb.length < @position
  @ewkb.unpack("@#{i}#{@double_mark}@*").first
end

#read_pointObject



167
168
169
170
171
172
# File 'lib/geo_ruby/ewk/ewkb_parser.rb', line 167

def read_point
  i = @position
  @position += 16
  fail EWKBFormatError.new('Truncated data') if @ewkb.length < @position
  @ewkb.unpack("@#{i}#{@double_mark}#{@double_mark}@*")
end

#read_uintObject



181
182
183
184
185
186
# File 'lib/geo_ruby/ewk/ewkb_parser.rb', line 181

def read_uint
  i = @position
  @position += 4
  fail EWKBFormatError.new('Truncated data') if @ewkb.length < @position
  @ewkb.unpack("@#{i}#{@uint_mark}@*").first
end