Class: GeoRuby::SimpleFeatures::UnpackStructure

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_ruby/simple_features/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.



177
178
179
180
# File 'lib/geo_ruby/simple_features/ewkb_parser.rb', line 177

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

Instance Method Details

#doneObject

Raises:



181
182
183
# File 'lib/geo_ruby/simple_features/ewkb_parser.rb', line 181

def done
  raise EWKBFormatError::new("Trailing data") if @position != @ewkb.length
end

#endianness=(byte_order) ⇒ Object



205
206
207
208
209
210
211
212
213
# File 'lib/geo_ruby/simple_features/ewkb_parser.rb', line 205

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

Raises:



198
199
200
201
202
203
204
# File 'lib/geo_ruby/simple_features/ewkb_parser.rb', line 198

def read_byte
  i = @position
  @position += 1
  packed_byte = @ewkb[i...@position]
  raise EWKBFormatError::new("Truncated data") if packed_byte.nil? or packed_byte.length < 1
  packed_byte.unpack("C")[0]
end

#read_doubleObject

Raises:



184
185
186
187
188
189
190
# File 'lib/geo_ruby/simple_features/ewkb_parser.rb', line 184

def read_double
  i=@position
  @position += 8
  packed_double = @ewkb[i...@position]
  raise EWKBFormatError::new("Truncated data") if packed_double.nil? or packed_double.length < 8
  packed_double.unpack(@double_mark)[0]
end

#read_uintObject

Raises:



191
192
193
194
195
196
197
# File 'lib/geo_ruby/simple_features/ewkb_parser.rb', line 191

def read_uint
  i=@position
  @position += 4
  packed_uint = @ewkb[i...@position]
  raise EWKBFormatError::new("Truncated data") if packed_uint.nil? or packed_uint.length < 4
  packed_uint.unpack(@uint_mark)[0]
end