class GDAL::GridderOptions

Object to be used with a {GDAL::Gridder}.

Attributes

grid[R]

Object used by the {GDAL::Gridder} for doing the actual grid work.

@!attribute [r] grid @return [GDAL::Grid]

input_clipping_geometry[R]

Use for filtering out input points; any input points from the layer that fall within this boundary will be excluded from the gridding process. Note that this does not clip the output raster.

Replaces gdal_grid’s -clipsrc option.

@!attribute [rw] input_clipping_geometry @return [OGR::Geometry]

input_field_name[RW]

Name of field attribute to extract from each feature to use for Z values.

@!attribute [rw] input_field_name @return [String]

output_creation_options[R]

Driver-specific options to pass to the {GDAL::Driver} when creating the raster. Check out GDAL documentation for the driver you’re specifying (specified here through {#output_format}) to see what options you have available.

Correlates to gdal_grid option -co.

@!attribute output_creation_options @return [Hash]

output_data_type[R]

Data type of the output raster values.

Correlates to gdal_grid option -ot.

@!attribute [rw] output_data_type @return [FFI::GDAL::GDAL::DataType]

output_format[R]

The {GDAL::Driver} name to use for creating the output raster.

Correlates to gdal_grid option -of.

@!attribute [rw] output_format @return [String]

output_projection[R]

The SpatialReference to use for the output raster’s {GDAL::Dataset#projection}. If one isn’t given, the {GDAL::Gridder} will try to use the one from the source layer.

Correlates to gdal_grid option -a_srs.

@!attribute [rw] output_projection @return [OGR::SpatialReference]

output_size[R]

Dimensions to output the raster in.

Correlates to gdal_grid option -outsize.

@overload output_size @overload output_size=(width_height_array)

Sets the output Hash using a 2-element Array.
@param width_height_array [Array<Float>]
  A 2-element Array specifying the width and height of the output raster.

@overload output_size=(width_height_hash)

Sets the output Hash using a similar input Hash.
@param width_height_hash [Hash{width => Number, height => Number}]
  A Hash with :width and :height keys, specifying the width and height
  of the output raster.

@return [Hash{width: Number, height: Number}]

output_x_extent[R]

The minimum and maximum X coordinates for the output raster.

Correlates to gdal_grid option -txe.

@!attribute [rw] output_x_extent @return [Hash{min: Number, max: Number}]

output_y_extent[R]

The minimum and maximum Y coordinates for the output raster.

Correlates to gdal_grid option -tye.

@!attribute [rw] output_y_extent @return [Hash{min: Number, max: Number}]

progress_formatter[RW]

Custom progress output Proc, passed on to {GDAL::Grid#create}. This must follow semantics imposed by FFI::GDAL::GDAL.ProgressFunc.

This option doesn’t exist in gdal_grid; you only get their output format or no output at all (using -q).

@!attribute [rw] progress_formatter @return [Proc]

Public Class Methods

new(algorithm_type) click to toggle source

@param algorithm_type [Symbol] One of {FFI::GDAL::Alg::GridAlgorithm}.

# File lib/gdal/extensions/gridder_options.rb, line 123
def initialize(algorithm_type)
  # Options with defaults
  @output_data_type = :GDT_Float64
  @output_format = "GTiff"
  @output_size = { width: 256, height: 256 }

  # Options without defaults
  @input_clipping_geometry = nil
  @output_x_extent = {}
  @output_y_extent = {}
  @output_projection = nil
  @output_creation_options = {}
  @progress_formatter = nil

  @grid = GDAL::Grid.new(algorithm_type, data_type: @output_data_type)
end

Public Instance Methods

input_clipping_geometry=(geometry) click to toggle source

@param geometry [OGR::Geometry] @return [OGR::Geometry]

# File lib/gdal/extensions/gridder_options.rb, line 142
def input_clipping_geometry=(geometry)
  unless geometry.is_a?(OGR::Geometry)
    raise OGR::InvalidGeometry,
          "Clipping geometry must be a OGR::Geometry type, but was a #{geometry.class}"
  end

  @input_clipping_geometry = geometry
end
output_creation_options=(**options_hash) click to toggle source

@param options_hash [Hash]

# File lib/gdal/extensions/gridder_options.rb, line 223
def output_creation_options=(**options_hash)
  return if options_hash.empty?

  @output_creation_options = options_hash
end
output_data_type=(type) click to toggle source

@param type [Symbol] Must be one of FFI::GDAL::GDAL::DataType.

# File lib/gdal/extensions/gridder_options.rb, line 152
def output_data_type=(type)
  data_types = FFI::GDAL::GDAL::DataType.symbols

  unless data_types.include?(type)
    raise GDAL::InvalidDataType, "output_data_type must be one of #{data_types} but was #{type}"
  end

  @grid.data_type = @output_data_type = type
end
output_data_type_size() click to toggle source

@return [Integer]

# File lib/gdal/extensions/gridder_options.rb, line 163
def output_data_type_size
  GDAL::DataType.size(@output_data_type) / 8
end
output_driver() click to toggle source

The {GDAL::Driver}, based on {#output_format} to use for creating the output raster.

@return [GDAL::Driver]

# File lib/gdal/extensions/gridder_options.rb, line 182
def output_driver
  @output_driver ||= GDAL::Driver.by_name(@output_format)
end
output_format=(format) click to toggle source

@param format [String] Must be one of GDAL::Driver.short_names.

# File lib/gdal/extensions/gridder_options.rb, line 168
def output_format=(format)
  driver_names = GDAL::Driver.short_names

  unless driver_names.include?(format)
    raise GDAL::InvalidDriverName, "output_form must be one of #{driver_names} but was #{format}"
  end

  @output_format = format
end
output_projection=(spatial_reference) click to toggle source

Set to use a different SRID for the output raster. Defaults to use the same as the source Layer.

@param spatial_reference [OGR::SpatialReference]

# File lib/gdal/extensions/gridder_options.rb, line 213
def output_projection=(spatial_reference)
  unless spatial_reference.is_a?(OGR::SpatialReference)
    raise OGR::InvalidSpatialReference,
          "output_projection must be an OGR::SpatialReference but was a #{spatial_reference.class}"
  end

  @output_projection = spatial_reference
end
output_size=(width_height) click to toggle source

@param width_height [Array<Float>, Hash{width => Number, height => Number}]

Either a 2-element Array or a Hash with :width and :height keys,
specifying the width and height of the output raster.
# File lib/gdal/extensions/gridder_options.rb, line 203
def output_size=(width_height)
  width, height = extract_min_max(width_height, :width, :height)

  @output_size = { width: width, height: height }
end
output_x_extent=(min_max) click to toggle source

@param min_max [Array<Integer>, Hash{min => Number, max => Number}]

# File lib/gdal/extensions/gridder_options.rb, line 187
def output_x_extent=(min_max)
  min, max = extract_min_max(min_max, :min, :max)

  @output_x_extent = { min: min, max: max }
end
output_y_extent=(min_max) click to toggle source

@param min_max [Array<Integer>, Hash{min => Number, max => Number}]

# File lib/gdal/extensions/gridder_options.rb, line 194
def output_y_extent=(min_max)
  min, max = extract_min_max(min_max, :min, :max)

  @output_y_extent = { min: min, max: max }
end

Private Instance Methods

extract_min_max(content, min_name, max_name) click to toggle source

Extracts a min and max value from either a 2-element Array or a Hash with :min and :max keys.

@param content [Array, Hash] @param min_name [Symbol] @param max_name [Symbol] @return [Array<Number>]

# File lib/gdal/extensions/gridder_options.rb, line 238
def extract_min_max(content, min_name, max_name)
  case content
  when Array
    extract_min_max_from_array(content, min_name, max_name)
  when Hash
    extract_min_max_from_hash(content, min_name, max_name)
  end
end
extract_min_max_from_array(content, min_name, max_name) click to toggle source

@param content [Array, Hash] @param min_name [Symbol] @param max_name [Symbol] @return [Array<Number>]

# File lib/gdal/extensions/gridder_options.rb, line 251
def extract_min_max_from_array(content, min_name, max_name)
  unless content.length == 2
    raise ArgumentError, "Please supply only 2 elements, one for #{min_name}, one for #{max_name}"
  end

  [content[0], content[1]]
end
extract_min_max_from_hash(content, min_name, max_name) click to toggle source

@param content [Array, Hash] @param min_name [Symbol] @param max_name [Symbol] @return [Array<Number>]

# File lib/gdal/extensions/gridder_options.rb, line 263
def extract_min_max_from_hash(content, min_name, max_name)
  valid_keys = [min_name, max_name]
  actual_keys = content.keys

  unless actual_keys.length == 2 && valid_keys & actual_keys == valid_keys
    raise ArgumentError, "Please supply only key/value pairs for #{min_name} and #{max_name}"
  end

  [content[min_name], content[max_name]]
end