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
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ require 'gdal/driver'
3
+ require 'gdal/raster_band'
4
+
5
+ RSpec.describe 'GDAL::RasterBandMixins::Extensions' do
6
+ let(:driver) { GDAL::Driver.by_name('MEM') }
7
+ let(:dataset_byte) { driver.create_dataset('test', 15, 25, data_type: :GDT_Byte) }
8
+ subject(:raster_band) { dataset_byte.raster_band(1) }
9
+
10
+ describe '#to_a' do
11
+ subject { raster_band.to_a }
12
+ it { is_expected.to eq(Array.new(25, Array.new(15, 0))) }
13
+ end
14
+
15
+ describe '#to_na' do
16
+ context 'no conversion' do
17
+ subject { raster_band.to_na }
18
+ it { is_expected.to eq(NArray.byte(15, 25)) }
19
+ end
20
+
21
+ context 'convert to Int16' do
22
+ subject { raster_band.to_na(:GDT_Int16) }
23
+ it { is_expected.to eq(NArray.sint(15, 25)) }
24
+ end
25
+
26
+ context 'convert to UInt16' do
27
+ subject { raster_band.to_na(:GDT_UInt16) }
28
+ it { is_expected.to eq(NArray.int(15, 25)) }
29
+ end
30
+
31
+ context 'convert to Int32' do
32
+ subject { raster_band.to_na(:GDT_Int32) }
33
+ it { is_expected.to eq(NArray.int(15, 25)) }
34
+ end
35
+
36
+ context 'convert to UInt32' do
37
+ subject { raster_band.to_na(:GDT_UInt32) }
38
+ it { is_expected.to eq(NArray.int(15, 25)) }
39
+ end
40
+
41
+ context 'convert to Float32' do
42
+ subject { raster_band.to_na(:GDT_Float32) }
43
+ it { is_expected.to eq(NArray.sfloat(15, 25)) }
44
+ end
45
+
46
+ context 'convert to Float64' do
47
+ subject { raster_band.to_na(:GDT_Float64) }
48
+ it { is_expected.to eq(NArray.float(15, 25)) }
49
+ end
50
+
51
+ context 'convert to CInt16' do
52
+ subject { raster_band.to_na(:GDT_CInt16) }
53
+ it { is_expected.to eq(NArray.scomplex(15, 25)) }
54
+ end
55
+
56
+ context 'convert to CInt32' do
57
+ subject { raster_band.to_na(:GDT_CInt32) }
58
+ it { is_expected.to eq(NArray.scomplex(15, 25)) }
59
+ end
60
+
61
+ context 'convert to CFloat32' do
62
+ subject { raster_band.to_na(:GDT_CFloat32) }
63
+ it { is_expected.to eq(NArray.scomplex(15, 25)) }
64
+ end
65
+
66
+ context 'convert to CFloat64' do
67
+ subject { raster_band.to_na(:GDT_CFloat64) }
68
+ it { is_expected.to eq(NArray.complex(15, 25)) }
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+ require 'gdal/driver'
3
+ require 'gdal/raster_band'
4
+
5
+ RSpec.describe 'GDAL::RasterBandMixins::IOExtensions' do
6
+ let(:driver) { GDAL::Driver.by_name('MEM') }
7
+ let(:dataset_byte) { driver.create_dataset('test', 15, 25, data_type: :GDT_Byte) }
8
+ let(:dataset_int16) { driver.create_dataset('test', 15, 25, data_type: :GDT_Int16) }
9
+ let(:dataset_uint16) { driver.create_dataset('test', 15, 25, data_type: :GDT_UInt16) }
10
+ let(:dataset_int32) { driver.create_dataset('test', 15, 25, data_type: :GDT_Int32) }
11
+ let(:dataset_uint32) { driver.create_dataset('test', 15, 25, data_type: :GDT_UInt32) }
12
+ let(:dataset_float32) { driver.create_dataset('test', 15, 25, data_type: :GDT_Float32) }
13
+ let(:dataset_float64) { driver.create_dataset('test', 15, 25, data_type: :GDT_Float64) }
14
+
15
+ subject(:raster_band) { dataset_byte.raster_band(1) }
16
+
17
+ describe '#write_xy_narray' do
18
+ let(:dataset) { driver.create_dataset('test dataset', 64, 4) }
19
+ let(:raster_band) { dataset.raster_band 1 }
20
+
21
+ it 'writes pixels from the NArray' do
22
+ row0 = Array.new(64) { 1 }
23
+ row1 = Array.new(64) { 2 }
24
+ row2 = Array.new(64) { 3 }
25
+ row3 = Array.new(64) { 4 }
26
+ narray = NArray[row0, row1, row2, row3]
27
+
28
+ raster_band.write_xy_narray(narray)
29
+
30
+ pixels = raster_band.to_na
31
+ expect(pixels[true, 0]).to eq(NArray.to_na(row0))
32
+ expect(pixels[true, 1]).to eq(NArray.to_na(row1))
33
+ expect(pixels[true, 2]).to eq(NArray.to_na(row2))
34
+ expect(pixels[true, 3]).to eq(NArray.to_na(row3))
35
+ end
36
+ end
37
+
38
+ describe '#set_pixel_value/#pixel_value' do
39
+ context 'valid values, GDT_Byte' do
40
+ it 'sets and gets the value successfully' do
41
+ subject.set_pixel_value(0, 0, 123)
42
+ expect(subject.pixel_value(0, 0)).to eq(123)
43
+ end
44
+ end
45
+
46
+ context 'valid values, GDT_Int16' do
47
+ subject { dataset_int16.raster_band(1) }
48
+
49
+ it 'sets and gets the value successfully' do
50
+ subject.set_pixel_value(0, 0, -12_345)
51
+ expect(subject.pixel_value(0, 0)).to eq(-12_345)
52
+ end
53
+ end
54
+
55
+ context 'valid values, GDT_UInt16' do
56
+ subject { dataset_uint16.raster_band(1) }
57
+
58
+ it 'sets and gets the value successfully' do
59
+ subject.set_pixel_value(0, 0, 32_123)
60
+ expect(subject.pixel_value(0, 0)).to eq(32_123)
61
+ end
62
+ end
63
+
64
+ context 'valid values, GDT_Int32' do
65
+ subject { dataset_int32.raster_band(1) }
66
+
67
+ it 'sets and gets the value successfully' do
68
+ subject.set_pixel_value(0, 0, -123_456_789)
69
+ expect(subject.pixel_value(0, 0)).to eq(-123_456_789)
70
+ end
71
+ end
72
+
73
+ context 'valid values, GDT_UInt32' do
74
+ subject { dataset_uint32.raster_band(1) }
75
+
76
+ it 'sets and gets the value successfully' do
77
+ subject.set_pixel_value(0, 0, 4_123_456_789)
78
+ expect(subject.pixel_value(0, 0)).to eq(4_123_456_789)
79
+ end
80
+ end
81
+
82
+ context 'valid values, GDT_Float32' do
83
+ subject { dataset_float32.raster_band(1) }
84
+
85
+ # For some reason, precision of float32 values isn't there past a couple
86
+ # decimals when reading back.
87
+ it 'sets and gets the value successfully' do
88
+ subject.set_pixel_value(0, 0, -123.456)
89
+ expect(subject.pixel_value(0, 0)).to be_within(0.001).of(-123.456)
90
+ end
91
+ end
92
+
93
+ context 'valid values, GDT_Float64' do
94
+ subject { dataset_float64.raster_band(1) }
95
+
96
+ it 'sets and gets the value successfully' do
97
+ subject.set_pixel_value(0, 0, -123_456_789_101.456)
98
+ expect(subject.pixel_value(0, 0)).to eq(-123_456_789_101.456)
99
+ end
100
+ end
101
+ end
102
+
103
+ describe '#block_count' do
104
+ it 'returns a Hash of relevant values' do
105
+ expect(subject.block_count).to eq(
106
+ x: 1,
107
+ x_remainder: 0,
108
+ y: 25,
109
+ y_remainder: 0
110
+ )
111
+ end
112
+ end
113
+
114
+ describe '#block_buffer_size' do
115
+ subject { raster_band.block_buffer_size }
116
+ it { is_expected.to eq(15) }
117
+ end
118
+
119
+ describe '#read_lines_by_block' do
120
+ context 'block is given' do
121
+ it 'yields each row of pixels' do
122
+ expect { |b| subject.read_lines_by_block(&b) }.
123
+ to yield_successive_args(*Array.new(25, Array.new(15, 0)))
124
+ end
125
+ end
126
+
127
+ context 'no block given' do
128
+ it 'returns an Enumerator' do
129
+ expect(subject.read_lines_by_block).to be_a(Enumerator)
130
+ end
131
+ end
132
+ end
133
+ end
@@ -2,4 +2,5 @@ require 'spec_helper'
2
2
  require 'gdal/raster_band'
3
3
 
4
4
  RSpec.describe GDAL::RasterBand do
5
+ pending 'Add some tests!'
5
6
  end
@@ -2,4 +2,5 @@ require 'spec_helper'
2
2
  require 'gdal/rpc_info'
3
3
 
4
4
  RSpec.describe GDAL::RPCInfo do
5
+ pending 'Add some tests!'
5
6
  end
@@ -3,4 +3,6 @@ require 'gdal/version_info'
3
3
 
4
4
  RSpec.describe GDAL::VersionInfo do
5
5
  subject { Object.new.extend(described_class) }
6
+
7
+ pending 'Add some tests!'
6
8
  end
@@ -2,4 +2,5 @@ require 'spec_helper'
2
2
  require 'gdal/warp_operation'
3
3
 
4
4
  RSpec.describe GDAL::WarpOperation do
5
+ pending 'Add some tests!'
5
6
  end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+ require 'ogr/coordinate_transformation'
3
+
4
+ RSpec.describe OGR::CoordinateTransformation do
5
+ let(:source_srs) { OGR::SpatialReference.new_from_epsg(3857) }
6
+ let(:dest_srs) { OGR::SpatialReference.new_from_epsg(4326) }
7
+
8
+ # From https://epsg.io/3857
9
+ let(:epsg4326_y_bounds) { [-85.06, 85.06] }
10
+ let(:epsg4326_x_bounds) { [-180.0, 180.0] }
11
+ let(:epsg3857_y_bounds) { [-20_048_966.10, 20_048_966.10] }
12
+ let(:epsg3857_x_bounds) { [-20_026_376.39, 20_026_376.39] }
13
+
14
+ subject { described_class.new(source_srs, dest_srs) }
15
+
16
+ describe '.proj4_normalize' do
17
+ context 'OCTProj4Normalize not supported' do
18
+ it 'raises a OGR::UnsupportedOperation' do
19
+ expect { described_class.proj4_normalize('asdf') }.to raise_exception(OGR::UnsupportedOperation)
20
+ end
21
+ end
22
+ end
23
+
24
+ describe '#initialize' do
25
+ context 'source_srs is not an OGR::SpatialReference' do
26
+ it 'raises an OGR::Failure' do
27
+ expect { described_class.new(123, dest_srs) }.to raise_exception(OGR::Failure)
28
+ end
29
+ end
30
+
31
+ context 'dest_srs is not an OGR::SpatialReference' do
32
+ it 'raises an OGR::Failure' do
33
+ expect { described_class.new(source_srs, 123) }.to raise_exception(OGR::Failure)
34
+ end
35
+ end
36
+
37
+ context 'source_srs and dest_srs are valid OGR::SpatialReference objects' do
38
+ it 'creates a new object with @c_pointer set' do
39
+ instance = described_class.new(source_srs, dest_srs)
40
+ expect(instance).to be_a described_class
41
+ expect(instance.c_pointer).to be_a FFI::Pointer
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '#destroy!' do
47
+ it 'sets @c_pointer to nil' do
48
+ subject.destroy!
49
+ expect(subject.c_pointer).to be_nil
50
+ end
51
+ end
52
+
53
+ describe '#transform' do
54
+ context 'no z_vertices, valid x and y vertices' do
55
+ it 'transforms the points' do
56
+ result = subject.transform(epsg3857_x_bounds, epsg3857_y_bounds)
57
+
58
+ transformed_x_points = result.first
59
+ transformed_y_points = result.last
60
+
61
+ expect(transformed_x_points.first).to be_within(0.11).of(epsg4326_x_bounds.first)
62
+ expect(transformed_x_points.last).to be_within(0.11).of(epsg4326_x_bounds.last)
63
+ expect(transformed_y_points.first).to be_within(0.001).of(epsg4326_y_bounds.first)
64
+ expect(transformed_y_points.last).to be_within(0.001).of(epsg4326_y_bounds.last)
65
+ end
66
+ end
67
+
68
+ context 'valid x, y, and z vertices' do
69
+ it 'transforms the points' do
70
+ result = subject.transform(epsg3857_x_bounds, epsg3857_y_bounds, [10_000, -299])
71
+
72
+ transformed_x_points = result.first
73
+ transformed_y_points = result[1]
74
+ transformed_z_points = result.last
75
+
76
+ expect(transformed_x_points.first).to be_within(0.11).of(epsg4326_x_bounds.first)
77
+ expect(transformed_x_points.last).to be_within(0.11).of(epsg4326_x_bounds.last)
78
+ expect(transformed_y_points.first).to be_within(0.001).of(epsg4326_y_bounds.first)
79
+ expect(transformed_y_points.last).to be_within(0.001).of(epsg4326_y_bounds.last)
80
+ expect(transformed_z_points.first).to eq(10_000)
81
+ expect(transformed_z_points.last).to eq(-299)
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#transform_ex' do
87
+ context 'no z_vertices, valid x and y vertices' do
88
+ it 'transforms the points' do
89
+ result = subject.transform_ex(epsg3857_x_bounds, epsg3857_y_bounds)
90
+
91
+ transformed_x_points = result[:points].first
92
+ transformed_y_points = result[:points].last
93
+
94
+ expect(transformed_x_points.first).to be_within(0.11).of(epsg4326_x_bounds.first)
95
+ expect(transformed_x_points.last).to be_within(0.11).of(epsg4326_x_bounds.last)
96
+ expect(transformed_y_points.first).to be_within(0.001).of(epsg4326_y_bounds.first)
97
+ expect(transformed_y_points.last).to be_within(0.001).of(epsg4326_y_bounds.last)
98
+ expect(result[:successes]).to eq([true, false])
99
+ end
100
+ end
101
+ end
102
+ end
@@ -11,6 +11,18 @@ RSpec.describe OGR::DataSource do
11
11
  end.to raise_exception OGR::OpenFailure
12
12
  end
13
13
  end
14
+
15
+ context 'block given' do
16
+ let(:data_source) { instance_double 'OGR::DataSource' }
17
+
18
+ it 'yields then closes the opened DataSource' do
19
+ allow(described_class).to receive(:new).and_return data_source
20
+
21
+ expect(data_source).to receive(:close)
22
+ expect { |b| described_class.open('blarg', 'r', &b) }.
23
+ to yield_with_args(data_source)
24
+ end
25
+ end
14
26
  end
15
27
 
16
28
  let(:driver) { OGR::Driver.by_name 'Memory' }
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+ require 'ogr'
3
+
4
+ RSpec.describe OGR::Feature do
5
+ let(:integer_field_def) { OGR::FieldDefinition.new('test integer field', :OFTInteger) }
6
+
7
+ let(:feature_definition) do
8
+ fd = OGR::FeatureDefinition.new('test FD')
9
+ fd.add_field_definition(integer_field_def) # 0
10
+
11
+ gfd = fd.geometry_field_definition(0)
12
+ gfd.type = :wkbPoint
13
+ gfd.name = 'test point'
14
+
15
+ fd
16
+ end
17
+
18
+ let(:geometry) { OGR::Point.create_from_wkt('POINT (0 1)') }
19
+
20
+ subject(:feature) do
21
+ f = described_class.new(feature_definition)
22
+ f.set_geometry_field(0, geometry)
23
+
24
+ f
25
+ end
26
+
27
+ describe '#each_field' do
28
+ context 'no block given' do
29
+ it 'returns an Enumerator' do
30
+ expect(subject.each_field).to be_a Enumerator
31
+ end
32
+ end
33
+
34
+ context 'block given' do
35
+ it 'yields each geometry field definition' do
36
+ expect { |b| subject.each_field(&b) }.to yield_successive_args(0)
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '#fields' do
42
+ it 'returns all of the field values as an Array' do
43
+ expect(subject.fields).to eq [0]
44
+ end
45
+ end
46
+
47
+ describe '#each_geometry_field_definition' do
48
+ context 'no block given' do
49
+ it 'returns an Enumerator' do
50
+ expect(subject.each_geometry_field_definition).to be_a Enumerator
51
+ end
52
+ end
53
+
54
+ context 'block given' do
55
+ it 'yields each geometry field definition' do
56
+ expect { |b| subject.each_geometry_field_definition(&b) }.
57
+ to yield_successive_args(OGR::GeometryFieldDefinition)
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '#geometry_field_definitions' do
63
+ it 'returns all of the geometry field definitions as an Array of GeometryFieldDefinitions' do
64
+ expect(subject.geometry_field_definitions).to contain_exactly instance_of(OGR::GeometryFieldDefinition)
65
+ end
66
+ end
67
+
68
+ describe '#each_geometry_field' do
69
+ context 'no block given' do
70
+ it 'returns an Enumerator' do
71
+ expect(subject.each_geometry_field).to be_a Enumerator
72
+ end
73
+ end
74
+
75
+ context 'block given' do
76
+ it 'yields each geometry field' do
77
+ expect { |b| subject.each_geometry_field(&b) }.
78
+ to yield_successive_args(geometry)
79
+ end
80
+ end
81
+ end
82
+
83
+ describe '#geometry_fields' do
84
+ it 'returns all of the geometry fields as an Array of Geometries' do
85
+ expect(subject.geometry_fields).to eq [geometry]
86
+ end
87
+ end
88
+ end
@@ -1,34 +1,33 @@
1
1
  require 'spec_helper'
2
2
  require 'date'
3
3
  require 'ogr/feature'
4
+ require 'ogr/field'
4
5
 
5
6
  RSpec.describe OGR::Feature do
6
- let(:integer_field) { OGR::FieldDefinition.new('test integer field', :OFTInteger) }
7
- let(:integer_list_field) { OGR::FieldDefinition.new('test integer list field', :OFTIntegerList) }
8
- let(:real_field) { OGR::FieldDefinition.new('test real field', :OFTReal) }
9
- let(:real_list_field) { OGR::FieldDefinition.new('test real list field', :OFTRealList) }
10
- let(:string_field) { OGR::FieldDefinition.new('test string field', :OFTString) }
11
- let(:string_list_field) { OGR::FieldDefinition.new('test string list field', :OFTStringList) }
12
- let(:binary_field) { OGR::FieldDefinition.new('test binary field', :OFTBinary) }
13
- let(:date_field) { OGR::FieldDefinition.new('test date field', :OFTDate) }
14
-
15
- let(:geometry_field_definition) do
16
- OGR::GeometryFieldDefinition.new('test geometry', :wkbPoint)
17
- end
7
+ let(:integer_field_def) { OGR::FieldDefinition.new('test integer field', :OFTInteger) }
8
+ let(:integer_list_field_def) { OGR::FieldDefinition.new('test integer list field', :OFTIntegerList) }
9
+ let(:real_field_def) { OGR::FieldDefinition.new('test real field', :OFTReal) }
10
+ let(:real_list_field_def) { OGR::FieldDefinition.new('test real list field', :OFTRealList) }
11
+ let(:string_field_def) { OGR::FieldDefinition.new('test string field', :OFTString) }
12
+ let(:string_list_field_def) { OGR::FieldDefinition.new('test string list field', :OFTStringList) }
13
+ let(:binary_field_def) { OGR::FieldDefinition.new('test binary field', :OFTBinary) }
14
+ let(:date_field_def) { OGR::FieldDefinition.new('test date field', :OFTDate) }
18
15
 
19
16
  let(:feature_definition) do
20
17
  fd = OGR::FeatureDefinition.new('test FD')
21
18
 
22
- fd.add_field_definition(integer_field) # 0
23
- fd.add_field_definition(integer_list_field) # 1
24
- fd.add_field_definition(real_field) # 2
25
- fd.add_field_definition(real_list_field) # 3
26
- fd.add_field_definition(string_field) # 4
27
- fd.add_field_definition(string_list_field) # 5
28
- fd.add_field_definition(binary_field) # 6
29
- fd.add_field_definition(date_field) # 7
19
+ fd.add_field_definition(integer_field_def) # 0
20
+ fd.add_field_definition(integer_list_field_def) # 1
21
+ fd.add_field_definition(real_field_def) # 2
22
+ fd.add_field_definition(real_list_field_def) # 3
23
+ fd.add_field_definition(string_field_def) # 4
24
+ fd.add_field_definition(string_list_field_def) # 5
25
+ fd.add_field_definition(binary_field_def) # 6
26
+ fd.add_field_definition(date_field_def) # 7
30
27
 
31
- fd.add_geometry_field_definition(geometry_field_definition)
28
+ gfd = fd.geometry_field_definition(0)
29
+ gfd.type = :wkbPoint
30
+ gfd.name = 'test point'
32
31
 
33
32
  fd
34
33
  end
@@ -218,21 +217,23 @@ RSpec.describe OGR::Feature do
218
217
  end
219
218
 
220
219
  describe '#set_field_raw + #field_as_raw' do
221
- let(:integer_field_struct) do
222
- f = FFI::OGR::Field.new
223
- f[:integer] = 1
220
+ let(:integer_field) do
221
+ f = OGR::Field.new
222
+ f.integer = 1
223
+
224
224
  f
225
225
  end
226
226
 
227
- let(:integer_list_field_struct) do
228
- f = FFI::OGR::Field.new
229
- f[:integer_list] = [1, 2, 3]
227
+ let(:integer_list_field) do
228
+ f = OGR::Field.new
229
+ f.integer_list = [1, 2, 3]
230
+
230
231
  f
231
232
  end
232
233
 
233
234
  context 'to a valid index' do
234
235
  it 'adds the field' do
235
- subject.set_field_raw(0, integer_field_struct)
236
+ subject.set_field_raw(0, integer_field)
236
237
  expect(subject.field_as_integer(0)).to eq 1
237
238
  end
238
239
  end
@@ -240,27 +241,10 @@ RSpec.describe OGR::Feature do
240
241
  context 'to an invalid valid index' do
241
242
  it 'adds the field' do
242
243
  expect do
243
- subject.set_field_raw(100, integer_field_struct)
244
+ subject.set_field_raw(100, integer_field)
244
245
  end.to raise_exception GDAL::Error
245
246
  end
246
247
  end
247
-
248
- context 'raw field is not of the given type' do
249
- let(:int_feature_definition) do
250
- fd = OGR::FeatureDefinition.new('test FD')
251
- fd.add_field_definition(integer_field) # 0
252
-
253
- fd
254
- end
255
-
256
- subject { described_class.new(int_feature_definition) }
257
-
258
- it 'raises a TypeError' do
259
- expect do
260
- subject.set_field_raw(0, integer_list_field_struct)
261
- end.to raise_exception TypeError
262
- end
263
- end
264
248
  end
265
249
 
266
250
  describe '#set_field_binary + #field_as_binary' do
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'ogr'
3
+
4
+ RSpec.describe OGR::GeometryCollection25D do
5
+ describe '#type' do
6
+ context 'when created with data' do
7
+ subject { OGR::Geometry.create_from_wkt(wkt) }
8
+ let(:wkt) { 'GEOMETRYCOLLECTION(POINT(4 6 8),LINESTRING(4 6 8,7 10 11))' }
9
+
10
+ it 'returns :wkbGeometryCollection25D' do
11
+ expect(subject.type).to eq :wkbGeometryCollection25D
12
+ end
13
+ end
14
+
15
+ context 'when created without data' do
16
+ subject { described_class.new }
17
+
18
+ it 'returns :wkbGeometryCollection' do
19
+ expect(subject.type).to eq :wkbGeometryCollection
20
+ end
21
+ end
22
+ end
23
+ end
@@ -64,7 +64,7 @@ RSpec.describe OGR::GeometryCollection do
64
64
  end
65
65
 
66
66
  let(:line_string2) do
67
- OGR::Geometry.create_from_wkt('LINESTRING (100 100,100 200,100 300)')
67
+ OGR::Geometry.create_from_wkt('LINESTRING (100 100,100 20,100 30)')
68
68
  end
69
69
 
70
70
  it 'raises a OGR::Failure error' do
@@ -123,7 +123,7 @@ RSpec.describe OGR::GeometryCollection do
123
123
  end
124
124
 
125
125
  let(:line_string2) do
126
- OGR::Geometry.create_from_wkt('LINESTRING (100 100,100 200,0 2)')
126
+ OGR::Geometry.create_from_wkt('LINESTRING (100 100,100 20,0 2)')
127
127
  end
128
128
 
129
129
  it 'raises a OGR::Failure' do
@@ -178,7 +178,7 @@ RSpec.describe OGR::GeometryCollection do
178
178
  it 'raises a GDAL::UnsupportedOperation or OGR::UnsupportedGeometryType' do
179
179
  expect do
180
180
  subject.polygon_from_edges(100, auto_close: false)
181
- end.to raise_exception
181
+ end.to raise_exception(GDAL::UnsupportedOperation)
182
182
  end
183
183
  end
184
184
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'ogr'
3
+
4
+ RSpec.describe OGR::LineString25D do
5
+ describe '#type' do
6
+ context 'when created with data' do
7
+ subject { OGR::Geometry.create_from_wkt(wkt) }
8
+ let(:wkt) { 'LINESTRING(1 2 3, 2 2 3)' }
9
+
10
+ it 'returns :wkbLineString25D' do
11
+ expect(subject.type).to eq :wkbLineString25D
12
+ end
13
+ end
14
+
15
+ context 'when created without data' do
16
+ subject { described_class.new }
17
+
18
+ it 'returns :wkbLineString' do
19
+ expect(subject.type).to eq :wkbLineString
20
+ end
21
+ end
22
+ end
23
+ end
@@ -49,7 +49,7 @@ RSpec.describe OGR::LineString do
49
49
 
50
50
  describe '#point_count' do
51
51
  subject { open_line_string.point_count }
52
- it { is_expected.to eq 3 }
52
+ it { is_expected.to eq 3 }
53
53
  end
54
54
 
55
55
  describe '#intersects?' do
@@ -76,7 +76,7 @@ RSpec.describe OGR::LineString do
76
76
  context 'other geometry is a line string' do
77
77
  context 'outside the ring' do
78
78
  let(:other_geometry) do
79
- OGR::Geometry.create_from_wkt('LINESTRING (100 100, 200 200)')
79
+ OGR::Geometry.create_from_wkt('LINESTRING (100 100, 20 20)')
80
80
  end
81
81
 
82
82
  subject { open_line_string.intersects?(other_geometry) }
@@ -34,7 +34,7 @@ RSpec.describe OGR::LinearRing do
34
34
 
35
35
  describe '#point_count' do
36
36
  subject { linear_ring.point_count }
37
- it { is_expected.to eq 5 }
37
+ it { is_expected.to eq 5 }
38
38
  end
39
39
 
40
40
  describe '#intersects?' do
@@ -61,7 +61,7 @@ RSpec.describe OGR::LinearRing do
61
61
  context 'other geometry is a line string' do
62
62
  context 'outside the ring' do
63
63
  let(:other_geometry) do
64
- OGR::Geometry.create_from_wkt('LINESTRING (100 100, 200 200)')
64
+ OGR::Geometry.create_from_wkt('LINESTRING (100 100, 20 20)')
65
65
  end
66
66
 
67
67
  subject { linear_ring.intersects?(other_geometry) }