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,145 @@
1
+ require 'spec_helper'
2
+ require 'ogr/layer'
3
+
4
+ RSpec.describe OGR::Layer do
5
+ include_context 'OGR::Layer, spatial_reference'
6
+
7
+ describe '#feature_definition' do
8
+ it 'returns a OGR::FeatureDefinition' do
9
+ expect(subject.feature_definition).to be_a OGR::FeatureDefinition
10
+ end
11
+ end
12
+
13
+ describe '#create_feature' do
14
+ let(:feature) { OGR::Feature.new(subject.feature_definition) }
15
+
16
+ context 'creation is not supported' do
17
+ before { expect(subject).to receive(:can_sequential_write?).and_return(false) }
18
+
19
+ it 'raises an OGR::UnsupportedOperation' do
20
+ expect { subject.create_feature(feature) }.to raise_exception OGR::UnsupportedOperation
21
+ end
22
+ end
23
+
24
+ context 'creation is supported' do
25
+ it 'returns true' do
26
+ expect(subject.create_feature(feature)).to eq true
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#delete_feature' do
32
+ context 'deletion is not supported' do
33
+ before { expect(subject).to receive(:can_delete_feature?).and_return(false) }
34
+
35
+ it 'raises an OGR::UnsupportedOperation' do
36
+ expect { subject.delete_feature(0) }.to raise_exception OGR::UnsupportedOperation
37
+ end
38
+ end
39
+
40
+ context 'deletion is supported' do
41
+ context 'no features' do
42
+ it 'raises an OGR::Failure' do
43
+ expect { subject.delete_feature(0) }.to raise_exception OGR::Failure
44
+ end
45
+ end
46
+
47
+ context 'has a feature' do
48
+ before { subject.create_feature(OGR::Feature.new(subject.feature_definition)) }
49
+
50
+ it 'returns true' do
51
+ expect(subject.delete_feature(0)).to eq true
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '#feature_count' do
58
+ it 'returns the number of features' do
59
+ expect(subject.feature_count).to be_zero
60
+ end
61
+ end
62
+
63
+ describe '#feature' do
64
+ context 'cannot random read' do
65
+ before { expect(subject).to receive(:can_random_read?).and_return(false) }
66
+
67
+ it 'raises an OGR::UnsupportedOperation' do
68
+ expect { subject.feature(0) }.to raise_exception OGR::UnsupportedOperation
69
+ end
70
+ end
71
+
72
+ context 'can random read' do
73
+ context 'no features' do
74
+ it 'returns nil' do
75
+ expect(subject.feature(0)).to be_nil
76
+ end
77
+ end
78
+
79
+ context 'has a feature' do
80
+ before { subject.create_feature(OGR::Feature.new(subject.feature_definition)) }
81
+
82
+ it 'returns an OGR::Feature' do
83
+ expect(subject.feature(0)).to be_a OGR::Feature
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '#feature=' do
90
+ context 'cannot random write' do
91
+ before { expect(subject).to receive(:can_random_write?).and_return(false) }
92
+
93
+ it 'raises an OGR::UnsupportedOperation' do
94
+ expect { subject.feature = OGR::Feature.new(subject.feature_definition) }.
95
+ to raise_exception OGR::UnsupportedOperation
96
+ end
97
+ end
98
+
99
+ context 'can random write' do
100
+ it 'adds the feature' do
101
+ skip
102
+ end
103
+ end
104
+ end
105
+
106
+ describe 'next_feature' do
107
+ context 'no features' do
108
+ it 'returns nil' do
109
+ expect(subject.next_feature).to be_nil
110
+ end
111
+ end
112
+
113
+ context 'has a feature' do
114
+ before { subject.create_feature(OGR::Feature.new(subject.feature_definition)) }
115
+
116
+ it 'returns an OGR::Feature' do
117
+ expect(subject.next_feature).to be_a OGR::Feature
118
+ end
119
+ end
120
+ end
121
+
122
+ describe '#next_feature_index=' do
123
+ context 'no features' do
124
+ it 'raises an OGR::Failure' do
125
+ expect { subject.next_feature_index = 123 }.
126
+ to raise_exception OGR::Failure
127
+ end
128
+ end
129
+
130
+ context 'features exist' do
131
+ let!(:feature1) do
132
+ subject.create_feature(OGR::Feature.new(subject.feature_definition))
133
+ end
134
+
135
+ let!(:feature2) do
136
+ subject.create_feature(OGR::Feature.new(subject.feature_definition))
137
+ end
138
+
139
+ it 'sets to the given feature' do
140
+ subject.next_feature_index = 1
141
+ expect(subject.next_feature).to_not be_nil
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,432 @@
1
+ require 'spec_helper'
2
+ require 'ogr/layer'
3
+
4
+ RSpec.describe OGR::Layer do
5
+ include_context 'OGR::Layer, spatial_reference'
6
+
7
+ describe '#create_field + #find_field_index' do
8
+ context 'creation not supported' do
9
+ before do
10
+ expect(subject).to receive(:can_create_field?).and_return false
11
+ end
12
+
13
+ it 'raises an OGR::UnsupportedOperation' do
14
+ expect { subject.create_field(OGR::FieldDefinition.new('test', :OFTInteger)) }.
15
+ to raise_exception OGR::UnsupportedOperation
16
+ end
17
+ end
18
+
19
+ context 'creation is supported' do
20
+ it 'can create an OFTInteger' do
21
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTInteger))
22
+ expect(subject.find_field_index('test field')).to be_zero
23
+ end
24
+
25
+ it 'can create an OFTIntegerList' do
26
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTIntegerList))
27
+ expect(subject.find_field_index('test field')).to be_zero
28
+ end
29
+
30
+ it 'can create an OFTReal' do
31
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTReal))
32
+ expect(subject.find_field_index('test field')).to be_zero
33
+ end
34
+
35
+ it 'can create an OFTRealList' do
36
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTRealList))
37
+ expect(subject.find_field_index('test field')).to be_zero
38
+ end
39
+
40
+ it 'can create an OFTString' do
41
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTString))
42
+ expect(subject.find_field_index('test field')).to be_zero
43
+ end
44
+
45
+ it 'can create an OFTStringList' do
46
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTStringList))
47
+ expect(subject.find_field_index('test field')).to be_zero
48
+ end
49
+
50
+ it 'can create an OFTWideString' do
51
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTWideString))
52
+ expect(subject.find_field_index('test field')).to be_zero
53
+ end
54
+
55
+ it 'can create an OFTWideStringList' do
56
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTWideStringList))
57
+ expect(subject.find_field_index('test field')).to be_zero
58
+ end
59
+
60
+ it 'can create an OFTBinary' do
61
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTBinary))
62
+ expect(subject.find_field_index('test field')).to be_zero
63
+ end
64
+
65
+ it 'can create an OFTDate' do
66
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTDate))
67
+ expect(subject.find_field_index('test field')).to be_zero
68
+ end
69
+
70
+ it 'can create an OFTTime' do
71
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTTime))
72
+ expect(subject.find_field_index('test field')).to be_zero
73
+ end
74
+
75
+ it 'can create an OFTDateTime' do
76
+ subject.create_field(OGR::FieldDefinition.new('test field', :OFTDateTime))
77
+ expect(subject.find_field_index('test field')).to be_zero
78
+ end
79
+ end
80
+ end
81
+
82
+ describe '#delete_field + #create_field' do
83
+ context 'delete not supported' do
84
+ before do
85
+ expect(subject).to receive(:can_delete_field?).and_return false
86
+ end
87
+
88
+ it 'raises an OGR::UnsupportedOperation' do
89
+ expect { subject.delete_field(0) }.to raise_exception OGR::UnsupportedOperation
90
+ end
91
+ end
92
+
93
+ context 'delete is supported' do
94
+ context 'field exists at index' do
95
+ before do
96
+ fd = OGR::FieldDefinition.new('test field', :OFTInteger)
97
+ subject.create_field(fd)
98
+ end
99
+
100
+ it 'can delete the field' do
101
+ expect(subject.delete_field(0)).to eq true
102
+ end
103
+ end
104
+
105
+ context 'field does not exist at index' do
106
+ it 'raises a GDAL::UnsupportedOperation' do
107
+ expect { subject.delete_field(1) }.to raise_exception GDAL::UnsupportedOperation
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ describe '#reorder_fields + #create_field' do
114
+ context 'reordering not supported' do
115
+ before do
116
+ expect(subject).to receive(:can_reorder_fields?).and_return false
117
+ end
118
+
119
+ it 'raises an OGR::UnsupportedOperation' do
120
+ expect { subject.reorder_fields(1, 0) }.to raise_exception OGR::UnsupportedOperation
121
+ end
122
+ end
123
+
124
+ context 'reordering is supported' do
125
+ context 'field does not exist at one of the given indexes' do
126
+ it 'returns false' do
127
+ expect(subject.reorder_fields(1, 0)).to eq false
128
+ end
129
+ end
130
+
131
+ context 'no fields given' do
132
+ it 'returns false' do
133
+ expect(subject.reorder_fields).to eq false
134
+ end
135
+ end
136
+
137
+ context 'fields exist' do
138
+ before do
139
+ fd0 = OGR::FieldDefinition.new('field0', :OFTInteger)
140
+ fd1 = OGR::FieldDefinition.new('field1', :OFTString)
141
+ subject.create_field(fd0)
142
+ subject.create_field(fd1)
143
+ end
144
+
145
+ it 'returns true and reorders the fields' do
146
+ expect(subject.find_field_index('field0')).to eq 0
147
+ expect(subject.find_field_index('field1')).to eq 1
148
+
149
+ expect(subject.reorder_fields(1, 0)).to eq true
150
+
151
+ expect(subject.find_field_index('field0')).to eq 1
152
+ expect(subject.find_field_index('field1')).to eq 0
153
+ end
154
+
155
+ it "updates the feature definition's field definitions" do
156
+ expect(subject.feature_definition.field_definition(0).name).to eq 'field0'
157
+ expect(subject.feature_definition.field_definition(1).name).to eq 'field1'
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+ describe '#reorder_field + #create_field' do
164
+ context 'reordering not supported' do
165
+ before do
166
+ expect(subject).to receive(:can_reorder_fields?).and_return false
167
+ end
168
+
169
+ it 'raises an OGR::UnsupportedOperation' do
170
+ expect { subject.reorder_field(1, 0) }.to raise_exception OGR::UnsupportedOperation
171
+ end
172
+ end
173
+
174
+ context 'reordering is supported' do
175
+ context 'field does not exist at one of the given indexes' do
176
+ it 'raises a GDAL::UnsupportedOperation' do
177
+ expect { subject.reorder_field(1, 0) }.to raise_exception GDAL::UnsupportedOperation
178
+ end
179
+ end
180
+
181
+ context 'fields exist' do
182
+ before do
183
+ fd0 = OGR::FieldDefinition.new('field0', :OFTInteger)
184
+ fd1 = OGR::FieldDefinition.new('field1', :OFTString)
185
+ subject.create_field(fd0)
186
+ subject.create_field(fd1)
187
+ end
188
+
189
+ it 'returns true and reorders the fields' do
190
+ expect(subject.find_field_index('field0')).to eq 0
191
+ expect(subject.find_field_index('field1')).to eq 1
192
+
193
+ expect(subject.reorder_field(1, 0)).to eq true
194
+
195
+ expect(subject.find_field_index('field0')).to eq 1
196
+ expect(subject.find_field_index('field1')).to eq 0
197
+ end
198
+
199
+ it "updates the feature definition's field definitions" do
200
+ expect(subject.feature_definition.field_definition(0).name).to eq 'field0'
201
+ expect(subject.feature_definition.field_definition(1).name).to eq 'field1'
202
+ end
203
+ end
204
+ end
205
+ end
206
+
207
+ describe '#alter_field_definition + #create_field' do
208
+ context 'altering not supported' do
209
+ before do
210
+ expect(subject).to receive(:can_alter_field_definition?).and_return false
211
+ end
212
+
213
+ it 'raises an OGR::UnsupportedOperation' do
214
+ expect do
215
+ subject.alter_field_definition(123, OGR::FieldDefinition.new('blah', :OFTString), OGR::Layer::ALTER_ALL_FLAG)
216
+ end.to raise_exception OGR::UnsupportedOperation
217
+ end
218
+ end
219
+
220
+ context 'altering is supported' do
221
+ let(:string_field_def) do
222
+ fd = OGR::FieldDefinition.new('StringField', :OFTString)
223
+ fd.width = 16
224
+
225
+ fd
226
+ end
227
+
228
+ let(:int_field_def) do
229
+ fd = OGR::FieldDefinition.new('IntField', :OFTInteger)
230
+ fd.width = 4
231
+
232
+ fd
233
+ end
234
+
235
+ let(:real_field_def) do
236
+ fd = OGR::FieldDefinition.new('RealField', :OFTReal)
237
+ fd.width = 8
238
+
239
+ fd
240
+ end
241
+
242
+ context 'no field at given index' do
243
+ it 'raises a GDAL::UnsupportedOperation' do
244
+ expect do
245
+ subject.alter_field_definition(123, int_field_def, OGR::Layer::ALTER_ALL_FLAG)
246
+ end.to raise_exception GDAL::UnsupportedOperation
247
+ end
248
+ end
249
+
250
+ context 'field exists at given index' do
251
+ context 'ALTER_NAME_FLAG' do
252
+ before { subject.create_field(string_field_def) }
253
+
254
+ it 'only alters the name of the field' do
255
+ subject.alter_field_definition(0, int_field_def, OGR::Layer::ALTER_NAME_FLAG)
256
+
257
+ expect(subject.feature_definition.field_definition(0).name).to eq 'IntField'
258
+ expect(subject.feature_definition.field_definition(0).type).to eq :OFTString
259
+ expect(subject.feature_definition.field_definition(0).width).to eq 16
260
+ end
261
+ end
262
+
263
+ context 'ALTER_TYPE_FLAG' do
264
+ context 'convert OFTString to OFTInteger' do
265
+ before { subject.create_field(string_field_def) }
266
+
267
+ it 'raises a GDAL::UnsupportedOperation' do
268
+ expect do
269
+ subject.alter_field_definition(0, int_field_def, OGR::Layer::ALTER_TYPE_FLAG)
270
+ end.to raise_exception GDAL::UnsupportedOperation
271
+ end
272
+ end
273
+
274
+ context 'convert OFTInteger to OFTString' do
275
+ before { subject.create_field(int_field_def) }
276
+
277
+ it 'only alters the type of the field' do
278
+ subject.alter_field_definition(0, string_field_def, OGR::Layer::ALTER_TYPE_FLAG)
279
+
280
+ expect(subject.feature_definition.field_definition(0).name).to eq 'IntField'
281
+ expect(subject.feature_definition.field_definition(0).type).to eq :OFTString
282
+ expect(subject.feature_definition.field_definition(0).width).to eq 4
283
+ end
284
+ end
285
+
286
+ context 'convert OFTInteger to OFTReal' do
287
+ before { subject.create_field(int_field_def) }
288
+
289
+ it 'only alters the type of the field' do
290
+ subject.alter_field_definition(0, real_field_def, OGR::Layer::ALTER_TYPE_FLAG)
291
+
292
+ expect(subject.feature_definition.field_definition(0).name).to eq 'IntField'
293
+ expect(subject.feature_definition.field_definition(0).type).to eq :OFTReal
294
+ expect(subject.feature_definition.field_definition(0).width).to eq 4
295
+ end
296
+ end
297
+
298
+ context 'convert OFTReal to OFTInteger' do
299
+ before { subject.create_field(real_field_def) }
300
+
301
+ it 'raises a GDAL::UnsupportedOperation' do
302
+ expect do
303
+ subject.alter_field_definition(0, int_field_def, OGR::Layer::ALTER_TYPE_FLAG)
304
+ end.to raise_exception GDAL::UnsupportedOperation
305
+ end
306
+ end
307
+ end
308
+
309
+ context 'ALTER_WIDTH_PRECISION_FLAG' do
310
+ before { subject.create_field(string_field_def) }
311
+
312
+ it 'only alters the width of the field' do
313
+ subject.alter_field_definition(0, int_field_def, OGR::Layer::ALTER_WIDTH_PRECISION_FLAG)
314
+
315
+ expect(subject.feature_definition.field_definition(0).name).to eq 'StringField'
316
+ expect(subject.feature_definition.field_definition(0).type).to eq :OFTString
317
+ expect(subject.feature_definition.field_definition(0).width).to eq 4
318
+ end
319
+ end
320
+
321
+ context 'ALTER_ALL_FLAG' do
322
+ context 'convert OFTString to OFTInteger' do
323
+ before { subject.create_field(string_field_def) }
324
+
325
+ it 'raises a GDAL::UnsupportedOperation' do
326
+ expect do
327
+ subject.alter_field_definition(0, int_field_def, OGR::Layer::ALTER_ALL_FLAG)
328
+ end.to raise_exception GDAL::UnsupportedOperation
329
+ end
330
+ end
331
+
332
+ context 'convert OFTInteger to OFTString' do
333
+ before { subject.create_field(int_field_def) }
334
+
335
+ it 'alters all attributes of the field' do
336
+ subject.alter_field_definition(0, string_field_def, OGR::Layer::ALTER_ALL_FLAG)
337
+
338
+ expect(subject.feature_definition.field_definition(0).name).to eq 'StringField'
339
+ expect(subject.feature_definition.field_definition(0).type).to eq :OFTString
340
+ expect(subject.feature_definition.field_definition(0).width).to eq 16
341
+ end
342
+ end
343
+
344
+ context 'convert OFTInteger to OFTReal' do
345
+ before { subject.create_field(int_field_def) }
346
+
347
+ it 'alters all attributes of the field' do
348
+ subject.alter_field_definition(0, real_field_def, OGR::Layer::ALTER_ALL_FLAG)
349
+
350
+ expect(subject.feature_definition.field_definition(0).name).to eq 'RealField'
351
+ expect(subject.feature_definition.field_definition(0).type).to eq :OFTReal
352
+ expect(subject.feature_definition.field_definition(0).width).to eq 8
353
+ end
354
+ end
355
+
356
+ context 'convert OFTReal to OFTInteger' do
357
+ before { subject.create_field(real_field_def) }
358
+
359
+ it 'raises a GDAL::UnsupportedOperation' do
360
+ expect do
361
+ subject.alter_field_definition(0, int_field_def, OGR::Layer::ALTER_ALL_FLAG)
362
+ end.to raise_exception GDAL::UnsupportedOperation
363
+ end
364
+ end
365
+ end
366
+ end
367
+ end
368
+ end
369
+
370
+ describe '#find_field_index' do
371
+ context 'field with name does not exist' do
372
+ it 'returns nil' do
373
+ expect(subject.find_field_index('meow')).to be_nil
374
+ end
375
+ end
376
+
377
+ context 'field with name exists' do
378
+ before { subject.create_field(OGR::FieldDefinition.new('meow', :OFTString)) }
379
+
380
+ it 'returns the index' do
381
+ expect(subject.find_field_index('meow')).to be_zero
382
+ end
383
+ end
384
+ end
385
+
386
+ describe '#create_geometry_field' do
387
+ let(:geometry_field_def) { OGR::GeometryFieldDefinition.new('geofield0') }
388
+
389
+ context 'creation not supported' do
390
+ before do
391
+ expect(subject).to receive(:can_create_geometry_field?).and_return false
392
+ end
393
+
394
+ it 'raises an OGR::UnsupportedOperation' do
395
+ expect { subject.create_geometry_field(geometry_field_def) }.
396
+ to raise_exception OGR::UnsupportedOperation
397
+ end
398
+ end
399
+
400
+ context 'creation is supported' do
401
+ it 'returns true' do
402
+ expect(subject.create_geometry_field(geometry_field_def)).to eq true
403
+ end
404
+ end
405
+ end
406
+
407
+ describe '#set_ignored_fields' do
408
+ context 'no fields given' do
409
+ it 'returns false' do
410
+ expect(subject.set_ignored_fields).to eq false
411
+ end
412
+ end
413
+
414
+ context 'invalid field names given' do
415
+ it 'raises an OGR::Failure' do
416
+ expect { subject.set_ignored_fields('meow', 'bobo') }.
417
+ to raise_exception OGR::Failure
418
+ end
419
+ end
420
+
421
+ context 'valid field names given' do
422
+ before do
423
+ subject.create_field(OGR::FieldDefinition.new('meow', :OFTInteger))
424
+ subject.create_field(OGR::FieldDefinition.new('bobo', :OFTInteger))
425
+ end
426
+
427
+ it 'returns true' do
428
+ expect(subject.set_ignored_fields('meow', 'bobo')).to eq true
429
+ end
430
+ end
431
+ end
432
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'ogr/layer'
3
+
4
+ RSpec.describe OGR::Layer do
5
+ include_context 'OGR::Layer, spatial_reference'
6
+
7
+ describe '#symmetrical_difference' do
8
+ let(:other_layer) do
9
+ data_source.create_layer 'other layer',
10
+ geometry_type: :wkbMultiPoint,
11
+ spatial_reference: OGR::SpatialReference.new_from_epsg(4326)
12
+ end
13
+
14
+ it 'does not die' do
15
+ skip 'Figuring out how to init a result pointer'
16
+ # expect { subject.symmetrical_difference(other_layer) }.
17
+ # to_not raise_exception
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'ogr/layer'
3
+
4
+ RSpec.describe OGR::Layer do
5
+ include_context 'OGR::Layer, spatial_reference'
6
+
7
+ describe '#spatial_filter' do
8
+ context 'default' do
9
+ subject { layer.spatial_filter }
10
+ it { is_expected.to be_nil }
11
+ end
12
+ end
13
+
14
+ describe '#spatial_filter= + #spatial_filter' do
15
+ it 'assigns the spatial_filter to the new geometry' do
16
+ geometry = OGR::Geometry.create_from_wkt('POINT (1 1)')
17
+ subject.spatial_filter = geometry
18
+ expect(subject.spatial_filter).to eq geometry
19
+ end
20
+ end
21
+
22
+ describe '#set_spatial_filter_ex' do
23
+ it 'does not die' do
24
+ geometry = OGR::Geometry.create_from_wkt('POINT (1 1)')
25
+ expect { subject.set_spatial_filter_ex(0, geometry) }.to_not raise_exception
26
+ end
27
+ end
28
+
29
+ describe '#set_spatial_filter_rectangle' do
30
+ it 'does not die' do
31
+ expect { subject.set_spatial_filter_rectangle(0, 0, 1000, 1000) }.
32
+ to_not raise_exception
33
+ end
34
+ end
35
+
36
+ describe '#set_spatial_filter_rectangle_ex' do
37
+ it 'does not die' do
38
+ expect { subject.set_spatial_filter_rectangle_ex(0, 0, 0, 1000, 1000) }.
39
+ to_not raise_exception
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'ogr/layer'
3
+
4
+ RSpec.describe OGR::Layer do
5
+ include_context 'OGR::Layer, spatial_reference'
6
+
7
+ describe '#geometry_column' do
8
+ it 'returns a String' do
9
+ expect(subject.geometry_column).to be_a String
10
+ end
11
+ end
12
+ end