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
@@ -1,60 +1,76 @@
1
1
  require 'spec_helper'
2
- require 'support/integration_help'
3
2
  require 'ffi-gdal'
4
- require 'gdal/dataset'
3
+ require 'gdal'
5
4
 
6
- TIF_FILES.each do |file|
7
- dataset = GDAL::Dataset.open(file, 'r')
5
+ RSpec.describe 'GDAL Color Table access', type: :integration do
6
+ let(:dataset) { GDAL::Dataset.open(tmp_tiff, 'r') }
7
+ let(:tmp_tiff) { make_temp_test_file(original_tiff) }
8
+ after(:each) { dataset.close }
8
9
 
9
- RSpec.describe 'Color Table Info' do
10
- after :all do
11
- dataset.close
12
- end
10
+ subject(:color_table) do
11
+ band = dataset.raster_band(1)
12
+ band.color_table
13
+ end
13
14
 
14
- # TODO: Test against each raster band
15
- subject do
16
- band = dataset.raster_band(1)
17
- band.color_table
15
+ context 'file with color table' do
16
+ let(:original_tiff) do
17
+ path = '../../../spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif'
18
+ File.expand_path(path, __dir__)
18
19
  end
19
20
 
20
21
  describe '#palette_interpretation' do
21
- it 'returns a GDALPaletteInterp' do
22
- next if subject.nil?
23
-
24
- expect(subject.palette_interpretation).to eq :GPI_RGB
25
- end
22
+ subject { color_table.palette_interpretation }
23
+ it { is_expected.to eq :GPI_RGB }
26
24
  end
27
25
 
28
26
  describe '#color_entry_count' do
29
- it 'returns a Fixnum (256 with current test files)' do
30
- next if subject.nil?
31
-
32
- expect(subject.color_entry_count).to eq 256
33
- end
27
+ subject { color_table.color_entry_count }
28
+ it { is_expected.to eq 256 }
34
29
  end
35
30
 
36
31
  describe '#color_entry' do
37
32
  it 'returns a GDAL::ColorEntry' do
38
- next if subject.nil?
39
-
40
33
  expect(subject.color_entry(0)).to be_a GDAL::ColorEntry
41
34
  end
42
35
 
43
36
  it 'has 4 Fixnum values, >= 0' do
44
- next if subject.nil?
37
+ expect(subject.color_entry(0).color1).to eq 0
38
+ expect(subject.color_entry(0).color2).to eq 0
39
+ expect(subject.color_entry(0).color3).to eq 0
40
+ expect(subject.color_entry(0).color4).to eq 255
45
41
 
46
- expect(subject.color_entry(0).color1).to be_a Fixnum
47
- expect(subject.color_entry(0).color1).to be >= 0
42
+ expect(subject.color_entry(1).color1).to eq 192
43
+ expect(subject.color_entry(1).color2).to eq 0
44
+ expect(subject.color_entry(1).color3).to eq 0
45
+ expect(subject.color_entry(1).color4).to eq 255
46
+ end
47
+ end
48
48
 
49
- expect(subject.color_entry(0).color2).to be_a Fixnum
50
- expect(subject.color_entry(0).color2).to be >= 0
49
+ describe '#color_entry_as_rgb' do
50
+ it 'returns a GDAL::ColorEntry' do
51
+ expect(subject.color_entry_as_rgb(0)).to be_a GDAL::ColorEntry
52
+ end
51
53
 
52
- expect(subject.color_entry(0).color3).to be_a Fixnum
53
- expect(subject.color_entry(0).color3).to be >= 0
54
+ it 'has 4 Fixnum values, >= 0' do
55
+ expect(subject.color_entry(0).color1).to eq 0
56
+ expect(subject.color_entry(0).color2).to eq 0
57
+ expect(subject.color_entry(0).color3).to eq 0
58
+ expect(subject.color_entry(0).color4).to eq 255
54
59
 
55
- expect(subject.color_entry(0).color4).to be_a Fixnum
56
- expect(subject.color_entry(0).color4).to be >= 0
60
+ expect(subject.color_entry(1).color1).to eq 192
61
+ expect(subject.color_entry(1).color2).to eq 0
62
+ expect(subject.color_entry(1).color3).to eq 0
63
+ expect(subject.color_entry(1).color4).to eq 255
57
64
  end
58
65
  end
59
66
  end
67
+
68
+ context 'file without color table' do
69
+ let(:original_tiff) do
70
+ path = '../../../spec/support/images/osgeo/geotiff/gdal_eg/cea.tif'
71
+ File.expand_path(path, __dir__)
72
+ end
73
+
74
+ it { is_expected.to be_nil }
75
+ end
60
76
  end
@@ -1,90 +1,339 @@
1
1
  require 'spec_helper'
2
- require 'support/integration_help'
3
2
  require 'ffi-gdal'
3
+ require 'gdal'
4
4
 
5
- TIF_FILES.each do |file|
6
- RSpec.describe 'Dataset Info' do
7
- subject do
8
- GDAL::Dataset.open(file, 'r')
5
+ RSpec.describe 'Dataset Info', type: :integration do
6
+ let(:tmp_tiff) { make_temp_test_file(original_tiff) }
7
+
8
+ let(:original_tiff) do
9
+ path = '../../../spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif'
10
+ File.expand_path(path, __dir__)
11
+ end
12
+
13
+ subject { GDAL::Dataset.open(tmp_tiff, 'r') }
14
+
15
+ after { subject.close if File.exist?(tmp_tiff) }
16
+
17
+ describe '#driver' do
18
+ it 'is a GDAL::Driver' do
19
+ expect(subject.driver).to be_a GDAL::Driver
20
+ end
21
+ end
22
+
23
+ describe '#file_list' do
24
+ it 'is a non-empty Array' do
25
+ expect(subject.file_list).to be_an Array
9
26
  end
10
27
 
11
- it_behaves_like 'a major object'
28
+ it 'contains the file name' do
29
+ expect(subject.file_list).to include(File.expand_path(tmp_tiff))
30
+ end
31
+ end
12
32
 
13
- describe '#driver' do
14
- it 'is a GDAL::Driver' do
15
- expect(subject.driver).to be_a GDAL::Driver
33
+ describe '#flush_cache' do
34
+ it 'is a GDAL::Driver' do
35
+ expect { subject.flush_cache }.to_not raise_exception
36
+ end
37
+ end
38
+
39
+ describe '#raster_x_size' do
40
+ it 'is a Fixnum' do
41
+ expect(subject.raster_x_size).to eq 101
42
+ end
43
+ end
44
+
45
+ describe '#raster_y_size' do
46
+ it 'is a Fixnum' do
47
+ expect(subject.raster_y_size).to eq 101
48
+ end
49
+ end
50
+
51
+ describe '#raster_count' do
52
+ it 'is a Fixnum' do
53
+ expect(subject.raster_count).to eq 1
54
+ end
55
+ end
56
+
57
+ describe '#raster_band' do
58
+ it 'each band is a GDAL::RasterBand' do
59
+ 1.upto(subject.raster_count) do |i|
60
+ expect(subject.raster_band(i)).to be_a GDAL::RasterBand
16
61
  end
17
62
  end
63
+ end
64
+
65
+ describe '#projection' do
66
+ it 'is a String' do
67
+ expect(subject.projection).to be_a String
68
+ end
69
+ end
18
70
 
19
- describe '#file_list' do
20
- it 'is a non-empty Array' do
21
- expect(subject.file_list).to be_an Array
71
+ describe '#projection=' do
72
+ context 'param is an invalid projection string' do
73
+ it 'raises a GDAL::Error' do
74
+ expect { subject.projection = 'meow' }.to raise_exception(GDAL::Error)
22
75
  end
76
+ end
23
77
 
24
- it 'contains the file name' do
25
- expect(subject.file_list).to include(File.expand_path(file))
78
+ context 'param is an valid projection string' do
79
+ let(:wkt) do
80
+ <<-WKT
81
+ GEOGCS["WGS 84",
82
+ DATUM["WGS_1984",
83
+ SPHEROID["WGS 84",6378137,298.257223563,
84
+ AUTHORITY["EPSG",7030]],
85
+ TOWGS84[0,0,0,0,0,0,0],
86
+ AUTHORITY["EPSG",6326]],
87
+ PRIMEM["Greenwich",0,AUTHORITY["EPSG",8901]],
88
+ UNIT["DMSH",0.0174532925199433,AUTHORITY["EPSG",9108]],
89
+ AXIS["Lat",NORTH],
90
+ AXIS["Long",EAST],
91
+ AUTHORITY["EPSG",4326]]
92
+ WKT
93
+ end
94
+
95
+ it 'sets the projection' do
96
+ subject.projection = wkt
97
+ expect(subject.projection).to eq wkt
98
+ end
99
+ end
100
+
101
+ context 'param is not a string' do
102
+ it 'raises a GDAL::Error' do
103
+ expect { subject.projection = { one: 1 } }.to raise_exception(GDAL::Error)
104
+ end
105
+ end
106
+ end
107
+
108
+ describe '#access_flag' do
109
+ it 'is GA_ReadOnly' do
110
+ expect(subject.access_flag).to be :GA_ReadOnly
111
+ end
112
+ end
113
+
114
+ describe '#add_band' do
115
+ it 'raises a GDAL::UnsupportedOperation' do
116
+ expect { subject.add_band(:GDT_Byte) }.to raise_exception(GDAL::UnsupportedOperation)
117
+ end
118
+ end
119
+
120
+ describe '#create_mask_band' do
121
+ context ':GMF_ALL_VALID' do
122
+ it 'returns true' do
123
+ expect(subject.create_mask_band(:GMF_ALL_VALID)).to eq true
26
124
  end
27
125
  end
28
126
 
29
- describe '#raster_x_size' do
30
- it 'is a Fixnum' do
31
- expect(subject.raster_x_size).to be_a Fixnum
127
+ context ':GMF_PER_DATASET' do
128
+ it 'returns true' do
129
+ expect(subject.create_mask_band(:GMF_PER_DATASET)).to eq true
32
130
  end
33
131
  end
34
132
 
35
- describe '#raster_y_size' do
36
- it 'is a Fixnum' do
37
- expect(subject.raster_y_size).to be_a Fixnum
133
+ context ':GMF_PER_ALPHA' do
134
+ it 'returns true' do
135
+ expect(subject.create_mask_band(:GMF_PER_ALPHA)).to eq true
38
136
  end
39
137
  end
40
138
 
41
- describe '#raster_count' do
42
- it 'is a Fixnum' do
43
- expect(subject.raster_count).to be_a Fixnum
139
+ context ':GMF_NODATA' do
140
+ it 'returns true' do
141
+ expect(subject.create_mask_band(:GMF_NODATA)).to eq true
44
142
  end
45
143
  end
46
144
 
47
- describe '#raster_band' do
48
- it 'each band is a GDAL::RasterBand' do
49
- 1.upto(subject.raster_count) do |i|
50
- expect(subject.raster_band(i)).to be_a GDAL::RasterBand
51
- end
145
+ context 'all flags' do
146
+ it 'returns true' do
147
+ expect(subject.create_mask_band(:GMF_ALL_VALID, :GMF_PER_DATASET, :GMF_PER_ALPHA, :GMF_NODATA)).to eq true
52
148
  end
53
149
  end
150
+ end
151
+
152
+ describe '#geo_transform' do
153
+ it 'is a GDAL::GeoTransform' do
154
+ expect(subject.geo_transform).to be_a GDAL::GeoTransform
155
+ end
156
+ end
157
+
158
+ describe '#geo_transform=' do
159
+ let(:geo_transform) { GDAL::GeoTransform.new }
54
160
 
55
- describe '#projection' do
56
- it 'is a String' do
57
- expect(subject.projection).to be_a String
161
+ context 'read-only dataset' do
162
+ it 'raises a GDAL::UnsupportedOperation' do
163
+ expect { subject.geo_transform = geo_transform }.to raise_exception GDAL::UnsupportedOperation
58
164
  end
59
165
  end
60
166
 
61
- describe '#access_flag' do
62
- it 'is GA_ReadOnly' do
63
- expect(subject.access_flag).to be :GA_ReadOnly
167
+ context 'writable dataset, param is a valid GeoTransform' do
168
+ subject { GDAL::Dataset.open(tmp_tiff, 'w') }
169
+
170
+ it 'returns the same GDAL::GeoTransform' do
171
+ subject.geo_transform = geo_transform
172
+ expect(subject.geo_transform).to eq geo_transform
64
173
  end
65
174
  end
66
175
 
67
- describe '#geo_transform' do
68
- it 'is a GDAL::GeoTransform' do
176
+ context 'writable dataset, param is a pointer to a valid GeoTransform' do
177
+ subject { GDAL::Dataset.open(tmp_tiff, 'w') }
178
+
179
+ it 'returns the same GDAL::GeoTransform' do
180
+ subject.geo_transform = geo_transform.c_pointer
69
181
  expect(subject.geo_transform).to be_a GDAL::GeoTransform
70
182
  end
71
183
  end
184
+ end
185
+
186
+ describe '#gcp_count' do
187
+ it 'is a Fixnum' do
188
+ expect(subject.gcp_count).to be_a Fixnum
189
+ end
190
+ end
191
+
192
+ describe '#gcp_projection' do
193
+ it 'is a String' do
194
+ expect(subject.gcp_projection).to be_a String
195
+ end
196
+ end
197
+
198
+ describe '#gcps' do
199
+ it 'is a GDALGCP' do
200
+ expect(subject.gcps).to be_a FFI::GDAL::GCP
201
+ end
202
+ end
203
+
204
+ describe '#build_overviews' do
205
+ let(:ovr_file) { "#{tmp_tiff}.ovr" }
206
+ after { File.unlink(ovr_file) if File.exist?(ovr_file) }
207
+
208
+ context 'nearest neighbor resampling' do
209
+ it 'creates an .ovr file with the same base name as the dataset file' do
210
+ subject.build_overviews(:nearest, [2, 4, 8])
211
+ expect(File.exist?(ovr_file)).to eq true
212
+ end
213
+ end
72
214
 
73
- describe '#gcp_count' do
74
- it 'is a Fixnum' do
75
- expect(subject.gcp_count).to be_a Fixnum
215
+ context 'Gauss resampling' do
216
+ it 'creates an .ovr file with the same base name as the dataset file' do
217
+ subject.build_overviews(:gauss, [2, 4, 8])
218
+ expect(File.exist?(ovr_file)).to eq true
76
219
  end
77
220
  end
78
221
 
79
- describe '#gcp_projection' do
80
- it 'is a String' do
81
- expect(subject.gcp_projection).to be_a String
222
+ context 'Cubic resampling' do
223
+ it 'creates an .ovr file with the same base name as the dataset file' do
224
+ subject.build_overviews(:cubic, [2, 4, 8])
225
+ expect(File.exist?(ovr_file)).to eq true
226
+ end
227
+ end
228
+
229
+ context 'Average resampling' do
230
+ it 'creates an .ovr file with the same base name as the dataset file' do
231
+ subject.build_overviews(:average, [2, 4, 8])
232
+ expect(File.exist?(ovr_file)).to eq true
233
+ end
234
+ end
235
+
236
+ context 'Mode resampling' do
237
+ it 'creates an .ovr file with the same base name as the dataset file' do
238
+ subject.build_overviews(:mode, [2, 4, 8])
239
+ expect(File.exist?(ovr_file)).to eq true
240
+ end
241
+ end
242
+
243
+ context 'Average mag phase resampling' do
244
+ it 'creates an .ovr file with the same base name as the dataset file' do
245
+ subject.build_overviews(:average_magphase, [2, 4, 8])
246
+ expect(File.exist?(ovr_file)).to eq true
247
+ end
248
+ end
249
+
250
+ context 'no resampling' do
251
+ it 'creates an .ovr file with the same base name as the dataset file' do
252
+ subject.build_overviews(:none, [2, 4, 8])
253
+ expect(File.exist?(ovr_file)).to eq true
254
+ end
255
+ end
256
+
257
+ context 'unknown resampling algorithm' do
258
+ it 'creates an .ovr file with the same base name as the dataset file' do
259
+ expect { subject.build_overviews(:stuff, [2, 4, 8]) }.
260
+ to raise_exception(GDAL::Error)
261
+ end
262
+ end
263
+ end
264
+
265
+ describe '#raster_io' do
266
+ let(:write_buffer) do
267
+ buffer = GDAL._buffer_from_data_type(:GDT_Byte, 2)
268
+ buffer.write_array_of_uchar([1, 2])
269
+ end
270
+
271
+ let(:read_buffer) { GDAL._buffer_from_data_type(:GDT_Byte, 2) }
272
+
273
+ context 'write to read-only dataset' do
274
+ it 'raises a GDAL::Error when flushing the cache' do
275
+ expect do
276
+ subject.raster_io('w', write_buffer, x_size: 2, y_size: 1)
277
+ subject.flush_cache
278
+ end.to raise_exception(GDAL::Error)
279
+ end
280
+ end
281
+
282
+ context 'write using buffer that is too small for defaults' do
283
+ subject { GDAL::Dataset.open(tmp_tiff, 'w') }
284
+
285
+ it 'raises a GDAL::Error when flushing the cache' do
286
+ expect do
287
+ subject.raster_io('w', write_buffer)
288
+ subject.flush_cache
289
+ end.to raise_exception(GDAL::BufferTooSmall)
290
+ end
291
+ end
292
+
293
+ context 'write to writable dataset' do
294
+ subject { GDAL::Dataset.open(tmp_tiff, 'w') }
295
+
296
+ it 'writes the data' do
297
+ expect do
298
+ subject.raster_io('w', write_buffer, x_size: 2, y_size: 1)
299
+ subject.flush_cache
300
+ end.to_not raise_exception
301
+ end
302
+ end
303
+
304
+ context 'read, buffer size too small' do
305
+ it 'raises a GDAL::BufferTooSmall' do
306
+ expect { subject.raster_io('r', read_buffer) }.
307
+ to raise_exception GDAL::BufferTooSmall
308
+ end
309
+ end
310
+
311
+ context 'read, giving params that fulfil buffer size requirements' do
312
+ it 'reads the data' do
313
+ subject.raster_io('r', read_buffer, x_size: 2, y_size: 1)
314
+ expect(read_buffer.read_array_of_uchar(2)).to eq [2, 2]
315
+ end
316
+ end
317
+ end
318
+
319
+ describe '#valid_min_buffer_size' do
320
+ it 'returns the number of bytes for the GDT type * x buffer size * y buffer size' do
321
+ expect(subject.send(:valid_min_buffer_size, :GDT_Float32, 3, 4)).to eq 48
322
+ end
323
+ end
324
+
325
+ describe '#band_numbers_args' do
326
+ context 'param is nil' do
327
+ it 'returns no pointer and 0 band count' do
328
+ expect(subject.send(:band_numbers_args, nil)).to eq [nil, 0]
82
329
  end
83
330
  end
84
331
 
85
- describe '#gcps' do
86
- it 'is a GDALGCP' do
87
- expect(subject.gcps).to be_a FFI::GDAL::GCP
332
+ context 'param is an array of numbers' do
333
+ it 'returns a pointer and the number of bands' do
334
+ result_ptr, band_count = subject.send(:band_numbers_args, [3, 4, 5])
335
+ expect(result_ptr).to be_a FFI::MemoryPointer
336
+ expect(band_count).to eq 3
88
337
  end
89
338
  end
90
339
  end