class OGR::Field

Attributes

c_struct[R]

@return [FFI::OGR::Point]

Public Class Methods

new(ogr_field_struct = nil) click to toggle source

@param ogr_field_struct [FFI::OGR::Point, FFI::Pointer]

# File lib/ogr/field.rb, line 13
def initialize(ogr_field_struct = nil)
  @c_struct = ogr_field_struct || ::FFI::OGR::Field.new
end

Public Instance Methods

bignum_list=(new_integer64_list)
Alias for: integer64_list=
binary() click to toggle source

@return [String] 8-bit, unsigned data (uchar). Unpack with

String#unpack('C*').
# File lib/ogr/field.rb, line 150
def binary
  b = @c_struct[:binary]

  b[:count].positive? ? b[:data].read_bytes(b[:count]) : ""
end
binary=(new_binary) click to toggle source

@param new_binary [String] Binary string of 8-bit, unsigned data (uchar).

Pack with Array#pack('C*').
# File lib/ogr/field.rb, line 158
def binary=(new_binary)
  data = FFI::MemoryPointer.new(:uchar, new_binary.length)
  data.put_bytes(0, new_binary)

  b = FFI::OGR::FieldTypes::Binary.new
  b[:data] = data
  b[:count] = new_binary.length

  @c_struct[:binary] = b
end
c_pointer() click to toggle source

@return [FFI::Pointer]

# File lib/ogr/field.rb, line 18
def c_pointer
  @c_struct.to_ptr
end
date() click to toggle source

@return [DateTime]

# File lib/ogr/field.rb, line 184
def date
  c_date = @c_struct[:date]
  return if c_date[:year].zero? || c_date[:month].zero? || c_date[:day].zero?

  formatted_tz = OGR._format_time_zone_for_ruby(c_date[:tz_flag].to_i)
  DateTime.new(c_date[:year],
               c_date[:month],
               c_date[:day],
               c_date[:hour],
               c_date[:minute],
               c_date[:second],
               formatted_tz)
end
date=(new_date) click to toggle source

@param new_date [Date, Time, DateTime]

# File lib/ogr/field.rb, line 199
def date=(new_date)
  # All of Date's Time methods are private. Using #send to accomdate Date.
  zone = OGR._format_time_zone_for_ogr(new_date.send(:zone))

  date = FFI::OGR::FieldTypes::Date.new
  date[:year] = new_date.year
  date[:month] = new_date.month
  date[:day] = new_date.day
  date[:hour] = new_date.hour
  date[:minute] = new_date.send(:min)
  date[:second] = new_date.send(:sec) + (new_date.to_time.usec / 1_000_000.to_f)
  date[:tz_flag] = zone

  @c_struct[:date] = date
end
float_list()
Alias for: real_list
float_list=(new_real_list)
Alias for: real_list=
integer() click to toggle source

@return [Integer]

# File lib/ogr/field.rb, line 23
def integer
  @c_struct[:integer]
end
Also aliased as: to_i
integer64() click to toggle source

@return [Integer]

# File lib/ogr/field.rb, line 34
def integer64
  @c_struct[:integer64]
end
integer64=(new_int64) click to toggle source

@param new_int64 [Integer]

# File lib/ogr/field.rb, line 39
def integer64=(new_int64)
  @c_struct[:integer64] = new_int64
end
integer64_list() click to toggle source

@return [Array<Integer>]

# File lib/ogr/field.rb, line 86
def integer64_list
  il = @c_struct[:integer_list]
  return [] if il[:count].zero?

  il[:list].read_array_of_int64(il[:count])
end
Also aliased as: to_bignum
integer64_list=(new_integer64_list) click to toggle source

@param new_integer64_list [Array<Integer>]

# File lib/ogr/field.rb, line 95
def integer64_list=(new_integer64_list)
  list_ptr = FFI::MemoryPointer.new(:int64, new_integer64_list.size)
  list_ptr.write_array_of_int64(new_integer64_list)

  il = FFI::OGR::FieldTypes::Integer64List.new
  il[:count] = new_integer64_list.size
  il[:list] = list_ptr

  @c_struct[:integer64_list] = il
end
Also aliased as: bignum_list=
integer=(new_int) click to toggle source

@param new_int [Integer]

# File lib/ogr/field.rb, line 29
def integer=(new_int)
  @c_struct[:integer] = new_int
end
integer_list() click to toggle source

@return [Array<Integer>]

# File lib/ogr/field.rb, line 66
def integer_list
  il = @c_struct[:integer_list]
  return [] if il[:count].zero?

  il[:list].read_array_of_int(il[:count])
end
integer_list=(new_integer_list) click to toggle source

@param new_integer_list [Array<Integer>]

# File lib/ogr/field.rb, line 74
def integer_list=(new_integer_list)
  list_ptr = FFI::MemoryPointer.new(:int, new_integer_list.length)
  list_ptr.write_array_of_int(new_integer_list)

  il = FFI::OGR::FieldTypes::IntegerList.new
  il[:count] = new_integer_list.size
  il[:list] = list_ptr

  @c_struct[:integer_list] = il
end
real() click to toggle source

@return [Float]

# File lib/ogr/field.rb, line 44
def real
  @c_struct[:real]
end
Also aliased as: to_f
real=(new_real) click to toggle source

@param new_real [Float]

# File lib/ogr/field.rb, line 50
def real=(new_real)
  @c_struct[:real] = new_real
end
real_list() click to toggle source

@return [Array<Float>]

# File lib/ogr/field.rb, line 108
def real_list
  rl = @c_struct[:real_list]
  return [] if rl[:count].zero?

  rl[:list].read_array_of_double(rl[:count])
end
Also aliased as: float_list
real_list=(new_real_list) click to toggle source

@param new_real_list [Array<Float>]

# File lib/ogr/field.rb, line 117
def real_list=(new_real_list)
  list_ptr = FFI::MemoryPointer.new(:double, new_real_list.size)
  list_ptr.write_array_of_double(new_real_list)

  rl = FFI::OGR::FieldTypes::RealList.new
  rl[:count] = new_real_list.size
  rl[:list] = list_ptr

  @c_struct[:real_list] = rl
end
Also aliased as: float_list=
set() click to toggle source

@return [Hash]

# File lib/ogr/field.rb, line 170
def set
  { marker1: @c_struct[:set][:marker1], marker2: @c_struct[:set][:marker2] }
end
set=(new_set) click to toggle source

@param new_set [Hash{marker1 => Integer, marker2 => Integer}]

# File lib/ogr/field.rb, line 175
def set=(new_set)
  set = FFI::OGR::FieldTypes::Set.new
  set[:marker1] = new_set[:marker1]
  set[:marker2] = new_set[:marker2]

  @c_struct[:set] = set
end
string() click to toggle source

TODO: This blows up when another value type has been set.

# File lib/ogr/field.rb, line 55
def string
  return "" if @c_struct[:string]&.null?

  @c_struct[:string].read_string
end
string=(new_string) click to toggle source
# File lib/ogr/field.rb, line 61
def string=(new_string)
  @c_struct[:string] = FFI::MemoryPointer.from_string(new_string)
end
string_list() click to toggle source

@return [Array<String>]

# File lib/ogr/field.rb, line 130
def string_list
  sl = @c_struct[:string_list]
  return [] if sl[:count].zero?

  sl[:list].read_array_of_pointer(sl[:count]).map(&:read_string)
end
string_list=(new_string_list) click to toggle source

@param new_string_list [Array<String>]

# File lib/ogr/field.rb, line 138
def string_list=(new_string_list)
  list_ptr = GDAL._string_array_to_pointer(new_string_list)

  sl = FFI::OGR::FieldTypes::StringList.new
  sl[:count] = new_string_list.size
  sl[:list] = list_ptr

  @c_struct[:string_list] = sl
end
to_bignum()
Alias for: integer64_list
to_f()
Alias for: real
to_i()
Alias for: integer