Class: GDAL::WarpOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/gdal/warp_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ WarpOptions

Returns a new instance of WarpOptions.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gdal/warp_options.rb', line 9

def initialize(options = {})
  @c_struct = FFI::GDAL::WarpOptions.new
  @source_dataset = nil
  @destination_dataset = nil

  options.each_key do |k|
    assign_meth = "#{k}=".to_sym

    begin
      if respond_to?(assign_meth)
        send(assign_meth, options[k])
      else
        @c_struct[k] = options[k]
      end
    rescue ArgumentError => e
      new_message = "#{k}; #{e.message}"
      raise $ERROR_INFO, new_message, $ERROR_INFO.backtrace
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth) ⇒ Object

Used for getting attributes of the internal WarpOptions struct.

Parameters:

  • meth (Symbol)

    The FFI::GDAL::WarpOptions key.



190
191
192
193
194
# File 'lib/gdal/warp_options.rb', line 190

def method_missing(meth)
  super unless FFI::GDAL::WarpOptions.members.include?(meth)

  @c_struct[meth]
end

Instance Attribute Details

#c_structObject (readonly)

Returns the value of attribute c_struct.



7
8
9
# File 'lib/gdal/warp_options.rb', line 7

def c_struct
  @c_struct
end

#cutlineObject

Returns the value of attribute cutline.



7
8
9
# File 'lib/gdal/warp_options.rb', line 7

def cutline
  @cutline
end

#destination_datasetObject

Returns the value of attribute destination_dataset.



7
8
9
# File 'lib/gdal/warp_options.rb', line 7

def destination_dataset
  @destination_dataset
end

#source_datasetObject

Returns the value of attribute source_dataset.



7
8
9
# File 'lib/gdal/warp_options.rb', line 7

def source_dataset
  @source_dataset
end

Instance Method Details

#c_pointerObject



30
31
32
# File 'lib/gdal/warp_options.rb', line 30

def c_pointer
  @c_struct.to_ptr
end

#destination_bandsArray<Integer>

Returns:



85
86
87
88
89
90
# File 'lib/gdal/warp_options.rb', line 85

def destination_bands
  pointer = @c_struct[:destination_bands]
  return [] if pointer.null?

  pointer.read_array_of_int(@c_struct[:band_count])
end

#destination_bands=(band_numbers) ⇒ Object

Parameters:



76
77
78
79
80
81
82
# File 'lib/gdal/warp_options.rb', line 76

def destination_bands=(band_numbers)
  bands_ptr = FFI::MemoryPointer.new(:pointer, band_numbers.length)
  bands_ptr.write_array_of_int(band_numbers)

  @c_struct[:destination_bands] = bands_ptr
  @c_struct[:band_count] = band_numbers.length if band_numbers.length > @c_struct[:band_count]
end

#destination_no_data_imaginaryArray<Float>

Returns:



164
165
166
167
168
169
# File 'lib/gdal/warp_options.rb', line 164

def destination_no_data_imaginary
  pointer = @c_struct[:destination_no_data_imaginary]
  return [] if pointer.null?

  pointer.read_array_of_double(@c_struct[:band_count])
end

#destination_no_data_imaginary=(values) ⇒ Object

Parameters:



156
157
158
159
160
161
# File 'lib/gdal/warp_options.rb', line 156

def destination_no_data_imaginary=(values)
  values_ptr = FFI::MemoryPointer.new(:double, values.length)
  values_ptr.write_array_of_double(values)

  @c_struct[:destination_no_data_imaginary] = values_ptr
end

#destination_no_data_realArray<Float>

Returns:



148
149
150
151
152
153
# File 'lib/gdal/warp_options.rb', line 148

def destination_no_data_real
  pointer = @c_struct[:destination_no_data_real]
  return [] if pointer.null?

  pointer.read_array_of_double(@c_struct[:band_count])
end

#destination_no_data_real=(values) ⇒ Object

Parameters:



140
141
142
143
144
145
# File 'lib/gdal/warp_options.rb', line 140

def destination_no_data_real=(values)
  values_ptr = FFI::MemoryPointer.new(:double, values.length)
  values_ptr.write_array_of_double(values)

  @c_struct[:destination_no_data_real] = values_ptr
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/gdal/warp_options.rb', line 196

def respond_to_missing?(method_name, include_private = false)
  FFI::GDAL::WarpOptions.members.include?(method_name) || super
end

#source_bandsArray<Integer>

Returns:



68
69
70
71
72
73
# File 'lib/gdal/warp_options.rb', line 68

def source_bands
  pointer = @c_struct[:source_bands]
  return [] if pointer.null?

  pointer.read_array_of_int(@c_struct[:band_count])
end

#source_bands=(band_numbers) ⇒ Object

Parameters:



59
60
61
62
63
64
65
# File 'lib/gdal/warp_options.rb', line 59

def source_bands=(band_numbers)
  bands_ptr = FFI::MemoryPointer.new(:int, band_numbers.length)
  bands_ptr.write_array_of_int(band_numbers)

  @c_struct[:source_bands] = bands_ptr
  @c_struct[:band_count] = band_numbers.length if band_numbers.length > @c_struct[:band_count]
end

#source_no_data_imaginaryArray<Float>

Returns:



132
133
134
135
136
137
# File 'lib/gdal/warp_options.rb', line 132

def source_no_data_imaginary
  pointer = @c_struct[:source_no_data_imaginary]
  return [] if pointer.null?

  pointer.read_array_of_double(@c_struct[:band_count])
end

#source_no_data_imaginary=(values) ⇒ Object

Parameters:



124
125
126
127
128
129
# File 'lib/gdal/warp_options.rb', line 124

def source_no_data_imaginary=(values)
  values_ptr = FFI::MemoryPointer.new(:double, values.length)
  values_ptr.write_array_of_double(values)

  @c_struct[:source_no_data_imaginary] = values_ptr
end

#source_no_data_realArray<Float>

Returns:



116
117
118
119
120
121
# File 'lib/gdal/warp_options.rb', line 116

def source_no_data_real
  pointer = @c_struct[:source_no_data_real]
  return [] if pointer.null?

  pointer.read_array_of_double(@c_struct[:band_count])
end

#source_no_data_real=(values) ⇒ Object

Parameters:



108
109
110
111
112
113
# File 'lib/gdal/warp_options.rb', line 108

def source_no_data_real=(values)
  values_ptr = FFI::MemoryPointer.new(:double, values.length)
  values_ptr.write_array_of_double(values)

  @c_struct[:source_no_data_real] = values_ptr
end

#source_per_band_validity_mask_function=(band_procs) ⇒ Object

Set a Proc per source band; number of procs in band_procs should equal the internal band_count.

Parameters:

  • band_procs (Array<Proc>)


175
176
177
178
179
180
181
182
183
184
185
# File 'lib/gdal/warp_options.rb', line 175

def source_per_band_validity_mask_function=(band_procs)
  mask_func = FFI::GDAL::Warper::MaskFunc

  funcs = band_procs.map do |band_proc|
    FFI::Function.new(mask_func.result_type, mask_func.param_types, band_proc, blocking: true)
  end

  pointer = FFI::MemoryPointer.new(:pointer, band_procs.length)
  pointer.write_array_of_pointer(funcs)
  @c_struct[:source_per_band_validity_mask_function] = pointer
end

#transformer_arg=(transformation_object) ⇒ Object



92
93
94
95
96
# File 'lib/gdal/warp_options.rb', line 92

def transformer_arg=(transformation_object)
  @c_struct[:transformer_arg] = transformation_object.c_pointer

  @c_struct[:transformer] = transformation_object.function
end

#warp_operation_optionsHash

Returns:

  • (Hash)


40
41
42
43
44
# File 'lib/gdal/warp_options.rb', line 40

def warp_operation_options
  options = @c_struct[:warp_operation_options]

  GDAL::Options.to_hash(options)
end

#warp_operation_options=(options) ⇒ Object

Parameters:

  • options (Hash)


35
36
37
# File 'lib/gdal/warp_options.rb', line 35

def warp_operation_options=(options)
  @c_struct[:warp_operation_options] = GDAL::Options.pointer(options)
end