Class: GDAL::Grid

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logger
Defined in:
lib/gdal/grid.rb

Overview

Wrapper for GDAL’s [Grid API](www.gdal.org/grid_tutorial.html).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(algorithm_type, data_type: :GDT_Float32) ⇒ Grid

Returns a new instance of Grid.

Parameters:



22
23
24
25
# File 'lib/gdal/grid.rb', line 22

def initialize(algorithm_type, data_type: :GDT_Float32)
  @algorithm = init_algorithm(algorithm_type)
  @data_type = data_type
end

Instance Attribute Details

#data_typeFFI::GDAL::GDAL::DataType



15
16
17
# File 'lib/gdal/grid.rb', line 15

def data_type
  @data_type
end

Instance Method Details

#create(points, extents, data_pointer, output_size = { x: 256, y: 256 }, progress_block = nil, progress_arg = nil) ⇒ FFI::MemoryPointer

Returns Pointer to the grid data.

Parameters:

  • points (Array, NArray)

    An Array containing all x, y, and z points.

  • extents (Hash{x_min: Integer, y_min: Integer, x_max: Integer, y_max: Integer})
  • data_pointer (FFI::Pointer)

    Pointer that will contain the gridded data (after this method is done).

  • output_size (Hash{x: Integer, y: Integer}) (defaults to: { x: 256, y: 256 })

    Overall dimensions of the area of the output raster to grid.

  • progress_block (Proc) (defaults to: nil)
  • progress_arg (FFI::Pointer) (defaults to: nil)

Returns:

  • (FFI::MemoryPointer)

    Pointer to the grid data.

Raises:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gdal/grid.rb', line 36

def create(points, extents, data_pointer, output_size = { x: 256, y: 256 },
  progress_block = nil, progress_arg = nil)
  points = points.to_a if points.is_a? NArray
  point_count = points.length
  log "Number of points: #{point_count}"
  raise GDAL::NoValuesToGrid, "No points to grid" if point_count.zero?

  points = points.transpose
  x_input_coordinates_ptr = make_points_pointer(points[0])
  y_input_coordinates_ptr = make_points_pointer(points[1])
  z_input_coordinates_ptr = make_points_pointer(points[2])

  log "x_min, y_min: #{extents[:x_min]}, #{extents[:y_min]}"
  log "x_max, y_max: #{extents[:x_max]}, #{extents[:y_max]}"
  log "output_x_size, output_y_size: #{output_size[:x]}, #{output_size[:y]}"

  FFI::GDAL::Alg.GDALGridCreate(
    @algorithm.c_identifier,                        # eAlgorithm
    @algorithm.options.to_ptr,                      # poOptions
    point_count,                                    # nPoints
    x_input_coordinates_ptr,                        # padfX
    y_input_coordinates_ptr,                        # padfY
    z_input_coordinates_ptr,                        # padfZ
    extents[:x_min],                                # dfXMin
    extents[:x_max],                                # dfXMax
    extents[:y_min],                                # dfYMin
    extents[:y_max],                                # dfYMax
    output_size[:x],                                # nXSize
    output_size[:y],                                # nYSize
    @data_type,                                     # eType
    data_pointer,                                   # pData,
    progress_block,                                 # pfnProgress
    progress_arg                                    # pProgressArg
  )
end