ffi-gdal 1.0.0.beta3 → 1.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (286) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +62 -0
  4. data/Gemfile +1 -1
  5. data/History.md +53 -28
  6. data/README.md +6 -0
  7. data/Rakefile +23 -1
  8. data/examples/extract_and_colorize.rb +21 -22
  9. data/examples/geometries.rb +2 -2
  10. data/examples/gridding.rb +106 -0
  11. data/examples/ogr_layer_to_layer.rb +1 -1
  12. data/examples/points.txt +127 -0
  13. data/examples/testing_gdal.rb +3 -4
  14. data/ffi-gdal.gemspec +3 -2
  15. data/lib/ext/error_symbols.rb +2 -57
  16. data/lib/ext/ffi_library_function_checks.rb +26 -0
  17. data/lib/ext/float_ext.rb +2 -2
  18. data/lib/ext/narray_ext.rb +2 -0
  19. data/lib/ext/numeric_as_data_type.rb +19 -0
  20. data/lib/ext/to_bool.rb +4 -4
  21. data/lib/ffi/cpl/conv.rb +132 -0
  22. data/lib/ffi/cpl/error.rb +67 -0
  23. data/lib/ffi/cpl/hash_set.rb +39 -0
  24. data/lib/ffi/cpl/http.rb +25 -0
  25. data/lib/ffi/cpl/http_result.rb +18 -0
  26. data/lib/ffi/cpl/list.rb +38 -0
  27. data/lib/ffi/cpl/mime_part.rb +11 -0
  28. data/lib/ffi/cpl/minixml.rb +47 -0
  29. data/lib/ffi/cpl/port.rb +23 -0
  30. data/lib/ffi/cpl/quad_tree.rb +51 -0
  31. data/lib/ffi/{ogr/ogr_envelope.rb → cpl/rect_obj.rb} +3 -3
  32. data/lib/ffi/cpl/string.rb +95 -0
  33. data/lib/ffi/cpl/vsi.rb +115 -0
  34. data/lib/ffi/cpl/xml_node.rb +6 -6
  35. data/lib/ffi/gdal/alg.rb +385 -0
  36. data/lib/ffi/gdal/{gdal_color_entry.rb → color_entry.rb} +1 -2
  37. data/lib/ffi/gdal/exceptions.rb +6 -0
  38. data/lib/ffi/gdal/{gdal_gcp.rb → gcp.rb} +1 -3
  39. data/lib/ffi/gdal/{gdal_h.rb → gdal.rb} +253 -252
  40. data/lib/ffi/gdal/grid.rb +58 -0
  41. data/lib/ffi/gdal/{gdal_grid_data_metrics_options.rb → grid_data_metrics_options.rb} +1 -2
  42. data/lib/ffi/gdal/{gdal_grid_inverse_distance_to_a_power_options.rb → grid_inverse_distance_to_a_power_options.rb} +1 -2
  43. data/lib/ffi/gdal/{gdal_grid_moving_average_options.rb → grid_moving_average_options.rb} +1 -2
  44. data/lib/ffi/gdal/{gdal_grid_nearest_neighbor_options.rb → grid_nearest_neighbor_options.rb} +1 -2
  45. data/lib/ffi/gdal/matching.rb +20 -0
  46. data/lib/ffi/gdal/{gdal_rpc_info.rb → rpc_info.rb} +1 -2
  47. data/lib/ffi/gdal/{gdal_transformer_info.rb → transformer_info.rb} +1 -2
  48. data/lib/ffi/gdal/version.rb +1 -1
  49. data/lib/ffi/gdal/vrt.rb +92 -0
  50. data/lib/ffi/gdal/{gdal_warp_options.rb → warp_options.rb} +8 -4
  51. data/lib/ffi/gdal/warper.rb +70 -0
  52. data/lib/ffi/gdal.rb +56 -69
  53. data/lib/ffi/ogr/api.rb +567 -0
  54. data/lib/ffi/ogr/{ogr_contour_writer_info.rb → contour_writer_info.rb} +2 -3
  55. data/lib/ffi/ogr/core.rb +181 -0
  56. data/lib/ffi/ogr/envelope.rb +12 -0
  57. data/lib/ffi/ogr/{ogr_envelope_3d.rb → envelope_3d.rb} +2 -2
  58. data/lib/ffi/ogr/featurestyle.rb +29 -0
  59. data/lib/ffi/ogr/field.rb +63 -0
  60. data/lib/ffi/ogr/geocoding.rb +30 -0
  61. data/lib/ffi/ogr/srs_api.rb +407 -0
  62. data/lib/ffi/ogr/style_param.rb +13 -0
  63. data/lib/ffi/ogr/{ogr_style_value.rb → style_value.rb} +4 -3
  64. data/lib/ffi/ogr.rb +7 -7
  65. data/lib/ffi-gdal.rb +7 -145
  66. data/lib/gdal/color_entry.rb +18 -14
  67. data/lib/gdal/color_entry_mixins/extensions.rb +32 -0
  68. data/lib/gdal/color_interpretation.rb +2 -2
  69. data/lib/gdal/color_table.rb +37 -32
  70. data/lib/gdal/color_table_mixins/extensions.rb +48 -0
  71. data/lib/gdal/cpl_error_handler.rb +119 -0
  72. data/lib/gdal/data_type.rb +7 -7
  73. data/lib/gdal/dataset.rb +131 -238
  74. data/lib/gdal/dataset_mixins/algorithm_methods.rb +182 -0
  75. data/lib/gdal/dataset_mixins/extensions.rb +542 -0
  76. data/lib/gdal/dataset_mixins/matching.rb +26 -0
  77. data/lib/gdal/driver.rb +68 -92
  78. data/lib/gdal/driver_mixins/extensions.rb +93 -0
  79. data/lib/gdal/exceptions.rb +32 -4
  80. data/lib/gdal/geo_transform.rb +63 -43
  81. data/lib/gdal/geo_transform_mixins/extensions.rb +57 -0
  82. data/lib/gdal/grid.rb +144 -0
  83. data/lib/gdal/grid_types/data_metrics_base.rb +14 -0
  84. data/lib/gdal/grid_types/inverse_distance_to_a_power.rb +19 -0
  85. data/lib/gdal/grid_types/metric_average_distance.rb +12 -0
  86. data/lib/gdal/grid_types/metric_average_distance_pts.rb +12 -0
  87. data/lib/gdal/grid_types/metric_count.rb +12 -0
  88. data/lib/gdal/grid_types/metric_maximum.rb +12 -0
  89. data/lib/gdal/grid_types/metric_minimum.rb +12 -0
  90. data/lib/gdal/grid_types/metric_range.rb +12 -0
  91. data/lib/gdal/grid_types/moving_average.rb +19 -0
  92. data/lib/gdal/grid_types/nearest_neighbor.rb +19 -0
  93. data/lib/gdal/grid_types.rb +22 -0
  94. data/lib/gdal/internal_helpers.rb +94 -0
  95. data/lib/gdal/major_object.rb +4 -7
  96. data/lib/gdal/options.rb +14 -7
  97. data/lib/gdal/raster_attribute_table.rb +38 -47
  98. data/lib/gdal/raster_attribute_table_mixins/extensions.rb +41 -0
  99. data/lib/gdal/raster_band.rb +193 -227
  100. data/lib/gdal/raster_band_classifier.rb +107 -0
  101. data/lib/gdal/raster_band_mixins/algorithm_methods.rb +292 -0
  102. data/lib/gdal/raster_band_mixins/extensions.rb +238 -0
  103. data/lib/gdal/rpc_info.rb +35 -0
  104. data/lib/gdal/transformer.rb +15 -0
  105. data/lib/gdal/transformers/approximate_transformer.rb +48 -0
  106. data/lib/gdal/transformers/base_general_image_projection_transformer.rb +45 -0
  107. data/lib/gdal/transformers/gcp_transformer.rb +55 -0
  108. data/lib/gdal/transformers/general_image_projection_transformer.rb +31 -0
  109. data/lib/gdal/transformers/general_image_projection_transformer2.rb +52 -0
  110. data/lib/gdal/transformers/general_image_projection_transformer3.rb +25 -0
  111. data/lib/gdal/transformers/geolocation_transformer.rb +42 -0
  112. data/lib/gdal/transformers/reprojection_transformer.rb +39 -0
  113. data/lib/gdal/transformers/rpc_transformer.rb +56 -0
  114. data/lib/gdal/transformers/tps_transformer.rb +40 -0
  115. data/lib/gdal/virtual_dataset.rb +96 -0
  116. data/lib/gdal/warp_operation.rb +20 -23
  117. data/lib/gdal.rb +17 -0
  118. data/lib/ogr/coordinate_transformation.rb +16 -41
  119. data/lib/ogr/data_source.rb +103 -58
  120. data/lib/ogr/data_source_extensions.rb +5 -6
  121. data/lib/ogr/data_source_mixins/capability_methods.rb +27 -0
  122. data/lib/ogr/driver.rb +61 -33
  123. data/lib/ogr/driver_mixins/capability_methods.rb +16 -0
  124. data/lib/ogr/envelope.rb +29 -18
  125. data/lib/ogr/envelope_extensions.rb +70 -49
  126. data/lib/ogr/error_handling.rb +46 -0
  127. data/lib/ogr/exceptions.rb +58 -12
  128. data/lib/ogr/feature.rb +334 -86
  129. data/lib/ogr/feature_definition.rb +94 -51
  130. data/lib/ogr/feature_definition_extensions.rb +36 -13
  131. data/lib/ogr/feature_extensions.rb +62 -11
  132. data/lib/ogr/field.rb +175 -54
  133. data/lib/ogr/field_definition.rb +110 -0
  134. data/lib/ogr/{field_extensions.rb → field_definition_extensions.rb} +4 -5
  135. data/lib/ogr/{geocoding_session.rb → geocoder.rb} +14 -13
  136. data/lib/ogr/geometries/geometry_collection.rb +13 -0
  137. data/lib/ogr/geometries/line_string.rb +35 -0
  138. data/lib/ogr/geometries/linear_ring.rb +11 -0
  139. data/lib/ogr/geometries/multi_line_string.rb +16 -0
  140. data/lib/ogr/geometries/multi_point.rb +14 -0
  141. data/lib/ogr/geometries/multi_polygon.rb +21 -0
  142. data/lib/ogr/geometries/none_geometry.rb +13 -0
  143. data/lib/ogr/geometries/point.rb +65 -0
  144. data/lib/ogr/geometries/point_extensions.rb +32 -0
  145. data/lib/ogr/geometries/polygon.rb +14 -0
  146. data/lib/ogr/geometries/unknown_geometry.rb +10 -0
  147. data/lib/ogr/geometry.rb +270 -242
  148. data/lib/ogr/geometry_extensions.rb +8 -9
  149. data/lib/ogr/geometry_field_definition.rb +99 -0
  150. data/lib/ogr/geometry_field_definition_extensions.rb +19 -0
  151. data/lib/ogr/geometry_types/container.rb +75 -0
  152. data/lib/ogr/geometry_types/curve.rb +25 -28
  153. data/lib/ogr/geometry_types/surface.rb +13 -4
  154. data/lib/ogr/internal_helpers.rb +57 -0
  155. data/lib/ogr/layer.rb +60 -181
  156. data/lib/ogr/layer_mixins/capability_methods.rb +102 -0
  157. data/lib/ogr/layer_mixins/extensions.rb +59 -0
  158. data/lib/ogr/layer_mixins/ogr_feature_methods.rb +127 -0
  159. data/lib/ogr/layer_mixins/ogr_field_methods.rb +143 -0
  160. data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +163 -0
  161. data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +89 -0
  162. data/lib/ogr/layer_mixins/ogr_sql_methods.rb +48 -0
  163. data/lib/ogr/spatial_reference.rb +108 -589
  164. data/lib/ogr/spatial_reference_extensions.rb +29 -3
  165. data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +494 -0
  166. data/lib/ogr/spatial_reference_mixins/exporters.rb +134 -0
  167. data/lib/ogr/spatial_reference_mixins/importers.rb +243 -0
  168. data/lib/ogr/spatial_reference_mixins/morphers.rb +25 -0
  169. data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +122 -0
  170. data/lib/ogr/spatial_reference_mixins/type_checks.rb +62 -0
  171. data/lib/ogr/style_table.rb +53 -5
  172. data/lib/ogr/style_table_extensions.rb +21 -5
  173. data/lib/ogr/style_tool.rb +118 -0
  174. data/lib/ogr.rb +8 -0
  175. data/spec/ffi-gdal_spec.rb +1 -2
  176. data/spec/integration/{color_table_info_spec.rb → gdal/color_table_info_spec.rb} +12 -12
  177. data/spec/integration/{dataset_info_spec.rb → gdal/dataset_info_spec.rb} +2 -6
  178. data/spec/integration/{driver_info_spec.rb → gdal/driver_info_spec.rb} +5 -5
  179. data/spec/integration/{geo_transform_info_spec.rb → gdal/geo_transform_info_spec.rb} +1 -14
  180. data/spec/integration/{raster_attribute_table_info_spec.rb → gdal/raster_attribute_table_info_spec.rb} +1 -2
  181. data/spec/integration/{raster_band_info_spec.rb → gdal/raster_band_info_spec.rb} +30 -42
  182. data/spec/integration/ogr/layer_spec.rb +97 -0
  183. data/spec/spec_helper.rb +94 -5
  184. data/spec/support/integration_help.rb +1 -0
  185. data/spec/support/shared_contexts.rb +26 -0
  186. data/spec/support/shared_examples/{major_object_examples.rb → gdal/major_object_examples.rb} +5 -5
  187. data/spec/support/shared_examples/ogr/a_25D_geometry.rb +7 -0
  188. data/spec/support/shared_examples/ogr/a_container_geometry.rb +47 -0
  189. data/spec/support/shared_examples/ogr/a_geometry.rb +404 -0
  190. data/spec/support/shared_examples/ogr/a_line_string.rb +16 -0
  191. data/spec/support/test_style_table.txt +3 -0
  192. data/spec/unit/ext/error_symbols_spec.rb +41 -53
  193. data/spec/unit/ext/numeric_as_data_type_spec.rb +113 -0
  194. data/spec/unit/ffi/gdal_spec.rb +70 -0
  195. data/spec/unit/gdal/color_entry_spec.rb +5 -0
  196. data/spec/unit/gdal/color_interpretation_spec.rb +5 -0
  197. data/spec/unit/gdal/{color_table_extensions_spec.rb → color_table_mixins/extensions_spec.rb} +3 -3
  198. data/spec/unit/gdal/color_table_spec.rb +14 -16
  199. data/spec/unit/gdal/data_type_spec.rb +10 -17
  200. data/spec/unit/gdal/dataset_spec.rb +4 -7
  201. data/spec/unit/gdal/driver_mixins/extensions_spec.rb +22 -0
  202. data/spec/unit/gdal/driver_spec.rb +49 -0
  203. data/spec/unit/gdal/environment_methods_spec.rb +6 -0
  204. data/spec/unit/gdal/geo_transform_spec.rb +276 -0
  205. data/spec/unit/gdal/grid_spec.rb +5 -0
  206. data/spec/unit/gdal/internal_helpers_spec.rb +112 -0
  207. data/spec/unit/gdal/major_object_spec.rb +6 -0
  208. data/spec/unit/gdal/options_spec.rb +5 -0
  209. data/spec/unit/gdal/raster_attribute_table_spec.rb +5 -0
  210. data/spec/unit/gdal/raster_band_classifier_spec.rb +134 -0
  211. data/spec/unit/gdal/raster_band_spec.rb +5 -0
  212. data/spec/unit/gdal/rpc_info_spec.rb +5 -0
  213. data/spec/unit/gdal/version_info_spec.rb +6 -0
  214. data/spec/unit/gdal/virtual_dataset_spec.rb +32 -0
  215. data/spec/unit/gdal/warp_operation_spec.rb +5 -0
  216. data/spec/unit/ogr/data_source_mixins/capability_methods_spec.rb +30 -0
  217. data/spec/unit/ogr/data_source_spec.rb +209 -0
  218. data/spec/unit/ogr/driver_mixins/capability_methods_spec.rb +18 -0
  219. data/spec/unit/ogr/driver_spec.rb +150 -0
  220. data/spec/unit/ogr/envelope_spec.rb +322 -0
  221. data/spec/unit/ogr/feature_definition_spec.rb +313 -0
  222. data/spec/unit/ogr/feature_spec.rb +379 -0
  223. data/spec/unit/ogr/field_definition_spec.rb +135 -0
  224. data/spec/unit/ogr/field_spec.rb +193 -0
  225. data/spec/unit/ogr/geometries/geometry_collection_spec.rb +186 -0
  226. data/spec/unit/ogr/geometries/line_string_spec.rb +105 -0
  227. data/spec/unit/ogr/{linear_ring_spec.rb → geometries/linear_ring_spec.rb} +10 -31
  228. data/spec/unit/ogr/geometries/multi_line_string_spec.rb +14 -0
  229. data/spec/unit/ogr/geometries/multi_point_spec.rb +14 -0
  230. data/spec/unit/ogr/geometries/multi_polygon_spec.rb +41 -0
  231. data/spec/unit/ogr/geometries/none_geometry_spec.rb +12 -0
  232. data/spec/unit/ogr/{point_spec.rb → geometries/point_spec.rb} +19 -25
  233. data/spec/unit/ogr/geometries/polygon_spec.rb +17 -0
  234. data/spec/unit/ogr/geometries/unknown_geometry_spec.rb +10 -0
  235. data/spec/unit/ogr/geometry_field_definition_spec.rb +87 -0
  236. data/spec/unit/ogr/geometry_spec.rb +542 -0
  237. data/spec/unit/ogr/internal_helpers_spec.rb +57 -0
  238. data/spec/unit/ogr/layer_mixins/capability_methods_spec.rb +88 -0
  239. data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +145 -0
  240. data/spec/unit/ogr/layer_mixins/ogr_field_methods_spec.rb +432 -0
  241. data/spec/unit/ogr/layer_mixins/ogr_layer_method_methods_spec.rb +20 -0
  242. data/spec/unit/ogr/layer_mixins/ogr_query_filter_methods_spec.rb +42 -0
  243. data/spec/unit/ogr/layer_mixins/ogr_sql_methods_spec.rb +12 -0
  244. data/spec/unit/ogr/layer_spec.rb +66 -67
  245. data/spec/unit/ogr/spatial_reference_mixins/coordinate_system_getter_setters_spec.rb +46 -0
  246. data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +139 -0
  247. data/spec/unit/ogr/spatial_reference_mixins/importers_spec.rb +38 -0
  248. data/spec/unit/ogr/spatial_reference_mixins/morphers_spec.rb +36 -0
  249. data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +102 -0
  250. data/spec/unit/ogr/spatial_reference_mixins/type_checks_spec.rb +157 -0
  251. data/spec/unit/ogr/spatial_reference_spec.rb +42 -0
  252. data/spec/unit/ogr/style_table_spec.rb +132 -0
  253. data/spec/unit/ogr/style_tool_spec.rb +157 -0
  254. data/spec/unit/version_info_spec.rb +1 -1
  255. metadata +285 -75
  256. data/lib/ffi/cpl/conv_h.rb +0 -143
  257. data/lib/ffi/cpl/error_h.rb +0 -63
  258. data/lib/ffi/cpl/minixml_h.rb +0 -14
  259. data/lib/ffi/cpl/string_h.rb +0 -81
  260. data/lib/ffi/cpl/vsi_h.rb +0 -112
  261. data/lib/ffi/gdal/alg_h.rb +0 -127
  262. data/lib/ffi/gdal/grid_h.rb +0 -51
  263. data/lib/ffi/gdal/warper_h.rb +0 -48
  264. data/lib/ffi/ogr/api_h.rb +0 -553
  265. data/lib/ffi/ogr/core_h.rb +0 -148
  266. data/lib/ffi/ogr/featurestyle_h.rb +0 -22
  267. data/lib/ffi/ogr/geocoding_h.rb +0 -21
  268. data/lib/ffi/ogr/ogr_field.rb +0 -50
  269. data/lib/ffi/ogr/ogr_style_param.rb +0 -12
  270. data/lib/ffi/ogr/srs_api_h.rb +0 -325
  271. data/lib/gdal/color_entry_extensions.rb +0 -30
  272. data/lib/gdal/color_table_extensions.rb +0 -47
  273. data/lib/gdal/dataset_extensions.rb +0 -496
  274. data/lib/gdal/driver_extensions.rb +0 -56
  275. data/lib/gdal/geo_transform_extensions.rb +0 -90
  276. data/lib/gdal/raster_attribute_table_extensions.rb +0 -40
  277. data/lib/gdal/raster_band_extensions.rb +0 -198
  278. data/lib/ogr/geometry_types/collection.rb +0 -45
  279. data/lib/ogr/layer_extensions.rb +0 -55
  280. data/lib/ogr/line_string.rb +0 -7
  281. data/lib/ogr/linear_ring.rb +0 -6
  282. data/lib/ogr/multi_line_string.rb +0 -9
  283. data/lib/ogr/multi_point.rb +0 -7
  284. data/lib/ogr/multi_polygon.rb +0 -14
  285. data/lib/ogr/point.rb +0 -89
  286. data/lib/ogr/polygon.rb +0 -9
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'fakefs/safe'
3
+
4
+ RSpec.describe FFI::GDAL do
5
+ describe '.find_lib' do
6
+ context 'ENV["GDAL_LIBRARY_PATH"] is set' do
7
+ before do
8
+ allow(ENV).to receive(:[]).with('GDAL_LIBRARY_PATH').and_return '/pants'
9
+ end
10
+
11
+ it 'returns GDAL_LIBRARY_PATH + libgdal file name' do
12
+ expect(described_class.find_lib('stuff')).to match %r{\A/pants/stuff\.+}
13
+ end
14
+ end
15
+
16
+ context 'ENV["GDAL_LIBRARY_PATH"] is not set' do
17
+ before do
18
+ allow(described_class).to receive(:search_paths).and_return %w[/pants]
19
+ FakeFS.activate!
20
+ FileUtils.mkdir 'pants'
21
+ FileUtils.touch("/pants/stuff.#{FFI::Platform::LIBSUFFIX}")
22
+ end
23
+
24
+ after { FakeFS.deactivate! }
25
+
26
+ it 'returns the search path + libgdal file name' do
27
+ expect(described_class.find_lib('stuff')).to match %r{\A/pants/stuff\.+}
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '.search_paths' do
33
+ context 'ENV["GDAL_LIBRARY_PATH"] is set' do
34
+ before do
35
+ allow(ENV).to receive(:[]).with('GDAL_LIBRARY_PATH').and_return '/pants'
36
+ end
37
+
38
+ it 'returns GDAL_LIBRARY_PATH' do
39
+ expect(described_class.search_paths).to match /\A\/pants\z/
40
+ end
41
+ end
42
+
43
+ context 'ENV["GDAL_LIBRARY_PATH"] is not set' do
44
+ it 'returns a bunch of directories' do
45
+ expect(described_class.search_paths.size).to be > 0
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '._files_with_constants' do
51
+ it 'returns a non-empty Array' do
52
+ expect(described_class._files_with_constants).to be_an Array
53
+ expect(described_class._files_with_constants).to_not be_empty
54
+ end
55
+ end
56
+
57
+ describe '_file_with_constants' do
58
+ context 'valid file' do
59
+ it 'returns the path to that file' do
60
+ expect(described_class._file_with_constants('gdal.h')).to match '.+gdal\.h\z'
61
+ end
62
+ end
63
+
64
+ context 'invalid file' do
65
+ it 'returns nil' do
66
+ expect(described_class._file_with_constants('derp')).to be_nil
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+ require 'gdal/color_entry'
3
+
4
+ RSpec.describe GDAL::ColorEntry do
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+ require 'gdal/color_interpretation'
3
+
4
+ RSpec.describe GDAL::ColorInterpretation do
5
+ end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
+ require 'gdal/color_table'
2
3
 
3
-
4
- describe GDAL::ColorTable do
4
+ RSpec.describe GDAL::ColorTable do
5
5
  subject do
6
- described_class.create(:GPI_RGB)
6
+ described_class.new(:GPI_RGB)
7
7
  end
8
8
 
9
9
  describe '#color_entries_for' do
@@ -1,29 +1,27 @@
1
1
  require 'spec_helper'
2
+ require 'gdal/color_table'
2
3
 
3
-
4
- describe GDAL::ColorTable do
5
- describe '.create' do
4
+ RSpec.describe GDAL::ColorTable do
5
+ describe '#initialize' do
6
6
  context 'with a valid PaletteInterpretation' do
7
7
  it 'creates a new ColorTable' do
8
- expect(described_class.create(:GPI_RGB)).to be_a(described_class)
8
+ expect(described_class.new(:GPI_RGB)).to be_a(described_class)
9
9
  end
10
10
  end
11
11
 
12
12
  context 'with an invalid PaletteInterpretation' do
13
- it 'raises an ArgumentError' do
14
- expect {
15
- described_class.create(:MEOW)
16
- }.to raise_exception(ArgumentError)
13
+ it 'raises an GDAL::InvalidColorTable' do
14
+ expect do
15
+ described_class.new(:MEOW)
16
+ end.to raise_exception(GDAL::InvalidColorTable)
17
17
  end
18
18
  end
19
- end
20
19
 
21
- describe '#initialize' do
22
20
  context ':GPI_RGB' do
23
21
  it 'extends the new object with the ColorTableTypes::RGB module' do
24
22
  expect_any_instance_of(described_class).to receive(:extend).
25
23
  with(GDAL::ColorTableTypes::RGB)
26
- described_class.create(:GPI_RGB)
24
+ described_class.new(:GPI_RGB)
27
25
  end
28
26
  end
29
27
 
@@ -31,7 +29,7 @@ describe GDAL::ColorTable do
31
29
  it 'extends the new object with the ColorTableTypes::Gray module' do
32
30
  expect_any_instance_of(described_class).to receive(:extend).
33
31
  with(GDAL::ColorTableTypes::Gray)
34
- described_class.create(:GPI_Gray)
32
+ described_class.new(:GPI_Gray)
35
33
  end
36
34
  end
37
35
 
@@ -39,7 +37,7 @@ describe GDAL::ColorTable do
39
37
  it 'extends the new object with the ColorTableTypes::CMYK module' do
40
38
  expect_any_instance_of(described_class).to receive(:extend).
41
39
  with(GDAL::ColorTableTypes::CMYK)
42
- described_class.create(:GPI_CMYK)
40
+ described_class.new(:GPI_CMYK)
43
41
  end
44
42
  end
45
43
 
@@ -47,13 +45,13 @@ describe GDAL::ColorTable do
47
45
  it 'extends the new object with the ColorTableTypes::HLS module' do
48
46
  expect_any_instance_of(described_class).to receive(:extend).
49
47
  with(GDAL::ColorTableTypes::HLS)
50
- described_class.create(:GPI_HLS)
48
+ described_class.new(:GPI_HLS)
51
49
  end
52
50
  end
53
51
  end
54
52
 
55
53
  subject do
56
- described_class.create(:GPI_RGB)
54
+ described_class.new(:GPI_RGB)
57
55
  end
58
56
 
59
57
  describe '#palette_interpretation' do
@@ -136,7 +134,7 @@ describe GDAL::ColorTable do
136
134
  context 'color entries that exist' do
137
135
  it 'returns nil' do
138
136
  entry0 = subject.add_color_entry(0, 0, 0, 0, 0)
139
- entry1 = subject.add_color_entry(1, 10, 10, 10, 10)
137
+ _entry1 = subject.add_color_entry(1, 10, 10, 10, 10)
140
138
  entry2 = subject.add_color_entry(2, 100, 100, 100, 100)
141
139
 
142
140
  expect(subject.create_color_ramp!(0, entry0, 2, entry2)).to be_nil
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
+ require 'gdal/data_type'
2
3
 
3
- describe GDAL::DataType do
4
+ RSpec.describe GDAL::DataType do
4
5
  describe '.size' do
5
6
  context 'with valid data type' do
6
7
  it 'returns the size' do
@@ -10,9 +11,9 @@ describe GDAL::DataType do
10
11
 
11
12
  context 'with invalid data type' do
12
13
  it 'raises an ArgumentError' do
13
- expect {
14
+ expect do
14
15
  described_class.size(:Bob)
15
- }.to raise_exception(ArgumentError)
16
+ end.to raise_exception(ArgumentError)
16
17
  end
17
18
  end
18
19
  end
@@ -32,9 +33,9 @@ describe GDAL::DataType do
32
33
 
33
34
  context 'with invalid data type' do
34
35
  it 'raises an ArgumentError' do
35
- expect {
36
+ expect do
36
37
  described_class.complex?(:Bob)
37
- }.to raise_exception(ArgumentError)
38
+ end.to raise_exception(ArgumentError)
38
39
  end
39
40
  end
40
41
  end
@@ -48,11 +49,9 @@ describe GDAL::DataType do
48
49
 
49
50
  context 'with invalid data type' do
50
51
  it 'raises an ArgumentError' do
51
- skip 'Figure out why this causes a segfault'
52
-
53
- expect {
52
+ expect do
54
53
  described_class.name(:Bob)
55
- }.to raise_exception(ArgumentError)
54
+ end.to raise_exception(ArgumentError)
56
55
  end
57
56
  end
58
57
  end
@@ -60,19 +59,13 @@ describe GDAL::DataType do
60
59
  describe '.by_name' do
61
60
  context 'with valid data type name' do
62
61
  it 'returns the data type' do
63
- skip 'Figure out why this causes a segfault'
64
-
65
62
  expect(described_class.by_name('Byte')).to eq :GDT_Byte
66
63
  end
67
64
  end
68
65
 
69
66
  context 'with invalid data type name' do
70
- it 'raises an ArgumentError' do
71
- skip 'Figure out why this causes a segfault'
72
-
73
- expect {
74
- described_class.by_name('Bob')
75
- }.to raise_exception(ArgumentError)
67
+ it 'returns :GDT_Unknown' do
68
+ expect(described_class.by_name('Bob')).to eq :GDT_Unknown
76
69
  end
77
70
  end
78
71
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
+ require 'gdal/dataset'
2
3
 
3
- describe GDAL::Dataset do
4
+ RSpec.describe GDAL::Dataset do
4
5
  let(:file_path) do
5
6
  File.expand_path('../../support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif', __dir__)
6
7
  end
@@ -59,12 +60,8 @@ describe GDAL::Dataset do
59
60
  end
60
61
 
61
62
  describe '#add_band' do
62
- it 'raises a GDAL::CPLErrFailure' do
63
- skip 'Figure out why this causes a segfault'
64
-
65
- expect {
66
- subject.add_band(:GDT_Byte)
67
- }.to raise_exception(GDAL::CPLErrFailure)
63
+ it 'raises a GDAL::UnsupportedOperation' do
64
+ expect { subject.add_band(:GDT_Byte) }.to raise_exception(GDAL::UnsupportedOperation)
68
65
  end
69
66
  end
70
67
 
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'gdal/driver'
3
+
4
+ RSpec.describe GDAL::Driver do
5
+ describe '.short_names' do
6
+ subject { described_class.short_names }
7
+
8
+ it 'is an Array of Strings' do
9
+ expect(subject).to be_an Array
10
+ expect(subject.first).to be_a String
11
+ end
12
+ end
13
+
14
+ describe '.long_names' do
15
+ subject { described_class.long_names }
16
+
17
+ it 'is an Array of Strings' do
18
+ expect(subject).to be_an Array
19
+ expect(subject.first).to be_a String
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'gdal/driver'
3
+
4
+ RSpec.describe GDAL::Driver do
5
+ describe '.count' do
6
+ subject { described_class.count }
7
+ it { is_expected.to be > 0 }
8
+ end
9
+
10
+ describe '.by_name' do
11
+ context 'not a driver' do
12
+ it 'raises a GDAL::InvalidDriverName' do
13
+ expect { described_class.by_name('blargh') }.
14
+ to raise_exception GDAL::InvalidDriverName
15
+ end
16
+ end
17
+
18
+ context 'valid driver name' do
19
+ subject { described_class.by_name('MEM') }
20
+ it { is_expected.to be_an_instance_of GDAL::Driver }
21
+ end
22
+ end
23
+
24
+ describe '.at_index' do
25
+ context 'invalid index' do
26
+ it 'raises a GDAL::InvalidDriverIndex' do
27
+ expect { described_class.at_index 123_456 }.
28
+ to raise_exception GDAL::InvalidDriverIndex
29
+ end
30
+ end
31
+
32
+ context 'valid index' do
33
+ subject { described_class.at_index(0) }
34
+ it { is_expected.to be_an_instance_of GDAL::Driver }
35
+ end
36
+ end
37
+
38
+ describe '.identify_driver' do
39
+ context 'file is not supported' do
40
+ subject { described_class.identify_driver(__FILE__) }
41
+ it { is_expected.to be_nil }
42
+ end
43
+
44
+ context 'file is supported' do
45
+ subject { described_class.identify_driver('spec/support/worldfiles/SR_50M/SR_50M.tif') }
46
+ it { is_expected.to be_an_instance_of GDAL::Driver }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+ require 'gdal/environment_methods'
3
+
4
+ RSpec.describe GDAL::EnvironmentMethods do
5
+ subject { Object.new.extend(described_class) }
6
+ end
@@ -0,0 +1,276 @@
1
+ require 'spec_helper'
2
+ require 'gdal/geo_transform'
3
+
4
+ RSpec.describe GDAL::GeoTransform do
5
+ let(:world_file_path) do
6
+ 'spec/support/worldfiles/SR_50M/SR_50M.tfw'
7
+ end
8
+
9
+ describe '.from_world_file' do
10
+ context 'a valid file' do
11
+ it 'reads in the file' do
12
+ result = described_class.from_world_file(world_file_path)
13
+ expect(result).to be_a GDAL::GeoTransform
14
+ end
15
+ end
16
+
17
+ context 'an invalid file' do
18
+ it 'reads in the file' do
19
+ expect do
20
+ described_class.from_world_file('things')
21
+ end.to raise_exception GDAL::OpenFailure
22
+ end
23
+ end
24
+ end
25
+
26
+ context 'an imported World file' do
27
+ subject(:world) do
28
+ described_class.from_world_file(world_file_path)
29
+ end
30
+
31
+ describe '#x_origin' do
32
+ subject { world.x_origin }
33
+ it { is_expected.to eq(-179.99999999999997) }
34
+ end
35
+
36
+ describe '#pixel_width' do
37
+ subject { world.pixel_width }
38
+ it { is_expected.to eq 0.03333333333333 }
39
+ end
40
+
41
+ describe '#x_rotation' do
42
+ subject { world.x_rotation }
43
+ it { is_expected.to eq 0.0 }
44
+ end
45
+
46
+ describe '#y_origin' do
47
+ subject { world.y_origin }
48
+ it { is_expected.to eq 90.0 }
49
+ end
50
+
51
+ describe '#pixel_height' do
52
+ subject { world.pixel_height }
53
+ it { is_expected.to eq(-0.03333333333333) }
54
+ end
55
+
56
+ describe '#y_rotation' do
57
+ subject { world.y_rotation }
58
+ it { is_expected.to eq 0.0 }
59
+ end
60
+ end
61
+
62
+ context 'a new GeoTransform' do
63
+ describe '#initialize' do
64
+ it 'sets all attributes to 0.0' do
65
+ expect(subject.x_origin).to eq 0.0
66
+ expect(subject.pixel_width).to eq 0.0
67
+ expect(subject.x_rotation).to eq 0.0
68
+ expect(subject.y_origin).to eq 0.0
69
+ expect(subject.pixel_height).to eq 0.0
70
+ expect(subject.y_rotation).to eq 0.0
71
+ end
72
+ end
73
+
74
+ describe '#x_origin= + #x_origin' do
75
+ it 'sets the value' do
76
+ subject.x_origin = 123
77
+ expect(subject.x_origin).to eq 123.0
78
+ end
79
+ end
80
+
81
+ describe '#pixel_width= + #pixel_width' do
82
+ it 'sets the value' do
83
+ subject.pixel_width = 123
84
+ expect(subject.pixel_width).to eq 123.0
85
+ end
86
+ end
87
+
88
+ describe '#x_rotation= + #x_rotation' do
89
+ it 'sets the value' do
90
+ subject.x_rotation = 123
91
+ expect(subject.x_rotation).to eq 123.0
92
+ end
93
+ end
94
+
95
+ describe '#y_origin= + #y_origin' do
96
+ it 'sets the value' do
97
+ subject.y_origin = 123
98
+ expect(subject.y_origin).to eq 123.0
99
+ end
100
+ end
101
+
102
+ describe '#pixel_width= + #pixel_height' do
103
+ it 'sets the value' do
104
+ subject.pixel_height = 123
105
+ expect(subject.pixel_height).to eq 123.0
106
+ end
107
+ end
108
+
109
+ describe '#y_rotation= + #y_rotation' do
110
+ it 'sets the value' do
111
+ subject.y_rotation = 123
112
+ expect(subject.y_rotation).to eq 123.0
113
+ end
114
+ end
115
+
116
+ describe '#apply_geo_transform' do
117
+ subject do
118
+ gt = described_class.new
119
+ gt.x_origin = 1000
120
+ gt.y_origin = -2000
121
+ gt.pixel_height = 0.1
122
+ gt.pixel_width = 0.1
123
+ gt
124
+ end
125
+
126
+ it "returns the GeoTransform's origins for (0, 0)" do
127
+ projected = subject.apply_geo_transform(0, 0)
128
+ expect(projected[:x_geo]).to eq 1000
129
+ expect(projected[:y_geo]).to eq(-2000)
130
+ end
131
+
132
+ it 'returns calculated points' do
133
+ projected = subject.apply_geo_transform(100, 100)
134
+ expect(projected[:x_geo]).to eq 1010.0
135
+ expect(projected[:y_geo]).to eq(-1990.0)
136
+ end
137
+ end
138
+
139
+ describe '#compose' do
140
+ context 'given parameter is not a GeoTransform' do
141
+ it 'raises a GDAL::NullObject' do
142
+ expect { subject.compose('not a pointer') }.to raise_exception GDAL::NullObject
143
+ end
144
+ end
145
+
146
+ context 'given parameter is a GeoTransform' do
147
+ let(:other_geo_transform) do
148
+ gt = described_class.new
149
+ gt.x_origin = 1000
150
+ gt.y_origin = 1000
151
+ gt.pixel_width = 0.5
152
+ gt.pixel_height = 0.25
153
+ gt.x_rotation = 1.0
154
+ gt.y_rotation = -1.0
155
+ gt
156
+ end
157
+
158
+ subject do
159
+ gt = described_class.new
160
+ gt.x_origin = 500
161
+ gt.y_origin = 500
162
+ gt.pixel_width = 0.25
163
+ gt.pixel_height = 0.5
164
+ gt.x_rotation = -1.0
165
+ gt.y_rotation = 1.0
166
+
167
+ gt.compose(other_geo_transform)
168
+ end
169
+
170
+ it 'is a new GeoTransform' do
171
+ expect(subject).to be_a GDAL::GeoTransform
172
+ end
173
+
174
+ it 'has a combined x_origin' do
175
+ expect(subject.x_origin).to eq 1750.0
176
+ end
177
+
178
+ it 'has a combined pixel_width' do
179
+ expect(subject.pixel_width).to eq 1.125
180
+ end
181
+
182
+ it 'has a combined x_rotation' do
183
+ expect(subject.x_rotation).to eq 0.0
184
+ end
185
+
186
+ it 'has a combined y_origin' do
187
+ expect(subject.y_origin).to eq 625.0
188
+ end
189
+
190
+ it 'has a combined pixel_height' do
191
+ expect(subject.pixel_height).to eq 1.125
192
+ end
193
+
194
+ it 'has a combined y_rotation' do
195
+ expect(subject.y_rotation).to eq 0.0
196
+ end
197
+ end
198
+ end
199
+
200
+ describe '#invert' do
201
+ subject do
202
+ gt = described_class.new
203
+ gt.x_origin = 1000
204
+ gt.y_origin = 2000
205
+ gt.pixel_width = 0.5
206
+ gt.pixel_height = 0.5
207
+ gt.x_rotation = 1.0
208
+ gt.y_rotation = -1.0
209
+
210
+ gt.invert
211
+ end
212
+
213
+ it 'returns a new GeoTransform' do
214
+ expect(subject).to be_a GDAL::GeoTransform
215
+ end
216
+
217
+ it 'returns an inverted x_origin' do
218
+ expect(subject.x_origin).to eq 1200
219
+ end
220
+
221
+ it 'returns an inverted pixel_width' do
222
+ expect(subject.pixel_width).to eq 0.4
223
+ end
224
+
225
+ it 'returns an inverted x_rotation' do
226
+ expect(subject.x_rotation).to eq(-0.8)
227
+ end
228
+
229
+ it 'returns an inverted y_origin' do
230
+ expect(subject.y_origin).to eq (-1600.0)
231
+ end
232
+
233
+ it 'returns an inverted pixel_height' do
234
+ expect(subject.pixel_height).to eq 0.4
235
+ end
236
+
237
+ it 'returns an inverted y_rotation' do
238
+ expect(subject.y_rotation).to eq 0.8
239
+ end
240
+ end
241
+
242
+ describe '#world_to_pixel' do
243
+ subject do
244
+ gt = described_class.new
245
+ gt.x_origin = 1000
246
+ gt.y_origin = -2000
247
+ gt.pixel_height = 0.1
248
+ gt.pixel_width = 0.1
249
+ gt
250
+ end
251
+
252
+ it 'converts (0, 0)' do
253
+ result = subject.world_to_pixel(0, 0)
254
+ expect(result).to eq pixel: -10_000, line: -20_000
255
+ end
256
+
257
+ it 'converts (100, -100)' do
258
+ result = subject.world_to_pixel(100, -100)
259
+ expect(result).to eq pixel: -9000, line: -19_000
260
+ end
261
+ end
262
+
263
+ describe '#as_json' do
264
+ it 'returns the attributes as a Hash' do
265
+ expect(subject.as_json).to eq(
266
+ x_origin: 0.0,
267
+ x_rotation: 0.0,
268
+ pixel_width: 0.0,
269
+ y_origin: 0.0,
270
+ y_rotation: 0.0,
271
+ pixel_height: 0.0
272
+ )
273
+ end
274
+ end
275
+ end
276
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+ require 'gdal/grid'
3
+
4
+ RSpec.describe GDAL::Grid do
5
+ end