ffi-gdal 1.0.0.beta5 → 1.0.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -3
  3. data/.rubocop.yml +7 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +1 -1
  6. data/History.md +143 -1
  7. data/README.md +5 -11
  8. data/Rakefile +2 -60
  9. data/TODO.md +10 -0
  10. data/examples/geometries.rb +4 -6
  11. data/examples/gridding.rb +99 -98
  12. data/examples/ogr_layer_to_layer.rb +0 -2
  13. data/examples/raster_erasing.rb +47 -0
  14. data/examples/remove_small_polygons.rb +62 -0
  15. data/examples/testing_gdal.rb +0 -3
  16. data/examples/warping.rb +140 -0
  17. data/ffi-gdal.gemspec +5 -2
  18. data/lib/ext/error_symbols.rb +1 -1
  19. data/lib/ext/ffi_library_function_checks.rb +3 -2
  20. data/lib/ext/float_ext.rb +2 -2
  21. data/lib/ext/narray_ext.rb +1 -1
  22. data/lib/ext/numeric_as_data_type.rb +1 -1
  23. data/lib/ext/to_bool.rb +2 -2
  24. data/lib/ffi/cpl/conv.rb +1 -3
  25. data/lib/ffi/cpl/error.rb +0 -3
  26. data/lib/ffi/cpl/minixml.rb +17 -21
  27. data/lib/ffi/cpl/progress.rb +27 -0
  28. data/lib/ffi/cpl/string.rb +0 -8
  29. data/lib/ffi/cpl/vsi.rb +0 -1
  30. data/lib/ffi/cpl/xml_node.rb +0 -1
  31. data/lib/ffi/cpl.rb +15 -0
  32. data/lib/ffi/gdal/alg.rb +72 -54
  33. data/lib/ffi/gdal/gdal.rb +669 -672
  34. data/lib/ffi/gdal/grid.rb +141 -24
  35. data/lib/ffi/gdal/grid_data_metrics_options.rb +1 -1
  36. data/lib/ffi/gdal/grid_moving_average_options.rb +1 -1
  37. data/lib/ffi/gdal/matching.rb +0 -2
  38. data/lib/ffi/gdal/transformer_info.rb +1 -1
  39. data/lib/ffi/gdal/version.rb +1 -1
  40. data/lib/ffi/gdal/vrt.rb +0 -2
  41. data/lib/ffi/gdal/warp_options.rb +12 -14
  42. data/lib/ffi/gdal/warper.rb +61 -6
  43. data/lib/ffi/gdal.rb +18 -3
  44. data/lib/ffi/ogr/api.rb +10 -21
  45. data/lib/ffi/ogr/core.rb +9 -12
  46. data/lib/ffi/ogr/featurestyle.rb +0 -5
  47. data/lib/ffi/ogr/geocoding.rb +0 -1
  48. data/lib/ffi/ogr/srs_api.rb +0 -4
  49. data/lib/ffi/ogr/style_value.rb +1 -2
  50. data/lib/ffi/ogr.rb +15 -12
  51. data/lib/ffi-gdal.rb +5 -3
  52. data/lib/gdal/color_entry.rb +1 -0
  53. data/lib/gdal/color_interpretation.rb +2 -2
  54. data/lib/gdal/color_table.rb +14 -14
  55. data/lib/gdal/color_table_mixins/extensions.rb +4 -4
  56. data/lib/gdal/cpl_error_handler.rb +12 -14
  57. data/lib/gdal/data_type.rb +13 -12
  58. data/lib/gdal/dataset.rb +170 -94
  59. data/lib/gdal/dataset_mixins/algorithm_methods.rb +47 -21
  60. data/lib/gdal/dataset_mixins/extensions.rb +32 -61
  61. data/lib/gdal/dataset_mixins/matching.rb +0 -2
  62. data/lib/gdal/dataset_mixins/warp_methods.rb +42 -0
  63. data/lib/gdal/driver.rb +62 -47
  64. data/lib/gdal/driver_mixins/extensions.rb +2 -7
  65. data/lib/gdal/environment_methods.rb +13 -10
  66. data/lib/gdal/exceptions.rb +24 -2
  67. data/lib/gdal/geo_transform.rb +10 -16
  68. data/lib/gdal/geo_transform_mixins/extensions.rb +58 -3
  69. data/lib/gdal/grid.rb +62 -109
  70. data/lib/gdal/{grid_types → grid_algorithms}/data_metrics_base.rb +1 -3
  71. data/lib/gdal/{grid_types → grid_algorithms}/inverse_distance_to_a_power.rb +2 -4
  72. data/lib/gdal/{grid_types → grid_algorithms}/metric_average_distance.rb +2 -2
  73. data/lib/gdal/{grid_types → grid_algorithms}/metric_average_distance_pts.rb +2 -2
  74. data/lib/gdal/{grid_types → grid_algorithms}/metric_count.rb +2 -2
  75. data/lib/gdal/{grid_types → grid_algorithms}/metric_maximum.rb +2 -2
  76. data/lib/gdal/{grid_types → grid_algorithms}/metric_minimum.rb +2 -2
  77. data/lib/gdal/{grid_types → grid_algorithms}/metric_range.rb +2 -2
  78. data/lib/gdal/{grid_types → grid_algorithms}/moving_average.rb +2 -4
  79. data/lib/gdal/{grid_types → grid_algorithms}/nearest_neighbor.rb +2 -4
  80. data/lib/gdal/grid_algorithms.rb +22 -0
  81. data/lib/gdal/gridder/point_extracting.rb +89 -0
  82. data/lib/gdal/gridder.rb +294 -0
  83. data/lib/gdal/gridder_options.rb +273 -0
  84. data/lib/gdal/internal_helpers.rb +132 -23
  85. data/lib/gdal/major_object.rb +13 -10
  86. data/lib/gdal/merger.rb +130 -0
  87. data/lib/gdal/options.rb +3 -2
  88. data/lib/gdal/raster_attribute_table.rb +74 -51
  89. data/lib/gdal/raster_attribute_table_mixins/extensions.rb +21 -3
  90. data/lib/gdal/raster_band.rb +139 -167
  91. data/lib/gdal/raster_band_classifier.rb +19 -18
  92. data/lib/gdal/raster_band_mixins/algorithm_extensions.rb +107 -0
  93. data/lib/gdal/raster_band_mixins/algorithm_methods.rb +79 -40
  94. data/lib/gdal/raster_band_mixins/coloring_extensions.rb +84 -0
  95. data/lib/gdal/raster_band_mixins/extensions.rb +34 -169
  96. data/lib/gdal/raster_band_mixins/io_extensions.rb +180 -0
  97. data/lib/gdal/rpc_info.rb +1 -2
  98. data/lib/gdal/transformer.rb +1 -6
  99. data/lib/gdal/transformers/approximate_transformer.rb +0 -4
  100. data/lib/gdal/transformers/base_general_image_projection_transformer.rb +0 -6
  101. data/lib/gdal/transformers/gcp_transformer.rb +2 -6
  102. data/lib/gdal/transformers/general_image_projection_transformer.rb +8 -7
  103. data/lib/gdal/transformers/general_image_projection_transformer2.rb +1 -1
  104. data/lib/gdal/transformers/geolocation_transformer.rb +0 -4
  105. data/lib/gdal/transformers/reprojection_transformer.rb +0 -8
  106. data/lib/gdal/transformers/rpc_transformer.rb +0 -4
  107. data/lib/gdal/transformers/tps_transformer.rb +1 -3
  108. data/lib/gdal/version_info.rb +7 -8
  109. data/lib/gdal/virtual_dataset.rb +2 -4
  110. data/lib/gdal/warp_operation.rb +17 -14
  111. data/lib/gdal/warp_options.rb +132 -0
  112. data/lib/gdal.rb +41 -2
  113. data/lib/ogr/coordinate_transformation.rb +79 -32
  114. data/lib/ogr/data_source.rb +17 -14
  115. data/lib/ogr/data_source_extensions.rb +1 -5
  116. data/lib/ogr/driver.rb +11 -14
  117. data/lib/ogr/envelope.rb +1 -1
  118. data/lib/ogr/envelope_extensions.rb +23 -6
  119. data/lib/ogr/error_handling.rb +3 -3
  120. data/lib/ogr/exceptions.rb +6 -0
  121. data/lib/ogr/feature.rb +25 -38
  122. data/lib/ogr/feature_definition.rb +6 -8
  123. data/lib/ogr/feature_definition_extensions.rb +2 -6
  124. data/lib/ogr/feature_extensions.rb +71 -41
  125. data/lib/ogr/field.rb +16 -15
  126. data/lib/ogr/field_definition.rb +4 -4
  127. data/lib/ogr/geocoder.rb +5 -5
  128. data/lib/ogr/geometries/geometry_collection.rb +4 -1
  129. data/lib/ogr/geometries/geometry_collection_25d.rb +12 -0
  130. data/lib/ogr/geometries/line_string.rb +30 -8
  131. data/lib/ogr/geometries/line_string_25d.rb +21 -0
  132. data/lib/ogr/geometries/linear_ring.rb +10 -1
  133. data/lib/ogr/geometries/multi_line_string.rb +2 -1
  134. data/lib/ogr/geometries/multi_line_string_25d.rb +13 -0
  135. data/lib/ogr/geometries/multi_point.rb +2 -1
  136. data/lib/ogr/geometries/multi_point_25d.rb +14 -0
  137. data/lib/ogr/geometries/multi_polygon.rb +3 -2
  138. data/lib/ogr/geometries/multi_polygon_25d.rb +13 -0
  139. data/lib/ogr/geometries/point.rb +20 -23
  140. data/lib/ogr/geometries/point_25d.rb +48 -0
  141. data/lib/ogr/geometries/polygon.rb +4 -1
  142. data/lib/ogr/geometries/polygon_25d.rb +14 -0
  143. data/lib/ogr/geometry.rb +125 -93
  144. data/lib/ogr/geometry_field_definition.rb +7 -5
  145. data/lib/ogr/geometry_mixins/container_mixins.rb +23 -0
  146. data/lib/ogr/geometry_mixins/extensions.rb +111 -0
  147. data/lib/ogr/geometry_types/container.rb +10 -3
  148. data/lib/ogr/geometry_types/curve.rb +68 -23
  149. data/lib/ogr/geometry_types/surface.rb +0 -9
  150. data/lib/ogr/internal_helpers.rb +3 -3
  151. data/lib/ogr/layer.rb +4 -5
  152. data/lib/ogr/layer_mixins/extensions.rb +242 -17
  153. data/lib/ogr/layer_mixins/ogr_feature_methods.rb +11 -11
  154. data/lib/ogr/layer_mixins/ogr_field_methods.rb +6 -11
  155. data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +18 -18
  156. data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +0 -2
  157. data/lib/ogr/layer_mixins/ogr_sql_methods.rb +1 -1
  158. data/lib/ogr/spatial_reference.rb +12 -37
  159. data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +53 -55
  160. data/lib/ogr/spatial_reference_mixins/exporters.rb +18 -49
  161. data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +10 -29
  162. data/lib/ogr/style_table.rb +2 -2
  163. data/lib/ogr/style_table_extensions.rb +3 -1
  164. data/lib/ogr/style_tool.rb +8 -14
  165. data/lib/ogr.rb +39 -1
  166. data/spec/ffi-gdal_spec.rb +18 -1
  167. data/spec/integration/gdal/color_table_info_spec.rb +49 -33
  168. data/spec/integration/gdal/dataset_info_spec.rb +294 -45
  169. data/spec/integration/gdal/driver_info_spec.rb +139 -31
  170. data/spec/integration/gdal/geo_transform_info_spec.rb +197 -26
  171. data/spec/integration/gdal/gridder_spec.rb +329 -0
  172. data/spec/integration/gdal/raster_attribute_table_info_spec.rb +216 -11
  173. data/spec/integration/gdal/raster_band_algorithms_spec.rb +33 -0
  174. data/spec/integration/gdal/raster_band_info_spec.rb +240 -271
  175. data/spec/integration/ogr/layer_spec.rb +3 -1
  176. data/spec/spec_helper.rb +15 -6
  177. data/spec/support/images/osgeo/gdal/data/hfa/float-rle.img +0 -0
  178. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.lgo +31 -0
  179. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif +0 -0
  180. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif.msk +0 -0
  181. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.txt +10 -0
  182. data/spec/support/images/osgeo/geotiff/gdal_eg/cea.tif +0 -0
  183. data/spec/support/images/osgeo/geotiff/gdal_eg/cea.txt +84 -0
  184. data/spec/support/images/osgeo/geotiff/zi_imaging/image0.lgo +45 -0
  185. data/spec/support/images/osgeo/geotiff/zi_imaging/image0.tif +0 -0
  186. data/spec/support/integration_help.rb +32 -2
  187. data/spec/support/shared_examples/gdal/major_object_examples.rb +0 -6
  188. data/spec/support/shared_examples/ogr/a_geometry.rb +1 -1
  189. data/spec/unit/ffi/gdal_spec.rb +1 -1
  190. data/spec/unit/gdal/color_entry_spec.rb +1 -0
  191. data/spec/unit/gdal/color_interpretation_spec.rb +1 -0
  192. data/spec/unit/gdal/dataset_spec.rb +53 -2
  193. data/spec/unit/gdal/geo_transform_mixins/extensions_spec.rb +67 -0
  194. data/spec/unit/gdal/geo_transform_spec.rb +1 -1
  195. data/spec/unit/gdal/grid_spec.rb +83 -0
  196. data/spec/unit/gdal/gridder/point_extracting_spec.rb +99 -0
  197. data/spec/unit/gdal/gridder_options_spec.rb +183 -0
  198. data/spec/unit/gdal/gridder_spec.rb +140 -0
  199. data/spec/unit/gdal/internal_helpers_spec.rb +166 -2
  200. data/spec/unit/gdal/major_object_spec.rb +2 -0
  201. data/spec/unit/gdal/options_spec.rb +1 -0
  202. data/spec/unit/gdal/raster_band_classifier_spec.rb +70 -12
  203. data/spec/unit/gdal/raster_band_mixins/extensions_spec.rb +71 -0
  204. data/spec/unit/gdal/raster_band_mixins/io_extensions_spec.rb +133 -0
  205. data/spec/unit/gdal/raster_band_spec.rb +1 -0
  206. data/spec/unit/gdal/rpc_info_spec.rb +1 -0
  207. data/spec/unit/gdal/version_info_spec.rb +2 -0
  208. data/spec/unit/gdal/warp_operation_spec.rb +1 -0
  209. data/spec/unit/ogr/coordinate_transformation_spec.rb +102 -0
  210. data/spec/unit/ogr/data_source_spec.rb +12 -0
  211. data/spec/unit/ogr/feature_extensions_spec.rb +88 -0
  212. data/spec/unit/ogr/feature_spec.rb +30 -46
  213. data/spec/unit/ogr/geometries/geometry_collection_25d_spec.rb +23 -0
  214. data/spec/unit/ogr/geometries/geometry_collection_spec.rb +3 -3
  215. data/spec/unit/ogr/geometries/line_string_25d_spec.rb +23 -0
  216. data/spec/unit/ogr/geometries/line_string_spec.rb +2 -2
  217. data/spec/unit/ogr/geometries/linear_ring_spec.rb +2 -2
  218. data/spec/unit/ogr/geometries/multi_line_string_25d_spec.rb +23 -0
  219. data/spec/unit/ogr/geometries/multi_point_25d_spec.rb +23 -0
  220. data/spec/unit/ogr/geometries/multi_polygon_25d_spec.rb +23 -0
  221. data/spec/unit/ogr/geometries/point_25d_spec.rb +23 -0
  222. data/spec/unit/ogr/geometries/point_spec.rb +14 -24
  223. data/spec/unit/ogr/geometries/polygon_25d_spec.rb +23 -0
  224. data/spec/unit/ogr/geometries/polygon_spec.rb +1 -1
  225. data/spec/unit/ogr/geometry_field_definition_spec.rb +1 -1
  226. data/spec/unit/ogr/geometry_spec.rb +196 -30
  227. data/spec/unit/ogr/internal_helpers_spec.rb +20 -9
  228. data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +14 -6
  229. data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +9 -1
  230. data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +2 -1
  231. data/spec/unit/ogr/style_table_spec.rb +1 -1
  232. data/tmp/.keep +0 -0
  233. metadata +121 -19
  234. data/examples/points.txt +0 -127
  235. data/lib/gdal/grid_types.rb +0 -22
  236. data/lib/ogr/geometries/point_extensions.rb +0 -32
  237. data/lib/ogr/geometry_extensions.rb +0 -59
@@ -3,6 +3,18 @@ require 'json'
3
3
  module GDAL
4
4
  module RasterAttributeTableMixins
5
5
  module Extensions
6
+ # @param row [Fixnum]
7
+ # @param field [Fixnum]
8
+ # @param value [String, Float, Fixnum]
9
+ def set_value(row, field, value)
10
+ case value.class
11
+ when String then set_value_as_string(row, field, value)
12
+ when Float then set_value_as_double(row, field, value)
13
+ when Fixnum then set_value_as_integer(row, field, value)
14
+ else raise GDAL::UnknownRasterAttributeTableType, "Unknown value type for value '#{value}'"
15
+ end
16
+ end
17
+
6
18
  # Get +column_name+, +column_usage+, +column_type+ as a Hash.
7
19
  #
8
20
  # @param index [Fixnum]
@@ -17,9 +29,15 @@ module GDAL
17
29
 
18
30
  # @return [Array<Hash>]
19
31
  def columns
20
- column_count.times.map do |i|
21
- column(i)
22
- end
32
+ each_column.to_a
33
+ end
34
+
35
+ # @return [Enumerator]
36
+ # @yieldparam [Hash]
37
+ def each_column
38
+ return enum_for(:each_column) unless block_given?
39
+
40
+ column_count.times { |i| yield column(i) }
23
41
  end
24
42
 
25
43
  # @return [Hash]
@@ -1,18 +1,21 @@
1
- require_relative '../ffi/gdal'
2
- require_relative '../ffi/ogr/api'
1
+ require 'narray'
2
+ require_relative '../gdal'
3
+ require_relative 'raster_band_mixins/algorithm_extensions'
3
4
  require_relative 'raster_band_mixins/algorithm_methods'
5
+ require_relative 'raster_band_mixins/coloring_extensions'
4
6
  require_relative 'raster_band_mixins/extensions'
5
- require_relative 'color_table'
7
+ require_relative 'raster_band_mixins/io_extensions'
6
8
  require_relative 'major_object'
7
- require_relative 'raster_attribute_table'
8
- require 'narray'
9
9
 
10
10
  module GDAL
11
11
  class RasterBand
12
12
  include MajorObject
13
13
  include GDAL::Logger
14
14
  include RasterBandMixins::AlgorithmMethods
15
+ include RasterBandMixins::AlgorithmExtensions
16
+ include RasterBandMixins::ColoringExtensions
15
17
  include RasterBandMixins::Extensions
18
+ include RasterBandMixins::IOExtensions
16
19
 
17
20
  ALL_VALID = 0x01
18
21
  PER_DATASET = 0x02
@@ -29,28 +32,28 @@ module GDAL
29
32
 
30
33
  # @return [Boolean]
31
34
  def flush_cache
32
- !!FFI::GDAL.GDALFlushRasterCache(@c_pointer)
35
+ !!FFI::GDAL::GDAL.GDALFlushRasterCache(@c_pointer)
33
36
  end
34
37
 
35
38
  # The raster width in pixels.
36
39
  #
37
40
  # @return [Fixnum]
38
41
  def x_size
39
- FFI::GDAL.GDALGetRasterBandXSize(@c_pointer)
42
+ FFI::GDAL::GDAL.GDALGetRasterBandXSize(@c_pointer)
40
43
  end
41
44
 
42
45
  # The raster height in pixels.
43
46
  #
44
47
  # @return [Fixnum]
45
48
  def y_size
46
- FFI::GDAL.GDALGetRasterBandYSize(@c_pointer)
49
+ FFI::GDAL::GDAL.GDALGetRasterBandYSize(@c_pointer)
47
50
  end
48
51
 
49
52
  # The type of access to the raster band this object currently has.
50
53
  #
51
54
  # @return [Symbol] Either :GA_Update or :GA_ReadOnly.
52
55
  def access_flag
53
- FFI::GDAL.GDALGetRasterAccess(@c_pointer)
56
+ FFI::GDAL::GDAL.GDALGetRasterAccess(@c_pointer)
54
57
  end
55
58
 
56
59
  # The number of band within the associated dataset that this band
@@ -58,50 +61,55 @@ module GDAL
58
61
  #
59
62
  # @return [Fixnum]
60
63
  def number
61
- FFI::GDAL.GDALGetBandNumber(@c_pointer)
64
+ FFI::GDAL::GDAL.GDALGetBandNumber(@c_pointer)
62
65
  end
63
66
 
64
67
  # @return [GDAL::Dataset, nil]
65
- def dataset
68
+ def dataset(access_flag = 'r')
66
69
  return @dataset if @dataset
67
70
 
68
- dataset_ptr = FFI::GDAL.GDALGetBandDataset(@c_pointer)
71
+ dataset_ptr = FFI::GDAL::GDAL.GDALGetBandDataset(@c_pointer)
69
72
  return nil if dataset_ptr.null?
70
73
 
71
- @dataset = GDAL::Dataset.new(dataset_ptr)
74
+ @dataset = GDAL::Dataset.new(dataset_ptr, access_flag, true)
72
75
  end
73
76
 
74
- # @return [Symbol] One of FFI::GDAL::ColorInterp.
77
+ # @return [Symbol] One of FFI::GDAL::GDAL::ColorInterp.
75
78
  def color_interpretation
76
- FFI::GDAL.GDALGetRasterColorInterpretation(@c_pointer)
79
+ FFI::GDAL::GDAL.GDALGetRasterColorInterpretation(@c_pointer)
77
80
  end
78
81
 
79
- # @param new_color_interp [FFI::GDAL::ColorInterp]
82
+ # @param new_color_interp [FFI::GDAL::GDAL::ColorInterp]
80
83
  # @return [Boolean]
81
84
  def color_interpretation=(new_color_interp)
82
- !!FFI::GDAL.GDALSetRasterColorInterpretation(@c_pointer,
85
+ !!FFI::GDAL::GDAL.GDALSetRasterColorInterpretation(@c_pointer,
83
86
  new_color_interp)
84
87
  end
85
88
 
89
+ # Gets the associated GDAL::ColorTable. Note that it remains owned by the
90
+ # RasterBand and cannot be modified.
91
+ #
86
92
  # @return [GDAL::ColorTable]
87
93
  def color_table
88
- gdal_color_table = FFI::GDAL.GDALGetRasterColorTable(@c_pointer)
89
- return nil if gdal_color_table.null?
94
+ color_table_ptr = FFI::GDAL::GDAL.GDALGetRasterColorTable(@c_pointer)
95
+ color_table_ptr.autorelease = false
90
96
 
91
- ColorTable.new(gdal_color_table)
97
+ return nil if color_table_ptr.null?
98
+
99
+ ColorTable.new(color_table_ptr)
92
100
  end
93
101
 
94
102
  # @param new_color_table [GDAL::ColorTable]
95
103
  def color_table=(new_color_table)
96
104
  color_table_pointer = GDAL._pointer(GDAL::ColorTable, new_color_table)
97
- FFI::GDAL.GDALSetRasterColorTable(@c_pointer, color_table_pointer)
105
+ FFI::GDAL::GDAL.GDALSetRasterColorTable(@c_pointer, color_table_pointer)
98
106
  end
99
107
 
100
108
  # The pixel data type for this band.
101
109
  #
102
- # @return [Symbol] One of FFI::GDAL::DataType.
110
+ # @return [Symbol] One of FFI::GDAL::GDAL::DataType.
103
111
  def data_type
104
- FFI::GDAL.GDALGetRasterDataType(@c_pointer)
112
+ FFI::GDAL::GDAL.GDALGetRasterDataType(@c_pointer)
105
113
  end
106
114
 
107
115
  # The natural block size is the block size that is most efficient for
@@ -112,14 +120,14 @@ module GDAL
112
120
  def block_size
113
121
  x_pointer = FFI::MemoryPointer.new(:int)
114
122
  y_pointer = FFI::MemoryPointer.new(:int)
115
- FFI::GDAL.GDALGetBlockSize(@c_pointer, x_pointer, y_pointer)
123
+ FFI::GDAL::GDAL.GDALGetBlockSize(@c_pointer, x_pointer, y_pointer)
116
124
 
117
125
  { x: x_pointer.read_int, y: y_pointer.read_int }
118
126
  end
119
127
 
120
128
  # @return [Array<String>]
121
129
  def category_names
122
- names = FFI::GDAL.GDALGetRasterCategoryNames(@c_pointer)
130
+ names = FFI::GDAL::GDAL.GDALGetRasterCategoryNames(@c_pointer)
123
131
  return [] if names.null?
124
132
 
125
133
  names.get_array_of_string(0)
@@ -130,7 +138,7 @@ module GDAL
130
138
  def category_names=(names)
131
139
  names_pointer = GDAL._string_array_to_pointer(names)
132
140
 
133
- !!FFI::GDAL.GDALSetRasterCategoryNames(@c_pointer, names_pointer)
141
+ !!FFI::GDAL::GDAL.GDALSetRasterCategoryNames(@c_pointer, names_pointer)
134
142
  end
135
143
 
136
144
  # The no data value for a band is generally a special marker value used to
@@ -140,7 +148,7 @@ module GDAL
140
148
  # @return [Hash{value => Float, is_associated => Boolean}]
141
149
  def no_data_value
142
150
  associated = FFI::MemoryPointer.new(:bool)
143
- value = FFI::GDAL.GDALGetRasterNoDataValue(@c_pointer, associated)
151
+ value = FFI::GDAL::GDAL.GDALGetRasterNoDataValue(@c_pointer, associated)
144
152
 
145
153
  { value: value, is_associated: associated.read_bytes(1).to_bool }
146
154
  end
@@ -150,17 +158,17 @@ module GDAL
150
158
  # @param value [Float]
151
159
  # @return [Boolean]
152
160
  def no_data_value=(value)
153
- !!FFI::GDAL.GDALSetRasterNoDataValue(@c_pointer, value)
161
+ !!FFI::GDAL::GDAL.GDALSetRasterNoDataValue(@c_pointer, value)
154
162
  end
155
163
 
156
164
  # @return [Fixnum]
157
165
  def overview_count
158
- FFI::GDAL.GDALGetOverviewCount(@c_pointer)
166
+ FFI::GDAL::GDAL.GDALGetOverviewCount(@c_pointer)
159
167
  end
160
168
 
161
169
  # @return [Boolean]
162
170
  def arbitrary_overviews?
163
- FFI::GDAL.GDALHasArbitraryOverviews(@c_pointer).zero? ? false : true
171
+ FFI::GDAL::GDAL.GDALHasArbitraryOverviews(@c_pointer).zero? ? false : true
164
172
  end
165
173
 
166
174
  # @param index [Fixnum] Must be between 0 and (#overview_count - 1).
@@ -168,18 +176,23 @@ module GDAL
168
176
  def overview(index)
169
177
  return nil if overview_count.zero?
170
178
 
171
- overview_pointer = FFI::GDAL.GDALGetOverview(@c_pointer, index)
179
+ overview_pointer = FFI::GDAL::GDAL.GDALGetOverview(@c_pointer, index)
172
180
  return nil if overview_pointer.null?
173
181
 
174
182
  self.class.new(overview_pointer)
175
183
  end
176
184
 
185
+ # Returns the most reduced overview of this RasterBand that still satisfies
186
+ # the deisred number of samples. Using 0 fetches the most reduced overview.
187
+ # If the band doesn't have any overviews or none of the overviews have
188
+ # enough samples, it will return the same band.
189
+ #
177
190
  # @param desired_samples [Fixnum] The returned band will have at least this
178
191
  # many pixels.
179
192
  # @return [GDAL::RasterBand] An optimal overview or the same raster band if
180
193
  # the raster band has no overviews.
181
194
  def raster_sample_overview(desired_samples = 0)
182
- band_pointer = FFI::GDAL.GDALGetRasterSampleOverview(@c_pointer, desired_samples)
195
+ band_pointer = FFI::GDAL::GDAL.GDALGetRasterSampleOverview(@c_pointer, desired_samples)
183
196
  return nil if band_pointer.null?
184
197
 
185
198
  self.class.new(band_pointer)
@@ -187,7 +200,7 @@ module GDAL
187
200
 
188
201
  # @return [GDAL::RasterBand]
189
202
  def mask_band
190
- band_pointer = FFI::GDAL.GDALGetMaskBand(@c_pointer)
203
+ band_pointer = FFI::GDAL::GDAL.GDALGetMaskBand(@c_pointer)
191
204
  return nil if band_pointer.null?
192
205
 
193
206
  self.class.new(band_pointer)
@@ -195,17 +208,19 @@ module GDAL
195
208
 
196
209
  # @return [Array<Symbol>]
197
210
  def mask_flags
198
- flag_list = FFI::GDAL.GDALGetMaskFlags(@c_pointer).to_s(2).scan(/\d/)
211
+ flag_list = FFI::GDAL::GDAL.GDALGetMaskFlags(@c_pointer).to_s(2).scan(/\d/)
199
212
  flags = []
200
213
 
201
- flag_list.reverse.each_with_index do |flag, i|
202
- if i == 0 && flag.to_i == 1
214
+ flag_list.reverse_each.with_index do |flag, i|
215
+ flag = flag.to_i
216
+
217
+ if i == 0 && flag == 1
203
218
  flags << :GMF_ALL_VALID
204
- elsif i == 1 && flag.to_i == 1
219
+ elsif i == 1 && flag == 1
205
220
  flags << :GMF_PER_DATASET
206
- elsif i == 2 && flag.to_i == 1
221
+ elsif i == 2 && flag == 1
207
222
  flags << :GMF_ALPHA
208
- elsif i == 3 && flag.to_i == 1
223
+ elsif i == 3 && flag == 1
209
224
  flags << :GMF_NODATA
210
225
  end
211
226
  end
@@ -213,9 +228,22 @@ module GDAL
213
228
  flags
214
229
  end
215
230
 
231
+ # @param flags [Array<Symbol>, Symbol] Any of the :GMF symbols.
216
232
  # @return [Boolean]
217
- def create_mask_band(flags)
218
- !!FFI::GDAL.GDALCreateMaskBand(@c_pointer, flags)
233
+ def create_mask_band(*flags)
234
+ flag_value = 0
235
+
236
+ flag_value = flags.each_with_object(flag_value) do |flag, result|
237
+ result + case flag
238
+ when :GMF_ALL_VALID then 0x01
239
+ when :GMF_PER_DATASET then 0x02
240
+ when :GMF_PER_ALPHA then 0x04
241
+ when :GMF_NODATA then 0x08
242
+ else 0
243
+ end
244
+ end
245
+
246
+ !!FFI::GDAL::GDAL.GDALCreateMaskBand(@c_pointer, flag_value)
219
247
  end
220
248
 
221
249
  # Fill this band with constant value. Useful for clearing a band and
@@ -224,7 +252,7 @@ module GDAL
224
252
  # @param real_value [Float]
225
253
  # @param imaginary_value [Float]
226
254
  def fill(real_value, imaginary_value = 0)
227
- !!FFI::GDAL.GDALFillRaster(@c_pointer, real_value, imaginary_value)
255
+ !!FFI::GDAL::GDAL.GDALFillRaster(@c_pointer, real_value, imaginary_value)
228
256
  end
229
257
 
230
258
  # Returns minimum, maximum, mean, and standard deviation of all pixel values
@@ -254,7 +282,7 @@ module GDAL
254
282
  end
255
283
 
256
284
  handler.custom_handle do
257
- FFI::GDAL.GDALGetRasterStatistics(@c_pointer,
285
+ FFI::GDAL::GDAL.GDALGetRasterStatistics(@c_pointer,
258
286
  approx_ok,
259
287
  force,
260
288
  min,
@@ -274,7 +302,7 @@ module GDAL
274
302
  mean_ptr = FFI::MemoryPointer.new(:double)
275
303
  standard_deviation_ptr = FFI::MemoryPointer.new(:double)
276
304
 
277
- FFI::GDAL::GDALComputeRasterStatistics(
305
+ FFI::GDAL::GDAL::GDALComputeRasterStatistics(
278
306
  @c_pointer, # hBand
279
307
  approx_ok, # bApproxOK
280
308
  min_ptr, # pdfMin
@@ -306,7 +334,7 @@ module GDAL
306
334
  # @return [Hash{value => Float, is_meaningful => Boolean}]
307
335
  def scale
308
336
  meaningful = FFI::MemoryPointer.new(:bool)
309
- result = FFI::GDAL.GDALGetRasterScale(@c_pointer, meaningful)
337
+ result = FFI::GDAL::GDAL.GDALGetRasterScale(@c_pointer, meaningful)
310
338
 
311
339
  { value: result, is_meaningful: meaningful.read_bytes(1).to_bool }
312
340
  end
@@ -314,7 +342,7 @@ module GDAL
314
342
  # @param new_scale [Float]
315
343
  # @return [Boolean]
316
344
  def scale=(new_scale)
317
- !!FFI::GDAL.GDALSetRasterScale(@c_pointer, new_scale.to_f)
345
+ !!FFI::GDAL::GDAL.GDALSetRasterScale(@c_pointer, new_scale.to_f)
318
346
  end
319
347
 
320
348
  # This value (in combination with the #scale value) is used to
@@ -330,28 +358,30 @@ module GDAL
330
358
  # @return [Hash{value => Float, is_meaningful => Boolean}]
331
359
  def offset
332
360
  meaningful = FFI::MemoryPointer.new(:bool)
333
- result = FFI::GDAL.GDALGetRasterOffset(@c_pointer, meaningful)
361
+ result = FFI::GDAL::GDAL.GDALGetRasterOffset(@c_pointer, meaningful)
334
362
 
335
363
  { value: result, is_meaningful: meaningful.read_bytes(1).to_bool }
336
364
  end
337
365
 
366
+ # Sets the scaling offset. Very few formats support this method.
367
+ #
338
368
  # @param new_offset [Float]
339
369
  # @return [Boolean]
340
370
  def offset=(new_offset)
341
- !!FFI::GDAL.GDALSetRasterOffset(@c_pointer, new_offset)
371
+ !!FFI::GDAL::GDAL.GDALSetRasterOffset(@c_pointer, new_offset)
342
372
  end
343
373
 
344
374
  # @return [String]
345
375
  def unit_type
346
- FFI::GDAL.GDALGetRasterUnitType(@c_pointer)
376
+ FFI::GDAL::GDAL.GDALGetRasterUnitType(@c_pointer)
347
377
  end
348
378
 
349
379
  # @param new_unit_type [String] "" indicates unknown, "m" is meters, "ft"
350
380
  # is feet; other non-standard values are allowed.
351
381
  # @return [Boolean]
352
382
  def unit_type=(new_unit_type)
353
- if defined? FFI::GDAL::GDALSetRasterUnitType
354
- !!FFI::GDAL.GDALSetRasterUnitType(@c_pointer, new_unit_type)
383
+ if defined? FFI::GDAL::GDAL::GDALSetRasterUnitType
384
+ !!FFI::GDAL::GDAL.GDALSetRasterUnitType(@c_pointer, new_unit_type)
355
385
  else
356
386
  warn "GDALSetRasterUnitType is not defined. Can't call RasterBand#unit_type="
357
387
  end
@@ -359,7 +389,7 @@ module GDAL
359
389
 
360
390
  # @return [GDAL::RasterAttributeTable]
361
391
  def default_raster_attribute_table
362
- rat_pointer = FFI::GDAL.GDALGetDefaultRAT(@c_pointer)
392
+ rat_pointer = FFI::GDAL::GDAL.GDALGetDefaultRAT(@c_pointer)
363
393
  return nil if rat_pointer.null?
364
394
 
365
395
  GDAL::RasterAttributeTable.new(rat_pointer)
@@ -368,7 +398,7 @@ module GDAL
368
398
  # @return [GDAL::RasterAttributeTable]
369
399
  def default_raster_attribute_table=(rat_table)
370
400
  rat_table_ptr = GDAL._pointer(GDAL::RasterAttributeTable, rat_table)
371
- FFI::GDAL.GDALSetDefaultRAT(@c_pointer, rat_table_ptr)
401
+ FFI::GDAL::GDAL.GDALSetDefaultRAT(@c_pointer, rat_table_ptr)
372
402
  end
373
403
 
374
404
  # Gets the default raster histogram. Results are returned as a Hash so some
@@ -399,7 +429,7 @@ module GDAL
399
429
  # }
400
430
  #
401
431
  # Also, you can pass a block to get status on the processing. Conforms to
402
- # FFI::GDAL::GDALProgressFunc.
432
+ # FFI::GDAL::GDAL::GDALProgressFunc.
403
433
  #
404
434
  # @param force [Boolean] Forces the computation of the histogram. If
405
435
  # +false+ and the default histogram isn't available, this returns nil.
@@ -441,7 +471,7 @@ module GDAL
441
471
  end
442
472
 
443
473
  handler.custom_handle do
444
- FFI::GDAL.GDALGetDefaultHistogram(
474
+ FFI::GDAL::GDAL.GDALGetDefaultHistogram(
445
475
  @c_pointer,
446
476
  min_pointer,
447
477
  max_pointer,
@@ -457,10 +487,13 @@ module GDAL
457
487
  # Computes a histogram using the given inputs. If you just want the default
458
488
  # histogram, use #default_histogram.
459
489
  #
460
- # @param min [Float]
461
- # @param max [Float]
490
+ # @param min [Float] The lower bound of the histogram.
491
+ # @param max [Float] The upper bound of the histogram.
462
492
  # @param buckets [Fixnum]
463
- # @param include_out_of_range [Boolean]
493
+ # @param include_out_of_range [Boolean] If +true+, values below the
494
+ # histogram range will be mapped into the first bucket of the output
495
+ # data; values above the range will be mapped into the last bucket. If
496
+ # +false+, values outside of the range will be discarded.
464
497
  # @param approx_ok [Boolean]
465
498
  # @param block [Proc] No required, but can be used to output progress info
466
499
  # during processing.
@@ -495,7 +528,7 @@ module GDAL
495
528
  end
496
529
 
497
530
  handler.custom_handle do
498
- FFI::GDAL.GDALGetRasterHistogram(@c_pointer,
531
+ FFI::GDAL::GDAL.GDALGetRasterHistogram(@c_pointer,
499
532
  min.to_f,
500
533
  max.to_f,
501
534
  buckets,
@@ -524,93 +557,13 @@ module GDAL
524
557
  destination_pointer = GDAL._pointer(GDAL::RasterBand, destination_band)
525
558
  options_ptr = GDAL::Options.pointer(options)
526
559
 
527
- !!FFI::GDAL.GDALRasterBandCopyWholeRaster(@c_pointer,
560
+ !!FFI::GDAL::GDAL.GDALRasterBandCopyWholeRaster(@c_pointer,
528
561
  destination_pointer,
529
562
  options_ptr,
530
563
  progress,
531
564
  nil)
532
565
  end
533
566
 
534
- # Reads the raster line-by-line and returns as an NArray. Will yield each
535
- # line and the line number if a block is given.
536
- #
537
- # @yieldparam pixel_line [Array]
538
- # @yieldparam line_number [Fixnum]
539
- # @return [NArray]
540
- # TODO: Extract RasterIO to separate function.
541
- def readlines(data_type: :GDT_Byte)
542
- x_offset = 0
543
- line_size = 1
544
- pixel_space = 0
545
- line_space = 0
546
- scan_line = GDAL._pointer_from_data_type(data_type, x_size)
547
-
548
- the_array = y_size.times.map do |y|
549
- FFI::GDAL.GDALRasterIO(
550
- @c_pointer,
551
- :GF_Read,
552
- x_offset,
553
- y,
554
- x_size,
555
- line_size,
556
- scan_line,
557
- x_size,
558
- line_size,
559
- data_type,
560
- pixel_space,
561
- line_space
562
- )
563
-
564
- line_array = if data_type == :GDT_Byte
565
- scan_line.read_array_of_uint8(x_size)
566
- else
567
- scan_line.read_array_of_float(x_size)
568
- end
569
-
570
- yield(line_array, y) if block_given?
571
-
572
- line_array
573
- end
574
-
575
- NArray.to_na(the_array)
576
- end
577
-
578
- # Writes an NArray of pixels to the raster band using {#raster_io}. It
579
- # determines +x_size+ and +y_size+ for the {#raster_io} call using the
580
- # dimensions of the array.
581
- #
582
- # @param pixel_array [NArray] The 2d list of pixels.
583
- # @param x_offset [Fixnum] The left-most pixel to start writing.
584
- # @param y_offset [Fixnum] The top-most line to start writing.
585
- # @param buffer_data_type [FFI::GDAL::DataType] The type of pixel contained in
586
- # the +pixel_array+.
587
- # @param line_space [Fixnum]
588
- # @param pixel_space [Fixnum]
589
- # TODO: Write using #buffer_size to write most efficiently.
590
- def write_array(pixel_array, x_offset: 0, y_offset: 0, x_size: nil, y_size: nil,
591
- buffer_x_size: nil, buffer_y_size: nil, buffer_data_type: data_type,
592
- line_space: 0, pixel_space: 0)
593
- x_size ||= pixel_array.sizes.first
594
- y_size ||= pixel_array.sizes.last
595
-
596
- columns_to_write = x_size - x_offset
597
- lines_to_write = y_size - y_offset
598
- scan_line = GDAL._pointer_from_data_type(buffer_data_type, columns_to_write * lines_to_write)
599
-
600
- (y_offset).upto(lines_to_write - 1) do |line_number|
601
- pixels = pixel_array[true, line_number]
602
- ffi_type = GDAL._gdal_data_type_to_ffi(buffer_data_type)
603
- meth = "write_array_of_#{ffi_type}".to_sym
604
- scan_line.send(meth, pixels.to_a)
605
-
606
- raster_io('w', scan_line, x_size: x_size, y_size: 1, x_offset: x_offset, y_offset: line_number,
607
- buffer_x_size: x_size, buffer_y_size: line_number, buffer_data_type: buffer_data_type,
608
- pixel_space: pixel_space, line_space: line_space)
609
- end
610
-
611
- flush_cache
612
- end
613
-
614
567
  # IO access for raster data in this band. Default values are set up to
615
568
  # operate on one line at a time, keeping the same aspect ratio.
616
569
  #
@@ -621,34 +574,35 @@ module GDAL
621
574
  # On +pixel_space+ and +line_space+.... These values control how data is
622
575
  # organized in the buffer.
623
576
  #
624
- # @param [Symbol] access_flag Must be 'r' or 'w'.
625
- # @param [FFI::MemoryPointer] buffer Allows for passing in your own buffer,
577
+ # @param access_flag [Symbol] Must be 'r' or 'w'.
578
+ # @param buffer [FFI::MemoryPointer] Allows for passing in your own buffer,
626
579
  # which is really only useful when writing.
627
- # @param [Fixnum] x_size The number of pixels per line to operate on.
628
- # Defaults to the value of {#x_size} - +x_offset+.
629
- # @param [Fixnum] y_size The number of lines to operate on. Defaults to 1.
630
- # @param [Fixnum] x_offset The pixel number in the line to start operating
580
+ # @param x_size [Fixnum] The number of pixels per line to operate on.
581
+ # Defaults to the value of {{#x_size}}.
582
+ # @param y_size [Fixnum] The number of lines to operate on. Defaults to the
583
+ # value of {{#y_size}}.
584
+ # @param x_offset [Fixnum] The pixel number in the line to start operating
631
585
  # on. Note that when using this, {#x_size} - +x_offset+ should be >= 0,
632
586
  # otherwise this means you're telling the method to read past the end of
633
587
  # the line. Defaults to 0.
634
- # @param [Fixnum] y_offset The line number to start operating on. Note that
588
+ # @param y_offset [Fixnum] The line number to start operating on. Note that
635
589
  # when using this, {#y_size} - +y_offset+ should be >= 0, otherwise this
636
590
  # means you're telling the method to read more lines than the raster has.
637
591
  # Defaults to 0.
638
- # @param [Fixnum] buffer_x_size The width of the buffer image in which to
592
+ # @param buffer_x_size [Fixnum] The width of the buffer image in which to
639
593
  # read/write the raster data into/from. Typically this should be the same
640
594
  # size as +x_size+; if it's different, GDAL will resample accordingly.
641
- # @param [Fixnum] buffer_y_size The height of the buffer image in which to
595
+ # @param buffer_y_size [Fixnum] The height of the buffer image in which to
642
596
  # read/write the raster data into/from. Typically this should be the same
643
597
  # size as +y_size+; if it's different, GDAL will resample accordingly.
644
- # @param [FFI::GDAL::DataType] buffer_data_type Can be used to convert the
598
+ # @param buffer_data_type [FFI::GDAL::GDAL::DataType] Can be used to convert the
645
599
  # data to a different type. You must account for this when reading/writing
646
600
  # to/from your buffer--your buffer size must be +buffer_x_size+ *
647
- # +buffer_y_size+. Defaults to {#data_type}.
648
- # @param [Fixnum] pixel_space The byte offset from the start of one pixel
601
+ # +buffer_y_size+. Defaults to {{#data_type}}.
602
+ # @param pixel_space [Fixnum] The byte offset from the start of one pixel
649
603
  # value in the buffer to the start of the next pixel value within a line.
650
604
  # If defaulted (0), the size of +buffer_data_type+ is used.
651
- # @param [Fixnum] line_space The byte offset from the start of one line in
605
+ # @param line_space [Fixnum] The byte offset from the start of one line in
652
606
  # the buffer to the start of the next. If defaulted (0), the size of
653
607
  # +buffer_data_type+ * +buffer_x_size* is used.
654
608
  # @return [FFI::MemoryPointer] Pointer to the data that was read/written.
@@ -656,16 +610,16 @@ module GDAL
656
610
  x_size: nil, y_size: nil, x_offset: 0, y_offset: 0,
657
611
  buffer_x_size: nil, buffer_y_size: nil, buffer_data_type: data_type,
658
612
  pixel_space: 0, line_space: 0)
613
+ return unless @c_pointer
614
+
659
615
  x_size ||= self.x_size
660
616
  y_size ||= self.y_size
661
- pixels_to_io = x_size - x_offset
662
- lines_to_io = y_size - y_offset
663
617
 
664
- buffer_x_size ||= pixels_to_io
665
- buffer_y_size ||= lines_to_io
618
+ buffer_x_size ||= x_size
619
+ buffer_y_size ||= y_size
666
620
  buffer ||= GDAL._pointer_from_data_type(buffer_data_type, buffer_x_size * buffer_y_size)
667
621
 
668
- FFI::GDAL.GDALRasterIO(
622
+ FFI::GDAL::GDAL.GDALRasterIO(
669
623
  @c_pointer,
670
624
  GDAL._gdal_access_flag(access_flag),
671
625
  x_offset,
@@ -686,25 +640,43 @@ module GDAL
686
640
  # Read a block of image data, more efficiently than #read. Doesn't
687
641
  # resample or do data type conversion.
688
642
  #
689
- # @param x_offset [Fixnum] The horizontal block offset, with 0 indicating
643
+ # @param x_block_number [Fixnum] The horizontal block offset, with 0 indicating
690
644
  # the left-most block, 1 the next block, etc.
691
- # @param y_offset [Fixnum] The vertical block offset, with 0 indicating the
645
+ # @param y_block_number [Fixnum] The vertical block offset, with 0 indicating the
692
646
  # top-most block, 1 the next block, etc.
693
- # @return [FFI::MemoryPointer] The image buffer.
694
- def read_block(x_offset, y_offset, image_buffer = nil)
695
- image_buffer ||= FFI::MemoryPointer.new(:void)
647
+ # @param image_buffer [FFI::Pointer] Optional pointer to use for reading
648
+ # the data into. If not provided, one will be created and returned.
649
+ # @return [FFI::MemoryPointer] The image buffer that contains the read data.
650
+ # If you passed in +image_buffer+ you don't need to bother with this
651
+ # return value since that original buffer will contain the data.
652
+ def read_block(x_block_number, y_block_number, image_buffer = nil)
653
+ image_buffer ||= FFI::MemoryPointer.new(:buffer_out, block_buffer_size)
696
654
 
697
- FFI::GDAL.GDALReadBlock(@c_pointer, x_offset, y_offset, image_buffer)
655
+ FFI::GDAL::GDAL.GDALReadBlock(@c_pointer, x_block_number, y_block_number, image_buffer)
698
656
 
699
657
  image_buffer
700
658
  end
701
659
 
660
+ # @param x_block_number [Fixnum] The horizontal block offset, with 0 indicating
661
+ # the left-most block, 1 the next block, etc.
662
+ # @param y_block_number [Fixnum] The vertical block offset, with 0 indicating the
663
+ # top-most block, 1 the next block, etc.
664
+ # @param data_pointer [FFI::Pointer] Optional pointer to write the data to.
665
+ # If not provided, one will be created and returned.
666
+ def write_block(x_block_number, y_block_number, data_pointer = nil)
667
+ data_pointer ||= FFI::Buffer.alloc_inout(block_buffer_size)
668
+
669
+ FFI::GDAL::GDAL.GDALWriteBlock(@c_pointer, x_block_number, y_block_number, data_pointer)
670
+
671
+ data_pointer
672
+ end
673
+
702
674
  # The minimum and maximum values for this band.
703
675
  #
704
676
  # @return [Hash{min => Float, max => Float}]
705
677
  def min_max(approx_ok: false)
706
678
  min_max = FFI::MemoryPointer.new(:double, 2)
707
- FFI::GDAL.GDALComputeRasterMinMax(@c_pointer, approx_ok, min_max)
679
+ FFI::GDAL::GDAL.GDALComputeRasterMinMax(@c_pointer, approx_ok, min_max)
708
680
 
709
681
  { min: min_max[0].read_double, max: min_max[1].read_double }
710
682
  end
@@ -717,7 +689,7 @@ module GDAL
717
689
  # tells whether the minimum is a tight minimum.
718
690
  def minimum_value
719
691
  is_tight = FFI::MemoryPointer.new(:bool)
720
- value = FFI::GDAL.GDALGetRasterMinimum(@c_pointer, is_tight)
692
+ value = FFI::GDAL::GDAL.GDALGetRasterMinimum(@c_pointer, is_tight)
721
693
 
722
694
  { value: value, is_tight: is_tight.read_bytes(1).to_bool }
723
695
  end
@@ -730,7 +702,7 @@ module GDAL
730
702
  # tells whether the maximum is a tight maximum.
731
703
  def maximum_value
732
704
  is_tight = FFI::MemoryPointer.new(:bool)
733
- value = FFI::GDAL.GDALGetRasterMaximum(@c_pointer, is_tight)
705
+ value = FFI::GDAL::GDAL.GDALGetRasterMaximum(@c_pointer, is_tight)
734
706
 
735
707
  { value: value, is_tight: is_tight.read_bytes(1).to_bool }
736
708
  end