ffi-gdal 1.0.0.beta16 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (324) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +17 -0
  3. data/.github/workflows/codacy.yml +61 -0
  4. data/.github/workflows/codeql.yml +74 -0
  5. data/.github/workflows/continuous-integration.yml +36 -0
  6. data/.github/workflows/dependency-review.yml +20 -0
  7. data/.github/workflows/specs-in-docker.yml +27 -0
  8. data/.gitignore +3 -0
  9. data/.rspec +1 -0
  10. data/.rubocop.yml +10 -80
  11. data/.rubocop_todo.yml +23 -40
  12. data/.ruby-version +1 -1
  13. data/Changelog-0.x.md +512 -0
  14. data/Changelog.md +12 -0
  15. data/Dockerfile.gdal2 +110 -0
  16. data/Dockerfile.gdal3 +73 -0
  17. data/README.md +25 -14
  18. data/Rakefile +0 -8
  19. data/Tiltfile +91 -0
  20. data/bin/bundle +123 -0
  21. data/bin/docker-clean +8 -0
  22. data/bin/rake +29 -0
  23. data/bin/rspec +29 -0
  24. data/bin/rubocop +29 -0
  25. data/docker-compose.yml +25 -0
  26. data/examples/extract_and_colorize.rb +0 -13
  27. data/examples/geometries.rb +14 -14
  28. data/examples/ogr_layer_to_layer.rb +1 -3
  29. data/examples/raster_erasing.rb +1 -0
  30. data/examples/remove_small_polygons.rb +1 -1
  31. data/examples/testing_gdal.rb +20 -17
  32. data/examples/warping.rb +9 -7
  33. data/ffi-gdal.gemspec +12 -6
  34. data/lib/ext/ffi_library_function_checks.rb +2 -2
  35. data/lib/ext/to_bool.rb +5 -3
  36. data/lib/ffi/cpl/conv.rb +27 -25
  37. data/lib/ffi/cpl/error.rb +19 -20
  38. data/lib/ffi/cpl/hash_set.rb +4 -4
  39. data/lib/ffi/cpl/http.rb +3 -3
  40. data/lib/ffi/cpl/http_result.rb +8 -8
  41. data/lib/ffi/cpl/list.rb +1 -1
  42. data/lib/ffi/cpl/mime_part.rb +2 -2
  43. data/lib/ffi/cpl/minixml.rb +7 -7
  44. data/lib/ffi/cpl/progress.rb +8 -8
  45. data/lib/ffi/cpl/quad_tree.rb +14 -14
  46. data/lib/ffi/cpl/rect_obj.rb +3 -3
  47. data/lib/ffi/cpl/string.rb +17 -20
  48. data/lib/ffi/cpl/vsi.rb +13 -13
  49. data/lib/ffi/cpl/xml_node.rb +3 -3
  50. data/lib/ffi/extensions/gdal/extensions/all.rb +4 -0
  51. data/lib/ffi/extensions/gdal/extensions/version.rb +9 -0
  52. data/lib/ffi/extensions/gdal/extensions.rb +12 -0
  53. data/lib/ffi/extensions/rttopo/gbox.rb +19 -0
  54. data/lib/ffi/extensions/rttopo/geom.rb +16 -0
  55. data/lib/ffi/extensions/rttopo.rb +41 -0
  56. data/lib/ffi/gdal/alg.rb +277 -277
  57. data/lib/ffi/gdal/color_entry.rb +3 -3
  58. data/lib/ffi/gdal/gcp.rb +6 -6
  59. data/lib/ffi/gdal/gdal.rb +349 -349
  60. data/lib/ffi/gdal/grid.rb +134 -134
  61. data/lib/ffi/gdal/grid_data_metrics_options.rb +4 -4
  62. data/lib/ffi/gdal/grid_inverse_distance_to_a_power_options.rb +9 -9
  63. data/lib/ffi/gdal/grid_moving_average_options.rb +4 -4
  64. data/lib/ffi/gdal/grid_nearest_neighbor_options.rb +3 -3
  65. data/lib/ffi/gdal/matching.rb +3 -3
  66. data/lib/ffi/gdal/rpc_info.rb +17 -17
  67. data/lib/ffi/gdal/transformer_info.rb +4 -4
  68. data/lib/ffi/gdal/version.rb +1 -1
  69. data/lib/ffi/gdal/vrt.rb +39 -39
  70. data/lib/ffi/gdal/warp_options.rb +34 -34
  71. data/lib/ffi/gdal/warper.rb +90 -90
  72. data/lib/ffi/gdal.rb +2 -31
  73. data/lib/ffi/ogr/api.rb +175 -167
  74. data/lib/ffi/ogr/contour_writer_info.rb +4 -4
  75. data/lib/ffi/ogr/core.rb +107 -107
  76. data/lib/ffi/ogr/envelope.rb +3 -3
  77. data/lib/ffi/ogr/envelope_3d.rb +5 -5
  78. data/lib/ffi/ogr/featurestyle.rb +3 -3
  79. data/lib/ffi/ogr/field.rb +22 -22
  80. data/lib/ffi/ogr/geocoding.rb +4 -4
  81. data/lib/ffi/ogr/srs_api.rb +154 -155
  82. data/lib/ffi/ogr/style_param.rb +3 -3
  83. data/lib/ffi/ogr/style_value.rb +4 -4
  84. data/lib/gdal/color_entry.rb +1 -5
  85. data/lib/gdal/color_interpretation.rb +7 -3
  86. data/lib/gdal/color_table.rb +46 -27
  87. data/lib/gdal/cpl_error_handler.rb +26 -6
  88. data/lib/gdal/data_type.rb +10 -3
  89. data/lib/gdal/dataset.rb +171 -85
  90. data/lib/gdal/dataset_mixins/algorithm_methods.rb +44 -44
  91. data/lib/gdal/dataset_mixins/matching.rb +1 -1
  92. data/lib/gdal/dataset_mixins/warp_methods.rb +4 -2
  93. data/lib/gdal/driver.rb +38 -21
  94. data/lib/gdal/environment_methods.rb +6 -6
  95. data/lib/gdal/extensions/all.rb +3 -0
  96. data/lib/gdal/{color_entry_mixins → extensions/color_entry}/extensions.rb +4 -1
  97. data/lib/gdal/{color_table_mixins → extensions/color_table}/extensions.rb +3 -0
  98. data/lib/gdal/extensions/dataset/extensions.rb +205 -0
  99. data/lib/gdal/{driver_mixins → extensions/driver}/extensions.rb +6 -2
  100. data/lib/gdal/{geo_transform_mixins → extensions/geo_transform}/extensions.rb +10 -8
  101. data/lib/gdal/{gridder → extensions/gridder}/point_extracting.rb +7 -5
  102. data/lib/gdal/{gridder.rb → extensions/gridder.rb} +33 -33
  103. data/lib/gdal/{gridder_options.rb → extensions/gridder_options.rb} +13 -14
  104. data/lib/gdal/{raster_attribute_table_mixins → extensions/raster_attribute_table}/extensions.rb +8 -6
  105. data/lib/gdal/{raster_band_mixins → extensions/raster_band}/algorithm_extensions.rb +8 -6
  106. data/lib/gdal/{raster_band_mixins → extensions/raster_band}/coloring_extensions.rb +6 -4
  107. data/lib/gdal/{raster_band_mixins → extensions/raster_band}/extensions.rb +9 -5
  108. data/lib/gdal/{raster_band_mixins → extensions/raster_band}/io_extensions.rb +18 -14
  109. data/lib/gdal/{raster_band_classifier.rb → extensions/raster_band_classifier.rb} +3 -5
  110. data/lib/gdal/geo_transform.rb +1 -6
  111. data/lib/gdal/grid.rb +3 -2
  112. data/lib/gdal/grid_algorithms.rb +9 -9
  113. data/lib/gdal/internal_helpers.rb +46 -9
  114. data/lib/gdal/major_object.rb +11 -3
  115. data/lib/gdal/options.rb +26 -32
  116. data/lib/gdal/raster_attribute_table.rb +63 -37
  117. data/lib/gdal/raster_band.rb +164 -116
  118. data/lib/gdal/raster_band_mixins/algorithm_methods.rb +26 -25
  119. data/lib/gdal/rpc_info.rb +3 -2
  120. data/lib/gdal/transformers/approximate_transformer.rb +12 -3
  121. data/lib/gdal/transformers/base_general_image_projection_transformer.rb +15 -2
  122. data/lib/gdal/transformers/gcp_transformer.rb +27 -19
  123. data/lib/gdal/transformers/general_image_projection_transformer.rb +8 -6
  124. data/lib/gdal/transformers/general_image_projection_transformer2.rb +9 -6
  125. data/lib/gdal/transformers/general_image_projection_transformer3.rb +6 -2
  126. data/lib/gdal/transformers/geolocation_transformer.rb +12 -4
  127. data/lib/gdal/transformers/reprojection_transformer.rb +11 -3
  128. data/lib/gdal/transformers/rpc_transformer.rb +11 -2
  129. data/lib/gdal/transformers/tps_transformer.rb +12 -4
  130. data/lib/gdal/version_info.rb +2 -2
  131. data/lib/gdal/virtual_dataset.rb +2 -0
  132. data/lib/gdal/warp_operation.rb +65 -54
  133. data/lib/gdal/warp_options.rb +9 -11
  134. data/lib/ogr/coordinate_transformation.rb +23 -9
  135. data/lib/ogr/data_source.rb +68 -37
  136. data/lib/ogr/driver.rb +18 -17
  137. data/lib/ogr/envelope.rb +0 -3
  138. data/lib/ogr/error_handling.rb +22 -24
  139. data/lib/ogr/extensions/all.rb +3 -0
  140. data/lib/ogr/{data_source_mixins → extensions/data_source}/capability_methods.rb +2 -0
  141. data/lib/ogr/extensions/data_source/data_source_extensions.rb +16 -0
  142. data/lib/ogr/{driver_mixins → extensions/driver}/capability_methods.rb +5 -1
  143. data/lib/ogr/extensions/envelope/extensions.rb +114 -0
  144. data/lib/ogr/extensions/feature/extensions.rb +87 -0
  145. data/lib/ogr/extensions/feature_definition/extensions.rb +43 -0
  146. data/lib/ogr/extensions/geometries/point/extensions.rb +19 -0
  147. data/lib/ogr/extensions/geometry/container_mixins.rb +56 -0
  148. data/lib/ogr/extensions/geometry/ewkb_io_extensions.rb +44 -0
  149. data/lib/ogr/extensions/geometry/ewkb_record.rb +94 -0
  150. data/lib/ogr/{geometry_mixins → extensions/geometry}/extensions.rb +16 -9
  151. data/lib/ogr/extensions/geometry/rttopo_extensions.rb +48 -0
  152. data/lib/ogr/extensions/geometry/wkb_record.rb +63 -0
  153. data/lib/ogr/extensions/geometry_types/curve/extensions.rb +68 -0
  154. data/lib/ogr/{layer_mixins → extensions/layer}/capability_methods.rb +4 -0
  155. data/lib/ogr/{layer_mixins → extensions/layer}/extensions.rb +11 -6
  156. data/lib/ogr/extensions/spatial_reference/extensions.rb +38 -0
  157. data/lib/ogr/extensions/spatial_reference/initializers.rb +138 -0
  158. data/lib/ogr/extensions/style_table/extensions.rb +31 -0
  159. data/lib/ogr/feature.rb +173 -88
  160. data/lib/ogr/feature_definition.rb +53 -45
  161. data/lib/ogr/field.rb +17 -19
  162. data/lib/ogr/field_definition.rb +30 -18
  163. data/lib/ogr/geocoder.rb +11 -4
  164. data/lib/ogr/geometries/line_string.rb +1 -0
  165. data/lib/ogr/geometries/line_string_25d.rb +0 -9
  166. data/lib/ogr/geometries/linear_ring.rb +2 -2
  167. data/lib/ogr/geometries/point.rb +0 -9
  168. data/lib/ogr/geometry.rb +116 -49
  169. data/lib/ogr/geometry_field_definition.rb +31 -15
  170. data/lib/ogr/geometry_types/container.rb +26 -28
  171. data/lib/ogr/geometry_types/curve.rb +5 -61
  172. data/lib/ogr/geometry_types/surface.rb +1 -1
  173. data/lib/ogr/internal_helpers.rb +2 -2
  174. data/lib/ogr/layer.rb +12 -10
  175. data/lib/ogr/layer_mixins/ogr_feature_methods.rb +39 -27
  176. data/lib/ogr/layer_mixins/ogr_field_methods.rb +66 -50
  177. data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +17 -8
  178. data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +7 -6
  179. data/lib/ogr/layer_mixins/ogr_sql_methods.rb +15 -7
  180. data/lib/ogr/spatial_reference.rb +79 -42
  181. data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +149 -118
  182. data/lib/ogr/spatial_reference_mixins/exporters.rb +87 -51
  183. data/lib/ogr/spatial_reference_mixins/importers.rb +88 -43
  184. data/lib/ogr/spatial_reference_mixins/morphers.rb +12 -8
  185. data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +27 -13
  186. data/lib/ogr/style_table.rb +15 -5
  187. data/lib/ogr/style_tool.rb +29 -15
  188. data/lib/ogr.rb +1 -0
  189. data/rakelib/docker.rake +10 -0
  190. data/sorbet/rbi/hidden-definitions/errors.txt +21790 -0
  191. data/tilt/gdal2.yml +22 -0
  192. data/tilt/gdal3.yml +22 -0
  193. metadata +116 -280
  194. data/History.md +0 -360
  195. data/lib/ext/error_symbols.rb +0 -7
  196. data/lib/gdal/dataset_mixins/extensions.rb +0 -380
  197. data/lib/gdal/merger.rb +0 -132
  198. data/lib/ogr/data_source_extensions.rb +0 -10
  199. data/lib/ogr/envelope_extensions.rb +0 -110
  200. data/lib/ogr/feature_definition_extensions.rb +0 -39
  201. data/lib/ogr/feature_extensions.rb +0 -87
  202. data/lib/ogr/geometry_mixins/container_mixins.rb +0 -25
  203. data/lib/ogr/spatial_reference_extensions.rb +0 -34
  204. data/lib/ogr/style_table_extensions.rb +0 -26
  205. data/spec/ffi-gdal_spec.rb +0 -24
  206. data/spec/integration/gdal/color_table_info_spec.rb +0 -78
  207. data/spec/integration/gdal/dataset_info_spec.rb +0 -342
  208. data/spec/integration/gdal/driver_info_spec.rb +0 -170
  209. data/spec/integration/gdal/geo_transform_info_spec.rb +0 -226
  210. data/spec/integration/gdal/gridder_spec.rb +0 -331
  211. data/spec/integration/gdal/raster_attribute_table_info_spec.rb +0 -229
  212. data/spec/integration/gdal/raster_band_algorithms_spec.rb +0 -35
  213. data/spec/integration/gdal/raster_band_info_spec.rb +0 -320
  214. data/spec/integration/ogr/layer_spec.rb +0 -95
  215. data/spec/spec_helper.rb +0 -116
  216. data/spec/support/images/123.tiff +0 -0
  217. data/spec/support/images/osgeo/gdal/data/hfa/float-rle.img +0 -0
  218. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.lgo +0 -31
  219. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif +0 -0
  220. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif.msk +0 -0
  221. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.txt +0 -10
  222. data/spec/support/images/osgeo/geotiff/gdal_eg/cea.tif +0 -0
  223. data/spec/support/images/osgeo/geotiff/gdal_eg/cea.txt +0 -84
  224. data/spec/support/images/osgeo/geotiff/zi_imaging/image0.lgo +0 -45
  225. data/spec/support/images/osgeo/geotiff/zi_imaging/image0.tif +0 -0
  226. data/spec/support/integration_help.rb +0 -34
  227. data/spec/support/shapefiles/states_21basic/states.dbf +0 -0
  228. data/spec/support/shapefiles/states_21basic/states.prj +0 -1
  229. data/spec/support/shapefiles/states_21basic/states.sbn +0 -0
  230. data/spec/support/shapefiles/states_21basic/states.sbx +0 -0
  231. data/spec/support/shapefiles/states_21basic/states.shp +0 -0
  232. data/spec/support/shapefiles/states_21basic/states.shp.xml +0 -3
  233. data/spec/support/shapefiles/states_21basic/states.shx +0 -0
  234. data/spec/support/shared_contexts.rb +0 -28
  235. data/spec/support/shared_examples/gdal/major_object_examples.rb +0 -55
  236. data/spec/support/shared_examples/ogr/a_25d_geometry.rb +0 -9
  237. data/spec/support/shared_examples/ogr/a_container_geometry.rb +0 -49
  238. data/spec/support/shared_examples/ogr/a_geometry.rb +0 -406
  239. data/spec/support/shared_examples/ogr/a_line_string.rb +0 -18
  240. data/spec/support/test_style_table.txt +0 -3
  241. data/spec/support/worldfiles/SR_50M/SR_50M.VERSION.txt +0 -1
  242. data/spec/support/worldfiles/SR_50M/SR_50M.prj +0 -1
  243. data/spec/support/worldfiles/SR_50M/SR_50M.tfw +0 -6
  244. data/spec/support/worldfiles/SR_50M/SR_50M.tif +0 -0
  245. data/spec/unit/ext/error_symbols_spec.rb +0 -69
  246. data/spec/unit/ext/numeric_as_data_type_spec.rb +0 -115
  247. data/spec/unit/ffi/gdal_spec.rb +0 -73
  248. data/spec/unit/gdal/color_entry_spec.rb +0 -8
  249. data/spec/unit/gdal/color_interpretation_spec.rb +0 -8
  250. data/spec/unit/gdal/color_table_mixins/extensions_spec.rb +0 -62
  251. data/spec/unit/gdal/color_table_spec.rb +0 -146
  252. data/spec/unit/gdal/data_type_spec.rb +0 -74
  253. data/spec/unit/gdal/dataset_mixins/warp_methods_spec.rb +0 -55
  254. data/spec/unit/gdal/dataset_spec.rb +0 -148
  255. data/spec/unit/gdal/driver_mixins/extensions_spec.rb +0 -24
  256. data/spec/unit/gdal/driver_spec.rb +0 -51
  257. data/spec/unit/gdal/environment_methods_spec.rb +0 -8
  258. data/spec/unit/gdal/geo_transform_mixins/extensions_spec.rb +0 -69
  259. data/spec/unit/gdal/geo_transform_spec.rb +0 -265
  260. data/spec/unit/gdal/grid_spec.rb +0 -98
  261. data/spec/unit/gdal/gridder/point_extracting_spec.rb +0 -101
  262. data/spec/unit/gdal/gridder_options_spec.rb +0 -185
  263. data/spec/unit/gdal/gridder_spec.rb +0 -182
  264. data/spec/unit/gdal/internal_helpers_spec.rb +0 -278
  265. data/spec/unit/gdal/major_object_spec.rb +0 -10
  266. data/spec/unit/gdal/options_spec.rb +0 -33
  267. data/spec/unit/gdal/raster_attribute_table_spec.rb +0 -7
  268. data/spec/unit/gdal/raster_band_classifier_spec.rb +0 -260
  269. data/spec/unit/gdal/raster_band_mixins/extensions_spec.rb +0 -73
  270. data/spec/unit/gdal/raster_band_mixins/io_extensions_spec.rb +0 -135
  271. data/spec/unit/gdal/raster_band_spec.rb +0 -8
  272. data/spec/unit/gdal/rpc_info_spec.rb +0 -8
  273. data/spec/unit/gdal/version_info_spec.rb +0 -10
  274. data/spec/unit/gdal/virtual_dataset_spec.rb +0 -34
  275. data/spec/unit/gdal/warp_operation_spec.rb +0 -8
  276. data/spec/unit/gdal/warp_options_spec.rb +0 -338
  277. data/spec/unit/ogr/coordinate_transformation_spec.rb +0 -104
  278. data/spec/unit/ogr/data_source_mixins/capability_methods_spec.rb +0 -32
  279. data/spec/unit/ogr/data_source_spec.rb +0 -223
  280. data/spec/unit/ogr/driver_mixins/capability_methods_spec.rb +0 -20
  281. data/spec/unit/ogr/driver_spec.rb +0 -152
  282. data/spec/unit/ogr/envelope_spec.rb +0 -324
  283. data/spec/unit/ogr/feature_definition_spec.rb +0 -296
  284. data/spec/unit/ogr/feature_extensions_spec.rb +0 -90
  285. data/spec/unit/ogr/feature_spec.rb +0 -363
  286. data/spec/unit/ogr/field_definition_spec.rb +0 -118
  287. data/spec/unit/ogr/field_spec.rb +0 -195
  288. data/spec/unit/ogr/geometries/geometry_collection_25d_spec.rb +0 -25
  289. data/spec/unit/ogr/geometries/geometry_collection_spec.rb +0 -188
  290. data/spec/unit/ogr/geometries/line_string_25d_spec.rb +0 -25
  291. data/spec/unit/ogr/geometries/line_string_spec.rb +0 -107
  292. data/spec/unit/ogr/geometries/linear_ring_spec.rb +0 -92
  293. data/spec/unit/ogr/geometries/multi_line_string_25d_spec.rb +0 -25
  294. data/spec/unit/ogr/geometries/multi_line_string_spec.rb +0 -16
  295. data/spec/unit/ogr/geometries/multi_point_25d_spec.rb +0 -25
  296. data/spec/unit/ogr/geometries/multi_point_spec.rb +0 -16
  297. data/spec/unit/ogr/geometries/multi_polygon_25d_spec.rb +0 -25
  298. data/spec/unit/ogr/geometries/multi_polygon_spec.rb +0 -43
  299. data/spec/unit/ogr/geometries/none_geometry_spec.rb +0 -14
  300. data/spec/unit/ogr/geometries/point_25d_spec.rb +0 -25
  301. data/spec/unit/ogr/geometries/point_spec.rb +0 -307
  302. data/spec/unit/ogr/geometries/polygon_25d_spec.rb +0 -25
  303. data/spec/unit/ogr/geometries/polygon_spec.rb +0 -19
  304. data/spec/unit/ogr/geometries/unknown_geometry_spec.rb +0 -12
  305. data/spec/unit/ogr/geometry_field_definition_spec.rb +0 -73
  306. data/spec/unit/ogr/geometry_spec.rb +0 -711
  307. data/spec/unit/ogr/internal_helpers_spec.rb +0 -70
  308. data/spec/unit/ogr/layer_mixins/capability_methods_spec.rb +0 -90
  309. data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +0 -155
  310. data/spec/unit/ogr/layer_mixins/ogr_field_methods_spec.rb +0 -434
  311. data/spec/unit/ogr/layer_mixins/ogr_layer_method_methods_spec.rb +0 -22
  312. data/spec/unit/ogr/layer_mixins/ogr_query_filter_methods_spec.rb +0 -44
  313. data/spec/unit/ogr/layer_mixins/ogr_sql_methods_spec.rb +0 -14
  314. data/spec/unit/ogr/layer_spec.rb +0 -98
  315. data/spec/unit/ogr/spatial_reference_mixins/coordinate_system_getter_setters_spec.rb +0 -48
  316. data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +0 -151
  317. data/spec/unit/ogr/spatial_reference_mixins/importers_spec.rb +0 -40
  318. data/spec/unit/ogr/spatial_reference_mixins/morphers_spec.rb +0 -38
  319. data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +0 -105
  320. data/spec/unit/ogr/spatial_reference_mixins/type_checks_spec.rb +0 -159
  321. data/spec/unit/ogr/spatial_reference_spec.rb +0 -44
  322. data/spec/unit/ogr/style_table_spec.rb +0 -108
  323. data/spec/unit/ogr/style_tool_spec.rb +0 -159
  324. data/spec/unit/version_info_spec.rb +0 -50
@@ -1,24 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'bigdecimal'
4
+ require 'bigdecimal/util'
3
5
  require 'narray'
4
- require 'numo/narray'
5
6
  require_relative '../gdal'
6
- require_relative 'raster_band_mixins/algorithm_extensions'
7
7
  require_relative 'raster_band_mixins/algorithm_methods'
8
- require_relative 'raster_band_mixins/coloring_extensions'
9
- require_relative 'raster_band_mixins/extensions'
10
- require_relative 'raster_band_mixins/io_extensions'
11
8
  require_relative 'major_object'
12
9
 
13
10
  module GDAL
14
- class RasterBand
11
+ class RasterBand # rubocop:disable Metrics/ClassLength
15
12
  include MajorObject
16
13
  include GDAL::Logger
17
14
  include RasterBandMixins::AlgorithmMethods
18
- include RasterBandMixins::AlgorithmExtensions
19
- include RasterBandMixins::ColoringExtensions
20
- include RasterBandMixins::Extensions
21
- include RasterBandMixins::IOExtensions
22
15
 
23
16
  ALL_VALID = 0x01
24
17
  PER_DATASET = 0x02
@@ -28,26 +21,37 @@ module GDAL
28
21
  # @return [FFI::Pointer] C pointer to the C raster band.
29
22
  attr_reader :c_pointer
30
23
 
24
+ # @return [GDAL::Dataset] The dataset that owns this RasterBand.
25
+ attr_reader :dataset
26
+
31
27
  # @param raster_band [GDAL::RasterBand, FFI::Pointer]
32
- def initialize(raster_band)
33
- @c_pointer = GDAL._pointer(GDAL::RasterBand, raster_band)
28
+ def initialize(raster_band, dataset = nil)
29
+ @c_pointer = GDAL._pointer(GDAL::RasterBand, raster_band, autorelease: false)
30
+
31
+ # Init the dataset too--the dataset owns the raster band, so when the dataset
32
+ # gets closed, the raster band gets cleaned up. Storing a reference to the
33
+ # dataset here ensures the underlying raster band doesn't get pulled out
34
+ # from under the Ruby object that represents it.
35
+ @dataset = dataset || init_dataset
34
36
  end
35
37
 
36
- # @return [Boolean]
38
+ # @raise [GDAL::Error]
37
39
  def flush_cache
38
- !!FFI::GDAL::GDAL.GDALFlushRasterCache(@c_pointer)
40
+ GDAL::CPLErrorHandler.manually_handle('Unable to flush cache') do
41
+ FFI::GDAL::GDAL.GDALFlushRasterCache(@c_pointer)
42
+ end
39
43
  end
40
44
 
41
45
  # The raster width in pixels.
42
46
  #
43
- # @return [Fixnum]
47
+ # @return [Integer]
44
48
  def x_size
45
49
  FFI::GDAL::GDAL.GDALGetRasterBandXSize(@c_pointer)
46
50
  end
47
51
 
48
52
  # The raster height in pixels.
49
53
  #
50
- # @return [Fixnum]
54
+ # @return [Integer]
51
55
  def y_size
52
56
  FFI::GDAL::GDAL.GDALGetRasterBandYSize(@c_pointer)
53
57
  end
@@ -62,31 +66,22 @@ module GDAL
62
66
  # The number of band within the associated dataset that this band
63
67
  # represents.
64
68
  #
65
- # @return [Fixnum]
69
+ # @return [Integer]
66
70
  def number
67
71
  FFI::GDAL::GDAL.GDALGetBandNumber(@c_pointer)
68
72
  end
69
73
 
70
- # @return [GDAL::Dataset, nil]
71
- def dataset(access_flag = 'r')
72
- return @dataset if @dataset
73
-
74
- dataset_ptr = FFI::GDAL::GDAL.GDALGetBandDataset(@c_pointer)
75
- return nil if dataset_ptr.null?
76
-
77
- @dataset = GDAL::Dataset.new(dataset_ptr, access_flag, true)
78
- end
79
-
80
74
  # @return [Symbol] One of FFI::GDAL::GDAL::ColorInterp.
81
75
  def color_interpretation
82
76
  FFI::GDAL::GDAL.GDALGetRasterColorInterpretation(@c_pointer)
83
77
  end
84
78
 
85
79
  # @param new_color_interp [FFI::GDAL::GDAL::ColorInterp]
86
- # @return [Boolean]
80
+ # @raise [GDAL::Error]
87
81
  def color_interpretation=(new_color_interp)
88
- !!FFI::GDAL::GDAL.GDALSetRasterColorInterpretation(@c_pointer,
89
- new_color_interp)
82
+ GDAL::CPLErrorHandler.manually_handle('Unable to set color interpretation') do
83
+ FFI::GDAL::GDAL.GDALSetRasterColorInterpretation(@c_pointer, new_color_interp)
84
+ end
90
85
  end
91
86
 
92
87
  # Gets the associated GDAL::ColorTable. Note that it remains owned by the
@@ -103,9 +98,13 @@ module GDAL
103
98
  end
104
99
 
105
100
  # @param new_color_table [GDAL::ColorTable]
101
+ # @raise [GDAL::Error]
106
102
  def color_table=(new_color_table)
107
- color_table_pointer = GDAL._pointer(GDAL::ColorTable, new_color_table)
108
- FFI::GDAL::GDAL.GDALSetRasterColorTable(@c_pointer, color_table_pointer)
103
+ color_table_pointer = GDAL::ColorTable.new_pointer(new_color_table)
104
+
105
+ GDAL::CPLErrorHandler.manually_handle('Unable to set color table') do
106
+ FFI::GDAL::GDAL.GDALSetRasterColorTable(@c_pointer, color_table_pointer)
107
+ end
109
108
  end
110
109
 
111
110
  # The pixel data type for this band.
@@ -119,7 +118,7 @@ module GDAL
119
118
  # accessing the format. For many formats this is simply a whole scanline
120
119
  # in which case x is set to #x_size, and y is set to 1.
121
120
  #
122
- # @return [Hash{x => Fixnum, y => Fixnum}]
121
+ # @return [Hash{x => Integer, y => Integer}]
123
122
  def block_size
124
123
  x_pointer = FFI::MemoryPointer.new(:int)
125
124
  y_pointer = FFI::MemoryPointer.new(:int)
@@ -137,11 +136,13 @@ module GDAL
137
136
  end
138
137
 
139
138
  # @param names [Array<String>]
140
- # @return [Boolean]
139
+ # @raise [GDAL::Error]
141
140
  def category_names=(names)
142
141
  names_pointer = GDAL._string_array_to_pointer(names)
143
142
 
144
- FFI::GDAL::GDAL.GDALSetRasterCategoryNames(@c_pointer, names_pointer)
143
+ GDAL::CPLErrorHandler.manually_handle('Unable to set category names') do
144
+ FFI::GDAL::GDAL.GDALSetRasterCategoryNames(@c_pointer, names_pointer)
145
+ end
145
146
  end
146
147
 
147
148
  # The no data value for a band is generally a special marker value used to
@@ -152,7 +153,7 @@ module GDAL
152
153
  def no_data_value
153
154
  associated = FFI::MemoryPointer.new(:bool)
154
155
  value = FFI::GDAL::GDAL.GDALGetRasterNoDataValue(@c_pointer, associated)
155
- value = nil if value == -10_000_000_000.0
156
+ value = nil if value.to_d == BigDecimal('-10_000_000_000.0')
156
157
 
157
158
  { value: value, is_associated: associated.read_bytes(1).to_bool }
158
159
  end
@@ -161,22 +162,24 @@ module GDAL
161
162
  # is impossible until GDAL 2.1.
162
163
  #
163
164
  # @param value [Float, nil]
164
- # @return [Boolean]
165
+ # @raise [GDAL::Error]
165
166
  def no_data_value=(value)
166
- !!FFI::GDAL::GDAL.GDALSetRasterNoDataValue(@c_pointer, value) if value
167
+ GDAL::CPLErrorHandler.manually_handle('Unable to set NODATA value') do
168
+ FFI::GDAL::GDAL.GDALSetRasterNoDataValue(@c_pointer, value)
169
+ end
167
170
  end
168
171
 
169
- # @return [Fixnum]
172
+ # @return [Integer]
170
173
  def overview_count
171
174
  FFI::GDAL::GDAL.GDALGetOverviewCount(@c_pointer)
172
175
  end
173
176
 
174
177
  # @return [Boolean]
175
178
  def arbitrary_overviews?
176
- FFI::GDAL::GDAL.GDALHasArbitraryOverviews(@c_pointer).zero? ? false : true
179
+ !FFI::GDAL::GDAL.GDALHasArbitraryOverviews(@c_pointer).zero?
177
180
  end
178
181
 
179
- # @param index [Fixnum] Must be between 0 and (#overview_count - 1).
182
+ # @param index [Integer] Must be between 0 and (#overview_count - 1).
180
183
  # @return [GDAL::RasterBand]
181
184
  def overview(index)
182
185
  return nil if overview_count.zero?
@@ -192,7 +195,7 @@ module GDAL
192
195
  # If the band doesn't have any overviews or none of the overviews have
193
196
  # enough samples, it will return the same band.
194
197
  #
195
- # @param desired_samples [Fixnum] The returned band will have at least this
198
+ # @param desired_samples [Integer] The returned band will have at least this
196
199
  # many pixels.
197
200
  # @return [GDAL::RasterBand] An optimal overview or the same raster band if
198
201
  # the raster band has no overviews.
@@ -234,7 +237,7 @@ module GDAL
234
237
  end
235
238
 
236
239
  # @param flags [Array<Symbol>, Symbol] Any of the :GMF symbols.
237
- # @return [Boolean]
240
+ # @raise [GDAL::Error]
238
241
  def create_mask_band(*flags)
239
242
  flag_value = 0
240
243
 
@@ -248,7 +251,9 @@ module GDAL
248
251
  end
249
252
  end
250
253
 
251
- !!FFI::GDAL::GDAL.GDALCreateMaskBand(@c_pointer, flag_value)
254
+ GDAL::CPLErrorHandler.manually_handle('Unable to create mask band') do
255
+ FFI::GDAL::GDAL.GDALCreateMaskBand(@c_pointer, flag_value)
256
+ end
252
257
  end
253
258
 
254
259
  # Fill this band with constant value. Useful for clearing a band and
@@ -256,8 +261,11 @@ module GDAL
256
261
  #
257
262
  # @param real_value [Float]
258
263
  # @param imaginary_value [Float]
264
+ # @raise [GDAL::Error]
259
265
  def fill(real_value, imaginary_value = 0)
260
- !!FFI::GDAL::GDAL.GDALFillRaster(@c_pointer, real_value, imaginary_value)
266
+ GDAL::CPLErrorHandler.manually_handle('Unable to fill raster') do
267
+ FFI::GDAL::GDAL.GDALFillRaster(@c_pointer, real_value, imaginary_value)
268
+ end
261
269
  end
262
270
 
263
271
  # Returns minimum, maximum, mean, and standard deviation of all pixel values
@@ -269,7 +277,7 @@ module GDAL
269
277
  # calculating can be done without rescanning the image.
270
278
  # @return [Hash{minimum: Float, maximum: Float, mean: Float,
271
279
  # standard_deviation: Float}]
272
- def statistics(approx_ok = true, force = true)
280
+ def statistics(approx_ok: true, force: true)
273
281
  min = FFI::MemoryPointer.new(:double)
274
282
  max = FFI::MemoryPointer.new(:double)
275
283
  mean = FFI::MemoryPointer.new(:double)
@@ -288,12 +296,12 @@ module GDAL
288
296
 
289
297
  handler.custom_handle do
290
298
  FFI::GDAL::GDAL.GDALGetRasterStatistics(@c_pointer,
291
- approx_ok,
292
- force,
293
- min,
294
- max,
295
- mean,
296
- standard_deviation)
299
+ approx_ok,
300
+ force,
301
+ min,
302
+ max,
303
+ mean,
304
+ standard_deviation)
297
305
  end
298
306
  end
299
307
 
@@ -307,16 +315,18 @@ module GDAL
307
315
  mean_ptr = FFI::MemoryPointer.new(:double)
308
316
  standard_deviation_ptr = FFI::MemoryPointer.new(:double)
309
317
 
310
- FFI::GDAL::GDAL::GDALComputeRasterStatistics(
311
- @c_pointer, # hBand
312
- approx_ok, # bApproxOK
313
- min_ptr, # pdfMin
314
- max_ptr, # pdfMax
315
- mean_ptr, # pdfMean
316
- standard_deviation_ptr, # pdfStdDev
317
- progress_block, # pfnProgress
318
- nil # pProgressData
319
- )
318
+ GDAL::CPLErrorHandler.manually_handle('Unable to compute raster statistics') do
319
+ FFI::GDAL::GDAL::GDALComputeRasterStatistics(
320
+ @c_pointer, # hBand
321
+ approx_ok, # bApproxOK
322
+ min_ptr, # pdfMin
323
+ max_ptr, # pdfMax
324
+ mean_ptr, # pdfMean
325
+ standard_deviation_ptr, # pdfStdDev
326
+ progress_block, # pfnProgress
327
+ nil # pProgressData
328
+ )
329
+ end
320
330
 
321
331
  {
322
332
  minimum: min_ptr.read_double,
@@ -336,18 +346,23 @@ module GDAL
336
346
  # For file formats that don't know this intrinsically a value of one is
337
347
  # returned.
338
348
  #
339
- # @return [Hash{value => Float, is_meaningful => Boolean}]
349
+ # @return Float
350
+ # @raise GDAL::Error if the underlying call fails.
340
351
  def scale
341
- meaningful = FFI::MemoryPointer.new(:bool)
342
- result = FFI::GDAL::GDAL.GDALGetRasterScale(@c_pointer, meaningful)
352
+ success = FFI::MemoryPointer.new(:bool)
353
+ result = FFI::GDAL::GDAL.GDALGetRasterScale(@c_pointer, success)
354
+
355
+ raise GDAL::Error, 'GDALGetRasterScale failed' unless success.read_bytes(1).to_bool
343
356
 
344
- { value: result, is_meaningful: meaningful.read_bytes(1).to_bool }
357
+ result
345
358
  end
346
359
 
347
360
  # @param new_scale [Float]
348
- # @return [Boolean]
361
+ # @raise [GDAL::Error]
349
362
  def scale=(new_scale)
350
- !!FFI::GDAL::GDAL.GDALSetRasterScale(@c_pointer, new_scale.to_f)
363
+ GDAL::CPLErrorHandler.manually_handle('Unable to set raster scale') do
364
+ FFI::GDAL::GDAL.GDALSetRasterScale(@c_pointer, new_scale.to_f)
365
+ end
351
366
  end
352
367
 
353
368
  # This value (in combination with the #scale value) is used to
@@ -360,12 +375,15 @@ module GDAL
360
375
  # For file formats that don't know this intrinsically a value of 0.0 is
361
376
  # returned.
362
377
  #
363
- # @return [Hash{value => Float, is_meaningful => Boolean}]
378
+ # @return Float
379
+ # @raise GDAL::Error if the underlying call fails.
364
380
  def offset
365
- meaningful = FFI::MemoryPointer.new(:bool)
366
- result = FFI::GDAL::GDAL.GDALGetRasterOffset(@c_pointer, meaningful)
381
+ success = FFI::MemoryPointer.new(:bool)
382
+ result = FFI::GDAL::GDAL.GDALGetRasterOffset(@c_pointer, success)
367
383
 
368
- { value: result, is_meaningful: meaningful.read_bytes(1).to_bool }
384
+ raise GDAL::Error, 'GDALGetRasterOffset failed' unless success.read_bytes(1).to_bool
385
+
386
+ result
369
387
  end
370
388
 
371
389
  # Sets the scaling offset. Very few formats support this method.
@@ -373,22 +391,31 @@ module GDAL
373
391
  # @param new_offset [Float]
374
392
  # @return [Boolean]
375
393
  def offset=(new_offset)
376
- !!FFI::GDAL::GDAL.GDALSetRasterOffset(@c_pointer, new_offset)
394
+ GDAL::CPLErrorHandler.manually_handle('Unable to set raster offset') do
395
+ FFI::GDAL::GDAL.GDALSetRasterOffset(@c_pointer, new_offset)
396
+ end
377
397
  end
378
398
 
379
399
  # @return [String]
380
400
  def unit_type
381
- FFI::GDAL::GDAL.GDALGetRasterUnitType(@c_pointer)
401
+ # The returned string should not be modified, nor freed by the calling application.
402
+ type, ptr = FFI::GDAL::GDAL.GDALGetRasterUnitType(@c_pointer)
403
+ ptr.autorelease = false
404
+
405
+ type
382
406
  end
383
407
 
384
408
  # @param new_unit_type [String] "" indicates unknown, "m" is meters, "ft"
385
409
  # is feet; other non-standard values are allowed.
386
- # @return [Boolean]
410
+ # @raise [GDAL::Error]
387
411
  def unit_type=(new_unit_type)
388
- if defined? FFI::GDAL::GDAL::GDALSetRasterUnitType
389
- !!FFI::GDAL::GDAL.GDALSetRasterUnitType(@c_pointer, new_unit_type)
390
- else
412
+ unless defined? FFI::GDAL::GDAL::GDALSetRasterUnitType
391
413
  warn "GDALSetRasterUnitType is not defined. Can't call RasterBand#unit_type="
414
+ return
415
+ end
416
+
417
+ GDAL::CPLErrorHandler.manually_handle('Unable to set unit type') do
418
+ FFI::GDAL::GDAL.GDALSetRasterUnitType(@c_pointer, new_unit_type)
392
419
  end
393
420
  end
394
421
 
@@ -400,10 +427,13 @@ module GDAL
400
427
  GDAL::RasterAttributeTable.new(rat_pointer)
401
428
  end
402
429
 
403
- # @return [GDAL::RasterAttributeTable]
430
+ # @raise [GDAL::Error]
404
431
  def default_raster_attribute_table=(rat_table)
405
- rat_table_ptr = GDAL._pointer(GDAL::RasterAttributeTable, rat_table)
406
- FFI::GDAL::GDAL.GDALSetDefaultRAT(@c_pointer, rat_table_ptr)
432
+ rat_table_ptr = GDAL::RasterAttributeTable.new_pointer(rat_table)
433
+
434
+ GDAL::CPLErrorHandler.manually_handle('Unable to set default raster attribute table') do
435
+ FFI::GDAL::GDAL.GDALSetDefaultRAT(@c_pointer, rat_table_ptr)
436
+ end
407
437
  end
408
438
 
409
439
  # Gets the default raster histogram. Results are returned as a Hash so some
@@ -444,10 +474,10 @@ module GDAL
444
474
  # @yieldparam completion [Float] The ration completed as a decimal.
445
475
  # @yieldparam message [String] Message string to display.
446
476
  #
447
- # @return [Hash{minimum => Float, maximum => Float, buckets => Fixnum,
448
- # totals => Array<Fixnum>}] Returns +nil+ if no default histogram is
477
+ # @return [Hash{minimum => Float, maximum => Float, buckets => Integer,
478
+ # totals => Array<Integer>}] Returns +nil+ if no default histogram is
449
479
  # available.
450
- def default_histogram(force = false, &block)
480
+ def default_histogram(force: false, &block)
451
481
  min_pointer = FFI::MemoryPointer.new(:double)
452
482
  max_pointer = FFI::MemoryPointer.new(:double)
453
483
  buckets_pointer = FFI::MemoryPointer.new(:int)
@@ -455,7 +485,7 @@ module GDAL
455
485
  progress_proc = block || nil
456
486
 
457
487
  handler = GDAL::CPLErrorHandler.new
458
- handler.on_warning = proc { nil }
488
+ handler.on_warning = proc {}
459
489
  handler.on_none = proc do
460
490
  min = min_pointer.read_double
461
491
  max = max_pointer.read_double
@@ -494,7 +524,7 @@ module GDAL
494
524
  #
495
525
  # @param min [Float] The lower bound of the histogram.
496
526
  # @param max [Float] The upper bound of the histogram.
497
- # @param buckets [Fixnum]
527
+ # @param buckets [Integer]
498
528
  # @param include_out_of_range [Boolean] If +true+, values below the
499
529
  # histogram range will be mapped into the first bucket of the output
500
530
  # data; values above the range will be mapped into the last bucket. If
@@ -506,8 +536,8 @@ module GDAL
506
536
  # @yieldparam completion [Float] The ration completed as a decimal.
507
537
  # @yieldparam message [String] Message string to display.
508
538
  #
509
- # @return [Hash{minimum => Float, maximum => Float, buckets => Fixnum,
510
- # totals => Array<Fixnum>}]
539
+ # @return [Hash{minimum => Float, maximum => Float, buckets => Integer,
540
+ # totals => Array<Integer>}]
511
541
  #
512
542
  # @see #default_histogram for more info.
513
543
  def histogram(min, max, buckets, include_out_of_range: false,
@@ -516,7 +546,7 @@ module GDAL
516
546
  progress_proc = block || nil
517
547
 
518
548
  handler = GDAL::CPLErrorHandler.new
519
- handler.on_warning = proc { nil }
549
+ handler.on_warning = proc {}
520
550
  handler.on_none = proc do
521
551
  totals = if buckets.zero?
522
552
  []
@@ -534,14 +564,14 @@ module GDAL
534
564
 
535
565
  handler.custom_handle do
536
566
  FFI::GDAL::GDAL.GDALGetRasterHistogram(@c_pointer,
537
- min.to_f,
538
- max.to_f,
539
- buckets,
540
- histogram_pointer,
541
- include_out_of_range,
542
- approx_ok,
543
- progress_proc,
544
- nil)
567
+ min.to_f,
568
+ max.to_f,
569
+ buckets,
570
+ histogram_pointer,
571
+ include_out_of_range,
572
+ approx_ok,
573
+ progress_proc,
574
+ nil)
545
575
  end
546
576
  end
547
577
 
@@ -562,11 +592,13 @@ module GDAL
562
592
  destination_pointer = GDAL._pointer(GDAL::RasterBand, destination_band)
563
593
  options_ptr = GDAL::Options.pointer(options)
564
594
 
565
- !!FFI::GDAL::GDAL.GDALRasterBandCopyWholeRaster(@c_pointer,
566
- destination_pointer,
567
- options_ptr,
568
- progress,
569
- nil)
595
+ GDAL::CPLErrorHandler.manually_handle('Unable to copy whole raster') do
596
+ FFI::GDAL::GDAL.GDALRasterBandCopyWholeRaster(@c_pointer,
597
+ destination_pointer,
598
+ options_ptr,
599
+ progress,
600
+ nil)
601
+ end
570
602
  end
571
603
 
572
604
  # IO access for raster data in this band. Default values are set up to
@@ -582,35 +614,36 @@ module GDAL
582
614
  # @param access_flag [Symbol] Must be 'r' or 'w'.
583
615
  # @param buffer [FFI::MemoryPointer] Allows for passing in your own buffer,
584
616
  # which is really only useful when writing.
585
- # @param x_size [Fixnum] The number of pixels per line to operate on.
617
+ # @param x_size [Integer] The number of pixels per line to operate on.
586
618
  # Defaults to the value of {{#x_size}}.
587
- # @param y_size [Fixnum] The number of lines to operate on. Defaults to the
619
+ # @param y_size [Integer] The number of lines to operate on. Defaults to the
588
620
  # value of {{#y_size}}.
589
- # @param x_offset [Fixnum] The pixel number in the line to start operating
621
+ # @param x_offset [Integer] The pixel number in the line to start operating
590
622
  # on. Note that when using this, {#x_size} - +x_offset+ should be >= 0,
591
623
  # otherwise this means you're telling the method to read past the end of
592
624
  # the line. Defaults to 0.
593
- # @param y_offset [Fixnum] The line number to start operating on. Note that
625
+ # @param y_offset [Integer] The line number to start operating on. Note that
594
626
  # when using this, {#y_size} - +y_offset+ should be >= 0, otherwise this
595
627
  # means you're telling the method to read more lines than the raster has.
596
628
  # Defaults to 0.
597
- # @param buffer_x_size [Fixnum] The width of the buffer image in which to
629
+ # @param buffer_x_size [Integer] The width of the buffer image in which to
598
630
  # read/write the raster data into/from. Typically this should be the same
599
631
  # size as +x_size+; if it's different, GDAL will resample accordingly.
600
- # @param buffer_y_size [Fixnum] The height of the buffer image in which to
632
+ # @param buffer_y_size [Integer] The height of the buffer image in which to
601
633
  # read/write the raster data into/from. Typically this should be the same
602
634
  # size as +y_size+; if it's different, GDAL will resample accordingly.
603
635
  # @param buffer_data_type [FFI::GDAL::GDAL::DataType] Can be used to convert the
604
636
  # data to a different type. You must account for this when reading/writing
605
637
  # to/from your buffer--your buffer size must be +buffer_x_size+ *
606
638
  # +buffer_y_size+. Defaults to {{#data_type}}.
607
- # @param pixel_space [Fixnum] The byte offset from the start of one pixel
639
+ # @param pixel_space [Integer] The byte offset from the start of one pixel
608
640
  # value in the buffer to the start of the next pixel value within a line.
609
641
  # If defaulted (0), the size of +buffer_data_type+ is used.
610
- # @param line_space [Fixnum] The byte offset from the start of one line in
642
+ # @param line_space [Integer] The byte offset from the start of one line in
611
643
  # the buffer to the start of the next. If defaulted (0), the size of
612
644
  # +buffer_data_type+ * +buffer_x_size* is used.
613
645
  # @return [FFI::MemoryPointer] Pointer to the data that was read/written.
646
+ # rubocop:disable Metrics/ParameterLists
614
647
  def raster_io(access_flag, buffer = nil,
615
648
  x_size: nil, y_size: nil, x_offset: 0, y_offset: 0,
616
649
  buffer_x_size: nil, buffer_y_size: nil, buffer_data_type: data_type,
@@ -641,13 +674,14 @@ module GDAL
641
674
 
642
675
  buffer
643
676
  end
677
+ # rubocop:enable Metrics/ParameterLists
644
678
 
645
679
  # Read a block of image data, more efficiently than #read. Doesn't
646
680
  # resample or do data type conversion.
647
681
  #
648
- # @param x_block_number [Fixnum] The horizontal block offset, with 0 indicating
682
+ # @param x_block_number [Integer] The horizontal block offset, with 0 indicating
649
683
  # the left-most block, 1 the next block, etc.
650
- # @param y_block_number [Fixnum] The vertical block offset, with 0 indicating the
684
+ # @param y_block_number [Integer] The vertical block offset, with 0 indicating the
651
685
  # top-most block, 1 the next block, etc.
652
686
  # @param image_buffer [FFI::Pointer] Optional pointer to use for reading
653
687
  # the data into. If not provided, one will be created and returned.
@@ -657,21 +691,25 @@ module GDAL
657
691
  def read_block(x_block_number, y_block_number, image_buffer = nil)
658
692
  image_buffer ||= FFI::MemoryPointer.new(:buffer_out, block_buffer_size)
659
693
 
660
- FFI::GDAL::GDAL.GDALReadBlock(@c_pointer, x_block_number, y_block_number, image_buffer)
694
+ GDAL::CPLErrorHandler.manually_handle('Unable to read block') do
695
+ FFI::GDAL::GDAL.GDALReadBlock(@c_pointer, x_block_number, y_block_number, image_buffer)
696
+ end
661
697
 
662
698
  image_buffer
663
699
  end
664
700
 
665
- # @param x_block_number [Fixnum] The horizontal block offset, with 0 indicating
701
+ # @param x_block_number [Integer] The horizontal block offset, with 0 indicating
666
702
  # the left-most block, 1 the next block, etc.
667
- # @param y_block_number [Fixnum] The vertical block offset, with 0 indicating the
703
+ # @param y_block_number [Integer] The vertical block offset, with 0 indicating the
668
704
  # top-most block, 1 the next block, etc.
669
705
  # @param data_pointer [FFI::Pointer] Optional pointer to write the data to.
670
706
  # If not provided, one will be created and returned.
671
707
  def write_block(x_block_number, y_block_number, data_pointer = nil)
672
708
  data_pointer ||= FFI::Buffer.alloc_inout(block_buffer_size)
673
709
 
674
- FFI::GDAL::GDAL.GDALWriteBlock(@c_pointer, x_block_number, y_block_number, data_pointer)
710
+ GDAL::CPLErrorHandler.manually_handle('Unable to write block') do
711
+ FFI::GDAL::GDAL.GDALWriteBlock(@c_pointer, x_block_number, y_block_number, data_pointer)
712
+ end
675
713
 
676
714
  data_pointer
677
715
  end
@@ -711,5 +749,15 @@ module GDAL
711
749
 
712
750
  { value: value, is_tight: is_tight.read_bytes(1).to_bool }
713
751
  end
752
+
753
+ private
754
+
755
+ # @return [GDAL::Dataset, nil]
756
+ def init_dataset
757
+ dataset_ptr = FFI::GDAL::GDAL.GDALGetBandDataset(@c_pointer)
758
+ return nil if dataset_ptr.null?
759
+
760
+ GDAL::Dataset.new(dataset_ptr, access_flag, shared_open: true)
761
+ end
714
762
  end
715
763
  end