Class: OGR::Field
- Inherits:
-
Object
- Object
- OGR::Field
- Defined in:
- lib/ogr/field.rb
Instance Attribute Summary collapse
- #c_struct ⇒ FFI::OGR::Point readonly
Instance Method Summary collapse
-
#binary ⇒ String
8-bit, unsigned data (uchar).
- #binary=(new_binary) ⇒ Object
- #c_pointer ⇒ FFI::Pointer
- #date ⇒ DateTime
- #date=(new_date) ⇒ Object
-
#initialize(ogr_field_struct = nil) ⇒ Field
constructor
A new instance of Field.
- #integer ⇒ Integer (also: #to_i)
- #integer64 ⇒ Integer
- #integer64=(new_int64) ⇒ Object
- #integer64_list ⇒ Array<Integer> (also: #to_bignum)
- #integer64_list=(new_integer64_list) ⇒ Object (also: #bignum_list=)
- #integer=(new_int) ⇒ Object
- #integer_list ⇒ Array<Integer>
- #integer_list=(new_integer_list) ⇒ Object
- #real ⇒ Float (also: #to_f)
- #real=(new_real) ⇒ Object
- #real_list ⇒ Array<Float> (also: #float_list)
- #real_list=(new_real_list) ⇒ Object (also: #float_list=)
- #set ⇒ Hash
- #set=(new_set) ⇒ Object
-
#string ⇒ Object
TODO: This blows up when another value type has been set.
- #string=(new_string) ⇒ Object
- #string_list ⇒ Array<String>
- #string_list=(new_string_list) ⇒ Object
Constructor Details
Instance Attribute Details
#c_struct ⇒ FFI::OGR::Point (readonly)
10 11 12 |
# File 'lib/ogr/field.rb', line 10 def c_struct @c_struct end |
Instance Method Details
#binary ⇒ String
Returns 8-bit, unsigned data (uchar). Unpack with String#unpack(‘C*’).
150 151 152 153 154 |
# 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) ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# 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 ⇒ FFI::Pointer
18 19 20 |
# File 'lib/ogr/field.rb', line 18 def c_pointer @c_struct.to_ptr end |
#date ⇒ DateTime
184 185 186 187 188 189 190 191 192 193 194 195 196 |
# 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) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# 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 |
#integer ⇒ Integer Also known as: to_i
23 24 25 |
# File 'lib/ogr/field.rb', line 23 def integer @c_struct[:integer] end |
#integer64 ⇒ Integer
34 35 36 |
# File 'lib/ogr/field.rb', line 34 def integer64 @c_struct[:integer64] end |
#integer64=(new_int64) ⇒ Object
39 40 41 |
# File 'lib/ogr/field.rb', line 39 def integer64=(new_int64) @c_struct[:integer64] = new_int64 end |
#integer64_list ⇒ Array<Integer> Also known as: to_bignum
86 87 88 89 90 91 |
# 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 |
#integer64_list=(new_integer64_list) ⇒ Object Also known as: bignum_list=
95 96 97 98 99 100 101 102 103 104 |
# 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 |
#integer=(new_int) ⇒ Object
29 30 31 |
# File 'lib/ogr/field.rb', line 29 def integer=(new_int) @c_struct[:integer] = new_int end |
#integer_list ⇒ Array<Integer>
66 67 68 69 70 71 |
# 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) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# 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 ⇒ Float Also known as: to_f
44 45 46 |
# File 'lib/ogr/field.rb', line 44 def real @c_struct[:real] end |
#real=(new_real) ⇒ Object
50 51 52 |
# File 'lib/ogr/field.rb', line 50 def real=(new_real) @c_struct[:real] = new_real end |
#real_list ⇒ Array<Float> Also known as: float_list
108 109 110 111 112 113 |
# 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 |
#real_list=(new_real_list) ⇒ Object Also known as: float_list=
117 118 119 120 121 122 123 124 125 126 |
# 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 |
#set ⇒ Hash
170 171 172 |
# File 'lib/ogr/field.rb', line 170 def set { marker1: @c_struct[:set][:marker1], marker2: @c_struct[:set][:marker2] } end |
#set=(new_set) ⇒ Object
175 176 177 178 179 180 181 |
# 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 ⇒ Object
TODO: This blows up when another value type has been set.
55 56 57 58 59 |
# File 'lib/ogr/field.rb', line 55 def string return "" if @c_struct[:string]&.null? @c_struct[:string].read_string end |
#string=(new_string) ⇒ Object
61 62 63 |
# File 'lib/ogr/field.rb', line 61 def string=(new_string) @c_struct[:string] = FFI::MemoryPointer.from_string(new_string) end |
#string_list ⇒ Array<String>
130 131 132 133 134 135 |
# 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) ⇒ Object
138 139 140 141 142 143 144 145 146 |
# 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 |