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,329 +1,298 @@
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
- dataset = GDAL::Dataset.open(file, 'r')
5
+ RSpec.describe 'Raster Band Info', type: :integration do
6
+ let(:original_tiff) do
7
+ path = '../../../spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif'
8
+ File.expand_path(path, __dir__)
9
+ end
7
10
 
8
- dataset.each_band do |band_under_test|
9
- RSpec.describe 'Raster Band Info' do
10
- after :suite do
11
- dataset.close
12
- end
11
+ let(:tmp_tiff) { make_temp_test_file(original_tiff) }
12
+ let(:dataset) { GDAL::Dataset.open(tmp_tiff, 'w') }
13
+ after { dataset.close }
14
+ subject { dataset.raster_band(1) }
13
15
 
14
- # TODO: Test against each raster band
15
- subject do
16
- GDAL::RasterBand.new(band_under_test.c_pointer)
17
- end
16
+ it_behaves_like 'a major object'
18
17
 
19
- it_behaves_like 'a major object'
18
+ describe '#x_size' do
19
+ it 'is a non-zero Integer' do
20
+ expect(subject.x_size).to be_a Fixnum
21
+ expect(subject.x_size).to be > 0
22
+ end
23
+ end
20
24
 
21
- describe '#x_size' do
22
- it 'is a non-zero Integer' do
23
- expect(subject.x_size).to be_a Fixnum
24
- expect(subject.x_size).to be > 0
25
- end
26
- end
25
+ describe '#y_size' do
26
+ it 'is a non-zero Integer' do
27
+ expect(subject.y_size).to be_a Fixnum
28
+ expect(subject.y_size).to be > 0
29
+ end
30
+ end
27
31
 
28
- describe '#y_size' do
29
- it 'is a non-zero Integer' do
30
- expect(subject.y_size).to be_a Fixnum
31
- expect(subject.y_size).to be > 0
32
- end
33
- end
32
+ describe '#access_flag' do
33
+ specify { expect(subject.access_flag).to eq :GA_Update }
34
+ end
34
35
 
35
- describe '#access_flag' do
36
- specify { expect(subject.access_flag).to eq :GA_ReadOnly }
37
- end
36
+ describe '#number' do
37
+ it 'is a non-zero Integer' do
38
+ expect(subject.number).to be_a Fixnum
39
+ expect(subject.number).to be > 0
40
+ end
41
+ end
38
42
 
39
- describe '#number' do
40
- it 'is a non-zero Integer' do
41
- expect(subject.number).to be_a Fixnum
42
- expect(subject.number).to be > 0
43
- end
44
- end
43
+ describe '#color_interpretation' do
44
+ it 'is a Symbol; one of FFI::GDAL::GDAL::ColorInterp' do
45
+ expect(subject.color_interpretation).to be_a Symbol
46
+ expect(FFI::GDAL::GDAL::ColorInterp.symbols).to include subject.color_interpretation
47
+ end
48
+ end
45
49
 
46
- describe '#color_interpretation' do
47
- it 'is a Symbol; one of FFI::GDAL::ColorInterp' do
48
- expect(subject.color_interpretation).to be_a Symbol
49
- expect(FFI::GDAL::ColorInterp.symbols).to include subject.color_interpretation
50
- end
50
+ describe '#color_table' do
51
+ it 'is a GDAL::ColorTable' do
52
+ if subject.color_table
53
+ expect(subject.color_table).to be_a GDAL::ColorTable
51
54
  end
55
+ end
56
+ end
52
57
 
53
- describe '#color_table' do
54
- it 'is a GDAL::ColorTable' do
55
- if subject.color_table
56
- expect(subject.color_table).to be_a GDAL::ColorTable
57
- end
58
- end
59
- end
58
+ describe '#data_type' do
59
+ it 'is a Symbol; one of FFI::GDAL::GDAL::DataType' do
60
+ expect(subject.data_type).to be_a Symbol
61
+ expect(FFI::GDAL::GDAL::DataType.symbols).to include subject.data_type
62
+ end
63
+ end
60
64
 
61
- describe '#data_type' do
62
- it 'is a Symbol; one of FFI::GDAL::DataType' do
63
- expect(subject.data_type).to be_a Symbol
64
- expect(FFI::GDAL::DataType.symbols).to include subject.data_type
65
- end
66
- end
65
+ describe '#block_size' do
66
+ it 'is a Hash with x and y keys that are >= 1' do
67
+ expect(subject.block_size).to be_a Hash
68
+ expect(subject.block_size[:x]).to be >= 1
69
+ expect(subject.block_size[:y]).to be >= 1
70
+ end
71
+ end
72
+
73
+ describe '#category_names' do
74
+ it 'is an Array of Strings' do
75
+ expect(subject.category_names).to be_an Array
67
76
 
68
- describe '#block_size' do
69
- it 'is a Hash with x and y keys that are >= 1' do
70
- expect(subject.block_size).to be_a Hash
71
- expect(subject.block_size[:x]).to be >= 1
72
- expect(subject.block_size[:y]).to be >= 1
73
- end
77
+ subject.category_names.each do |category_name|
78
+ expect(category_name).to be_a String
79
+ expect(category_name).to_not be_empty
74
80
  end
81
+ end
82
+ end
75
83
 
76
- describe '#category_names' do
77
- it 'is an Array of Strings' do
78
- expect(subject.category_names).to be_an Array
84
+ describe '#category_names=' do
85
+ it 'sets the category names' do
86
+ subject.category_names = %w[one two three]
79
87
 
80
- subject.category_names.each do |category_name|
81
- expect(category_name).to be_a String
82
- expect(category_name).to_not be_empty
83
- end
84
- end
85
- end
88
+ expect(subject.category_names).to eq %w[one two three]
89
+ end
90
+ end
86
91
 
87
- describe '#category_names=' do
88
- around do |example|
89
- category_names = subject.category_names
90
- example.run
91
- subject.category_names = category_names
92
- end
92
+ describe '#no_data_value' do
93
+ it 'is a Hash with :value and :is_associated keys' do
94
+ expect(subject.no_data_value).to be_an Hash
93
95
 
94
- it 'sets the category names' do
95
- expect(subject.category_names).to be_empty
96
+ expect(subject.no_data_value[:value]).to be_a Float
97
+ expect(subject.no_data_value[:is_associated]).to_not be_nil
98
+ end
99
+ end
96
100
 
97
- subject.category_names = %w[one two three]
101
+ describe '#overview_count' do
102
+ it 'is a Fixnum' do
103
+ expect(subject.overview_count).to be_a Fixnum
104
+ end
105
+ end
98
106
 
99
- expect(subject.category_names).to eq %w[one two three]
100
- end
101
- end
107
+ describe '#arbitrary_overviews?' do
108
+ it 'is true or false' do
109
+ expect([true, false]).to include subject.arbitrary_overviews?
110
+ end
111
+ end
102
112
 
103
- describe '#no_data_value' do
104
- it 'is a Hash with :value and :is_associated keys' do
105
- expect(subject.no_data_value).to be_an Hash
113
+ describe '#overview' do
114
+ it 'returns a GDAL::RasterBand if the overview exists' do
115
+ overview = subject.overview(0)
116
+ expect(overview).to be_a GDAL::RasterBand if overview
117
+ end
118
+ end
106
119
 
107
- expect(subject.no_data_value[:value]).to be_a Float
108
- expect(subject.no_data_value[:is_associated]).to_not be_nil
109
- end
110
- end
120
+ describe '#raster_sample_overview' do
121
+ it 'returns a GDAL::RasterBand if the overview exists' do
122
+ overview = subject.raster_sample_overview
123
+ expect(overview).to be_a GDAL::RasterBand
124
+ end
125
+ end
111
126
 
112
- describe '#overview_count' do
113
- it 'is a Fixnum' do
114
- expect(subject.overview_count).to be_a Fixnum
115
- end
116
- end
127
+ describe '#mask_band' do
128
+ it 'returns a GDAL::RasterBand if the mask_band exists' do
129
+ overview = subject.mask_band
130
+ expect(overview).to be_a GDAL::RasterBand
131
+ end
132
+ end
117
133
 
118
- describe '#arbitrary_overviews?' do
119
- it 'is true or false' do
120
- expect([true, false]).to include subject.arbitrary_overviews?
121
- end
122
- end
134
+ describe '#mask_flags' do
135
+ it 'returns an Array of Symbols' do
136
+ expect(subject.mask_flags).to eq([:GMF_ALL_VALID]).or eq([:GMF_PER_DATASET])
137
+ end
138
+ end
123
139
 
124
- describe '#overview' do
125
- it 'returns a GDAL::RasterBand if the overview exists' do
126
- overview = subject.overview(0)
127
- expect(overview).to be_a GDAL::RasterBand if overview
128
- end
129
- end
140
+ describe '#statistics' do
141
+ it 'returns a Hash with populated values' do
142
+ expect(subject.statistics).to be_a Hash
143
+ expect(%i[minimum maximum mean standard_deviation]).
144
+ to eq subject.statistics.keys
145
+ end
130
146
 
131
- describe '#raster_sample_overview' do
132
- it 'returns a GDAL::RasterBand if the overview exists' do
133
- overview = subject.raster_sample_overview
134
- expect(overview).to be_a GDAL::RasterBand
135
- end
147
+ it 'has a :minimum that ranges between 0.0/-32768.0 and 255.0' do
148
+ min = subject.statistics[:minimum]
149
+ unless min == -32_768.0
150
+ expect(subject.statistics[:minimum]).to satisfy { |v| v >= 0 || v == -32_768 }
151
+ expect(subject.statistics[:minimum]).to be <= 255.0
136
152
  end
153
+ end
154
+ end
137
155
 
138
- describe '#mask_band' do
139
- it 'returns a GDAL::RasterBand if the mask_band exists' do
140
- overview = subject.mask_band
141
- expect(overview).to be_a GDAL::RasterBand
142
- end
143
- end
156
+ describe '#scale' do
157
+ it 'returns a Hash with populated values' do
158
+ expect(subject.scale).to be_a Hash
159
+ expect(%i[value is_meaningful]).to eq subject.scale.keys
160
+ end
144
161
 
145
- describe '#mask_flags' do
146
- it 'returns an Array of Symbols' do
147
- expect(subject.mask_flags).to eq([:GMF_ALL_VALID]).or eq([:GMF_PER_DATASET])
148
- end
149
- end
162
+ it 'has a :value that is a Float' do
163
+ expect(subject.scale[:value]).to be_a Float
164
+ end
150
165
 
151
- describe '#statistics' do
152
- it 'returns a Hash with populated values' do
153
- expect(subject.statistics).to be_a Hash
154
- expect(%i[minimum maximum mean standard_deviation]).
155
- to eq subject.statistics.keys
156
- end
157
-
158
- it 'has a :minimum that ranges between 0.0/-32768.0 and 255.0' do
159
- min = subject.statistics[:minimum]
160
- unless min == -32_768.0
161
- expect(subject.statistics[:minimum]).to (be >= 0.0).or eq(-32_768.0)
162
- expect(subject.statistics[:minimum]).to be <= 255.0
163
- end
164
- end
165
- end
166
+ it 'has a :is_meaningful that is false (since the examples are geotiffs)' do
167
+ expect(subject.scale[:is_meaningful]).to eq false
168
+ end
169
+ end
166
170
 
167
- describe '#scale' do
168
- it 'returns a Hash with populated values' do
169
- expect(subject.scale).to be_a Hash
170
- expect(%i[value is_meaningful]).to eq subject.scale.keys
171
- end
171
+ describe '#scale=' do
172
+ it 'does nothing (because the file formats dont support it)' do
173
+ subject.scale = 0.1
174
+ expect(subject.scale[:value]).to eq 0.1
175
+ end
176
+ end
172
177
 
173
- it 'has a :value that is a Float' do
174
- expect(subject.scale[:value]).to be_a Float
175
- end
178
+ describe '#offset' do
179
+ it 'returns a Hash with populated values' do
180
+ expect(subject.offset).to be_a Hash
181
+ expect(%i[value is_meaningful]).to eq subject.offset.keys
182
+ end
176
183
 
177
- it 'has a :is_meaningful that is false (since the examples are geotiffs)' do
178
- expect(subject.scale[:is_meaningful]).to eq false
179
- end
180
- end
184
+ it 'has a :value that is a Float' do
185
+ expect(subject.offset[:value]).to be_a Float
186
+ end
181
187
 
182
- describe '#scale=' do
183
- around do |example|
184
- scale = subject.scale[:value]
185
- example.run
186
- subject.scale = scale
187
- end
188
-
189
- it 'does nothing (because the file formats dont support it)' do
190
- subject.scale = 0.1
191
- expect(subject.scale[:value]).to eq 0.1
192
- end
193
- end
188
+ it 'has a :is_meaningful that is false (since the examples are geotiffs)' do
189
+ expect(subject.offset[:is_meaningful]).to eq false
190
+ end
191
+ end
194
192
 
195
- describe '#offset' do
196
- it 'returns a Hash with populated values' do
197
- expect(subject.offset).to be_a Hash
198
- expect(%i[value is_meaningful]).to eq subject.offset.keys
199
- end
193
+ describe '#offset=' do
194
+ it 'does nothing (because the file formats dont support it)' do
195
+ subject.offset = 0.1
196
+ expect(subject.offset[:value]).to eq 0.1
197
+ end
198
+ end
200
199
 
201
- it 'has a :value that is a Float' do
202
- expect(subject.offset[:value]).to be_a Float
203
- end
200
+ describe '#unit_type' do
201
+ it 'returns a String' do
202
+ expect(subject.unit_type).to be_a String
203
+ end
204
+ end
204
205
 
205
- it 'has a :is_meaningful that is false (since the examples are geotiffs)' do
206
- expect(subject.offset[:is_meaningful]).to eq false
207
- end
206
+ describe '#unit_type=' do
207
+ it 'does nothing (because the file formats dont support it)' do
208
+ if defined? FFI::GDAL::GDAL::GDALSetRasterUnitType
209
+ subject.unit_type = 'ft'
210
+ expect(subject.unit_type).to eq 'ft'
211
+ else
212
+ skip 'GDALSetRasterUnitType not supported'
208
213
  end
214
+ end
215
+ end
209
216
 
210
- describe '#offset=' do
211
- around do |example|
212
- offset = subject.offset[:value]
213
- example.run
214
- subject.offset = offset
215
- end
216
-
217
- it 'does nothing (because the file formats dont support it)' do
218
- subject.offset = 0.1
219
- expect(subject.offset[:value]).to eq 0.1
220
- end
221
- end
217
+ describe '#default_histogram' do
218
+ let!(:histogram) { subject.default_histogram }
222
219
 
223
- describe '#unit_type' do
224
- it 'returns a String' do
225
- expect(subject.unit_type).to be_a String
226
- end
220
+ it 'returns a Hash with :minimum, :maximum, :buckets, and :totals' do
221
+ if histogram
222
+ expect(histogram).to be_a Hash
223
+ expect(histogram.keys).to eq %i[minimum maximum buckets totals]
227
224
  end
225
+ end
228
226
 
229
- describe '#unit_type=' do
230
- around do |example|
231
- unit_type = subject.unit_type
232
- example.run
233
- subject.unit_type = unit_type
234
- end
235
-
236
- it 'does nothing (because the file formats dont support it)' do
237
- if defined? FFI::GDAL::GDALSetRasterUnitType
238
- subject.unit_type = 'ft'
239
- expect(subject.unit_type).to eq 'ft'
240
- else
241
- skip 'GDALSetRasterUnitType not supported'
242
- end
243
- end
244
- end
227
+ it 'has :minimum as a Float' do
228
+ expect(histogram[:minimum]).to be_a Float if histogram
229
+ end
245
230
 
246
- describe '#default_histogram' do
247
- let!(:histogram) { subject.default_histogram }
248
-
249
- it 'returns a Hash with :minimum, :maximum, :buckets, and :totals' do
250
- if histogram
251
- expect(histogram).to be_a Hash
252
- expect(histogram.keys).to eq %i[minimum maximum buckets totals]
253
- end
254
- end
255
-
256
- it 'has :minimum as a Float' do
257
- expect(histogram[:minimum]).to be_a Float if histogram
258
- end
259
-
260
- it 'has :maximum as a Float' do
261
- expect(histogram[:maximum]).to be_a Float if histogram
262
- end
263
-
264
- it 'has :buckets as a Fixnum' do
265
- expect(histogram[:buckets]).to be_a Fixnum if histogram
266
- end
267
-
268
- it 'has :totals as an Array of 0 or 256 Fixnums' do
269
- if histogram
270
- expect(histogram[:totals]).to be_an Array
271
- expect(histogram[:totals].size).to eq(256).or eq(0)
272
- expect(histogram[:totals].all? { |t| t.class == Fixnum }).to eq true
273
- end
274
- end
275
- end
231
+ it 'has :maximum as a Float' do
232
+ expect(histogram[:maximum]).to be_a Float if histogram
233
+ end
276
234
 
277
- describe '#default_raster_attribute_table' do
278
- it 'returns a GDAL::RasterAttributeTable' do
279
- rat = subject.default_raster_attribute_table
235
+ it 'has :buckets as a Fixnum' do
236
+ expect(histogram[:buckets]).to be_a Fixnum if histogram
237
+ end
280
238
 
281
- expect(rat).to be_a GDAL::RasterAttributeTable if rat
282
- end
239
+ it 'has :totals as an Array of 0 or 256 Fixnums' do
240
+ if histogram
241
+ expect(histogram[:totals]).to be_an Array
242
+ expect(histogram[:totals].size).to eq(256).or eq(0)
243
+ expect(histogram[:totals].all? { |t| t.class == Fixnum }).to eq true
283
244
  end
245
+ end
246
+ end
284
247
 
285
- describe '#min_max' do
286
- it 'returns a Hash with :min and :max keys' do
287
- expect(subject.min_max).to be_a Hash
288
- expect(subject.min_max.size).to eq 2
289
- expect(subject.min_max[:min]).to be_a Float
290
- expect(subject.min_max[:max]).to be_a Float
291
- end
292
-
293
- it 'has a min that is < its max' do
294
- expect(subject.min_max[:min]).to be < subject.min_max[:max]
295
- end
296
- end
248
+ describe '#default_raster_attribute_table' do
249
+ it 'returns a GDAL::RasterAttributeTable' do
250
+ rat = subject.default_raster_attribute_table
297
251
 
298
- describe '#minimum_value' do
299
- it 'returns a Hash with populated values' do
300
- expect(subject.minimum_value).to be_a Hash
301
- expect(%i[value is_tight]).to eq subject.minimum_value.keys
302
- end
252
+ expect(rat).to be_a GDAL::RasterAttributeTable if rat
253
+ end
254
+ end
303
255
 
304
- it 'has a :value that is a Float' do
305
- expect(subject.minimum_value[:value]).to be_a Float
306
- end
256
+ describe '#min_max' do
257
+ it 'returns a Hash with :min and :max keys' do
258
+ expect(subject.min_max).to be_a Hash
259
+ expect(subject.min_max.size).to eq 2
260
+ expect(subject.min_max[:min]).to be_a Float
261
+ expect(subject.min_max[:max]).to be_a Float
262
+ end
307
263
 
308
- it 'has a :is_tight that is nil (since the examples are geotiffs)' do
309
- # expect(subject.minimum_value[:is_tight]).to eq nil
310
- end
311
- end
264
+ it 'has a min that is < its max' do
265
+ expect(subject.min_max[:min]).to be < subject.min_max[:max]
266
+ end
267
+ end
312
268
 
313
- describe '#maximum_value' do
314
- it 'returns a Hash with populated values' do
315
- expect(subject.maximum_value).to be_a Hash
316
- expect(%i[value is_tight]).to eq subject.maximum_value.keys
317
- end
269
+ describe '#minimum_value' do
270
+ it 'returns a Hash with populated values' do
271
+ expect(subject.minimum_value).to be_a Hash
272
+ expect(%i[value is_tight]).to eq subject.minimum_value.keys
273
+ end
318
274
 
319
- it 'has a :value that is a Float' do
320
- expect(subject.maximum_value[:value]).to be_a Float
321
- end
275
+ it 'has a :value that is a Float' do
276
+ expect(subject.minimum_value[:value]).to be_a Float
277
+ end
322
278
 
323
- it 'has a :is_tight that is nil (since the examples are geotiffs)' do
324
- # expect(subject.maximum_value[:is_tight]).to eq nil
325
- end
326
- end
279
+ it 'has a :is_tight that is nil (since the examples are geotiffs)' do
280
+ # expect(subject.minimum_value[:is_tight]).to eq nil
281
+ end
282
+ end
283
+
284
+ describe '#maximum_value' do
285
+ it 'returns a Hash with populated values' do
286
+ expect(subject.maximum_value).to be_a Hash
287
+ expect(%i[value is_tight]).to eq subject.maximum_value.keys
288
+ end
289
+
290
+ it 'has a :value that is a Float' do
291
+ expect(subject.maximum_value[:value]).to be_a Float
292
+ end
293
+
294
+ it 'has a :is_tight that is nil (since the examples are geotiffs)' do
295
+ # expect(subject.maximum_value[:is_tight]).to eq nil
327
296
  end
328
297
  end
329
298
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
+ require 'ogr'
2
3
 
3
- RSpec.describe OGR::Layer do
4
+ RSpec.describe 'OGR::Layer' do
4
5
  let(:data_source) do
5
6
  OGR::DataSource.open('spec/support/shapefiles/states_21basic/states.shp', 'r')
6
7
  end
@@ -35,6 +36,7 @@ RSpec.describe OGR::Layer do
35
36
 
36
37
  describe '#next_feature' do
37
38
  subject { layer0.next_feature }
39
+ after { subject.destroy! }
38
40
  it { is_expected.to be_a OGR::Feature }
39
41
  end
40
42
 
data/spec/spec_helper.rb CHANGED
@@ -9,9 +9,9 @@ end
9
9
 
10
10
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
11
11
  require 'ffi-gdal'
12
+ require 'byebug'
12
13
 
13
- require './spec/support/shared_contexts'
14
- Dir['./spec/support/shared_examples/**/*.rb'].sort.each { |f| require f }
14
+ Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
15
15
 
16
16
  # This file was generated by the `rspec --init` command. Conventionally, all
17
17
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -81,13 +81,13 @@ RSpec.configure do |config|
81
81
  # Use the documentation formatter for detailed output,
82
82
  # unless a formatter has already been configured
83
83
  # (e.g. via a command-line flag).
84
- # config.default_formatter = 'doc'
84
+ config.default_formatter = 'doc'
85
85
  end
86
86
 
87
87
  # Print the 10 slowest examples and example groups at the
88
88
  # end of the spec run, to help surface which specs are running
89
89
  # particularly slow.
90
- config.profile_examples = 3
90
+ config.profile_examples = 10
91
91
 
92
92
  # Run specs in random order to surface order dependencies. If you find an
93
93
  # order dependency and want to debug it, you can fix the order by providing
@@ -100,6 +100,15 @@ RSpec.configure do |config|
100
100
  # test failures related to randomization by passing the same `--seed` value
101
101
  # as the one that triggered the failure.
102
102
  Kernel.srand config.seed
103
- end
104
103
 
105
- GDAL::Logger.logging_enabled = true
104
+ config.include IntegrationHelp, type: :integration
105
+
106
+ config.before do
107
+ ::FFI::GDAL::GDAL.GDALAllRegister
108
+ Dir[File.join('tmp', '*')].each { |f| File.unlink(f) if File.exist?(f) }
109
+ end
110
+
111
+ config.after(:example, type: :integration) do
112
+ cleanup_test_files
113
+ end
114
+ end