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,135 @@
1
+ require 'spec_helper'
2
+ require 'ogr/field_definition'
3
+
4
+ RSpec.describe OGR::FieldDefinition do
5
+ subject(:field) { described_class.new('test field', :OFTInteger) }
6
+
7
+ describe '#set' do
8
+ before do
9
+ subject.set('new name', :OFTString, 5, 2, :OJRight)
10
+ end
11
+
12
+ it 'sets the name' do
13
+ expect(subject.name).to eq 'new name'
14
+ end
15
+
16
+ it 'sets the width' do
17
+ expect(subject.width).to eq 5
18
+ end
19
+
20
+ it 'sets the precision' do
21
+ expect(subject.precision).to eq 2
22
+ end
23
+
24
+ it 'sets the justification' do
25
+ expect(subject.justification).to eq :OJRight
26
+ end
27
+ end
28
+
29
+ describe '#name' do
30
+ it 'returns the name given during creation' do
31
+ expect(subject.name).to eq 'test field'
32
+ end
33
+ end
34
+
35
+ describe '#name= + #name' do
36
+ it 'assigns the name' do
37
+ subject.name = 'new test name'
38
+ expect(subject.name).to eq 'new test name'
39
+ end
40
+ end
41
+
42
+ describe '#justification' do
43
+ context 'default' do
44
+ it 'returns :OJUndefined' do
45
+ expect(subject.justification).to eq :OJUndefined
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#justification= + #justification' do
51
+ it 'assigns the justification' do
52
+ subject.justification = :OJLeft
53
+ expect(subject.justification).to eq :OJLeft
54
+ end
55
+ end
56
+
57
+ describe '#precision' do
58
+ context 'default' do
59
+ it 'returns 0' do
60
+ expect(subject.precision).to be_zero
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '#precision= + #precision' do
66
+ it 'assigns the precision' do
67
+ subject.precision = 1
68
+ expect(subject.precision).to eq 1
69
+ end
70
+ end
71
+
72
+ describe '#type' do
73
+ context 'default' do
74
+ it 'returns the value it was created with' do
75
+ expect(subject.type).to eq :OFTInteger
76
+ end
77
+ end
78
+ end
79
+
80
+ describe '#type= + #type' do
81
+ it 'assigns the type' do
82
+ subject.type = :OFTString
83
+ expect(subject.type).to eq :OFTString
84
+ end
85
+ end
86
+
87
+ describe '#width' do
88
+ context 'default' do
89
+ it 'returns 0' do
90
+ expect(subject.width).to be_zero
91
+ end
92
+ end
93
+ end
94
+
95
+ describe '#width= + #width' do
96
+ it 'assigns the width' do
97
+ subject.width = 1
98
+ expect(subject.width).to eq 1
99
+ end
100
+ end
101
+
102
+ describe '#ignored?' do
103
+ context 'default' do
104
+ it 'returns false' do
105
+ expect(subject).to_not be_ignored
106
+ end
107
+ end
108
+ end
109
+
110
+ describe '#ignore= + #ignored?' do
111
+ it 'assigns the value' do
112
+ subject.ignore = true
113
+ expect(subject).to be_ignored
114
+ end
115
+ end
116
+
117
+ describe '#as_json' do
118
+ it 'returns a Hash of attributes' do
119
+ expect(subject.as_json).to eq(
120
+ is_ignored: false,
121
+ justification: :OJUndefined,
122
+ name: 'test field',
123
+ precision: 0,
124
+ type: :OFTInteger,
125
+ width: 0
126
+ )
127
+ end
128
+ end
129
+
130
+ describe '#to_json' do
131
+ it 'returns a string' do
132
+ expect(subject.to_json).to be_a String
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,193 @@
1
+ require 'spec_helper'
2
+ require 'ogr/field'
3
+
4
+ RSpec.describe OGR::Field do
5
+ describe '#integer' do
6
+ context 'not set' do
7
+ it 'returns 0.0' do
8
+ expect(subject.integer).to eql 0
9
+ end
10
+ end
11
+ end
12
+
13
+ describe '#integer= + #integer' do
14
+ context 'valid int' do
15
+ it 'sets the value' do
16
+ subject.integer = 1
17
+ expect(subject.integer).to eq 1
18
+ end
19
+ end
20
+ end
21
+
22
+ describe '#integer64' do
23
+ context 'not set' do
24
+ it 'returns 0.0' do
25
+ expect(subject.integer64).to eql 0
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#integer64= + #integer64' do
31
+ context 'valid int64' do
32
+ it 'sets the value' do
33
+ subject.integer64 = 2**32 + 1
34
+ expect(subject.integer64).to eq 2**32 + 1
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '#real' do
40
+ context 'not set' do
41
+ it 'returns 0.0' do
42
+ expect(subject.real).to eql 0.0
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#real= + #real' do
48
+ context 'valid float' do
49
+ it 'sets the value' do
50
+ subject.real = 1.23
51
+ expect(subject.real).to eq 1.23
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '#string' do
57
+ context 'not set' do
58
+ it 'returns an empty string' do
59
+ expect(subject.string).to eq ''
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '#string= + #string' do
65
+ context 'valid string' do
66
+ it 'sets the value' do
67
+ subject.string = 'meow'
68
+ expect(subject.string).to eq 'meow'
69
+ end
70
+ end
71
+ end
72
+
73
+ describe '#integer_list' do
74
+ context 'not set' do
75
+ it 'returns an empty array' do
76
+ expect(subject.integer_list).to eq []
77
+ end
78
+ end
79
+ end
80
+
81
+ describe '#integer_list= + #integer_list' do
82
+ context 'valid int array' do
83
+ it 'sets the value' do
84
+ subject.integer_list = [1, 2]
85
+ expect(subject.integer_list).to eq [1, 2]
86
+ end
87
+ end
88
+ end
89
+
90
+ describe '#integer64_list' do
91
+ context 'not set' do
92
+ it 'returns an empty array' do
93
+ expect(subject.integer64_list).to eq []
94
+ end
95
+ end
96
+ end
97
+
98
+ describe '#integer64_list= + #integer64_list' do
99
+ context 'valid int64 array' do
100
+ it 'sets the value' do
101
+ subject.integer64_list = [2**32 + 1, 2**32 + 2]
102
+ expect(subject.integer64_list).to eq [2**32 + 1, 2**32 + 2]
103
+ end
104
+ end
105
+ end
106
+
107
+ describe '#real_list' do
108
+ context 'not set' do
109
+ it 'returns an empty array' do
110
+ expect(subject.real_list).to eq []
111
+ end
112
+ end
113
+ end
114
+
115
+ describe '#real_list= + #real_list' do
116
+ context 'valid float array' do
117
+ it 'sets the value' do
118
+ subject.real_list = [1.5, 6.9]
119
+ expect(subject.real_list).to eq [1.5, 6.9]
120
+ end
121
+ end
122
+ end
123
+
124
+ describe '#string_list' do
125
+ context 'not set' do
126
+ it 'returns an empty array' do
127
+ expect(subject.string_list).to eq []
128
+ end
129
+ end
130
+ end
131
+
132
+ describe '#string_list= + #string_list' do
133
+ context 'valid string array' do
134
+ it 'sets the value' do
135
+ subject.string_list = %w[one two]
136
+ expect(subject.string_list).to eq %w[one two]
137
+ end
138
+ end
139
+ end
140
+
141
+ describe '#binary' do
142
+ context 'not set' do
143
+ it 'returns an empty string' do
144
+ expect(subject.binary).to eq ''
145
+ end
146
+ end
147
+ end
148
+
149
+ describe '#binary= + #binary' do
150
+ context 'valid binary' do
151
+ it 'sets the value' do
152
+ subject.binary = [1, 2, 3].pack('C*')
153
+ expect(subject.binary).to eq [1, 2, 3].pack('C*')
154
+ end
155
+ end
156
+ end
157
+
158
+ describe '#set' do
159
+ context 'not set' do
160
+ it 'returns a Hash with markers set to 0' do
161
+ expect(subject.set).to eq(marker1: 0, marker2: 0)
162
+ end
163
+ end
164
+ end
165
+
166
+ describe '#set= + #set' do
167
+ context 'valid set hash' do
168
+ it 'sets the value' do
169
+ subject.set = { marker1: 1, marker2: 200 }
170
+ expect(subject.set).to eq(marker1: 1.0, marker2: 200)
171
+ end
172
+ end
173
+ end
174
+
175
+ describe '#date' do
176
+ context 'not set' do
177
+ it 'returns nil' do
178
+ expect(subject.date).to be_nil
179
+ end
180
+ end
181
+ end
182
+
183
+ describe '#date= + #date' do
184
+ context 'valid date' do
185
+ let(:now) { DateTime.now }
186
+
187
+ it 'sets the date' do
188
+ subject.date = now
189
+ expect(subject.date.httpdate).to eq now.httpdate
190
+ end
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,186 @@
1
+ require 'spec_helper'
2
+ require 'ogr/geometry'
3
+
4
+ RSpec.describe OGR::GeometryCollection do
5
+ it_behaves_like 'a geometry' do
6
+ let(:geometry) { described_class.new }
7
+ end
8
+
9
+ it_behaves_like 'a container geometry' do
10
+ let(:child_geometry) do
11
+ OGR::Geometry.create_from_wkt('POLYGON ((0 0,0 1,1 1,1 0,0 0))')
12
+ end
13
+ end
14
+
15
+ describe '#to_polygon' do
16
+ let(:polygon) do
17
+ OGR::Geometry.create_from_wkt('POLYGON ((0 0,0 1,1 1,1 0,0 0))')
18
+ end
19
+
20
+ subject do
21
+ gc = described_class.new
22
+ gc.add_geometry(polygon)
23
+ gc
24
+ end
25
+
26
+ it 'returns a Polygon' do
27
+ expect(subject.to_polygon).to be_a OGR::Polygon
28
+ end
29
+ end
30
+
31
+ describe '#to_multi_polygon' do
32
+ let(:polygon1) do
33
+ OGR::Geometry.create_from_wkt('POLYGON ((0 0,0 1,1 1,1 0,0 0))')
34
+ end
35
+
36
+ let(:polygon2) do
37
+ OGR::Geometry.create_from_wkt('POLYGON ((10 10,10 11,11 11,11 10,10 10))')
38
+ end
39
+
40
+ subject do
41
+ gc = described_class.new
42
+ gc.add_geometry(polygon1)
43
+ gc.add_geometry(polygon2)
44
+ gc
45
+ end
46
+
47
+ it 'returns a MultiPolygon' do
48
+ expect(subject.to_multi_polygon).to be_a OGR::MultiPolygon
49
+ end
50
+ end
51
+
52
+ describe '#polygon_from_edges' do
53
+ context 'auto_close is false' do
54
+ subject do
55
+ gc = described_class.new
56
+ gc.add_geometry(line_string1)
57
+ gc.add_geometry(line_string2)
58
+ gc.polygon_from_edges(10, auto_close: false)
59
+ end
60
+
61
+ context 'points are not within tolerance' do
62
+ let(:line_string1) do
63
+ OGR::Geometry.create_from_wkt('LINESTRING (0 0,0 1,0 2)')
64
+ end
65
+
66
+ let(:line_string2) do
67
+ OGR::Geometry.create_from_wkt('LINESTRING (100 100,100 200,100 300)')
68
+ end
69
+
70
+ it 'raises a OGR::Failure error' do
71
+ expect { subject }.to raise_exception OGR::Failure
72
+ end
73
+ end
74
+
75
+ context 'points are within tolerance, not closed' do
76
+ let(:line_string1) do
77
+ OGR::Geometry.create_from_wkt('LINESTRING (0 0,0 1,0 2)')
78
+ end
79
+
80
+ let(:line_string2) do
81
+ OGR::Geometry.create_from_wkt('LINESTRING (1 1,1 2,1 3)')
82
+ end
83
+
84
+ it 'returns a Polygon' do
85
+ expect(subject).to be_a OGR::Polygon
86
+ end
87
+
88
+ it 'returns WKT with the merged strings' do
89
+ expect(subject.to_wkt).to eq 'POLYGON ((0 0,0 1,0 2,1 1,1 2,1 3))'
90
+ end
91
+ end
92
+
93
+ context 'points are within tolerance and closed' do
94
+ let(:line_string1) do
95
+ OGR::Geometry.create_from_wkt('LINESTRING (0 0,0 1,0 2)')
96
+ end
97
+
98
+ let(:line_string2) do
99
+ OGR::Geometry.create_from_wkt('LINESTRING (0 2,1 4,0 0)')
100
+ end
101
+
102
+ it 'returns a Polygon' do
103
+ expect(subject).to be_a OGR::Polygon
104
+ end
105
+
106
+ it 'returns WKT with the merged strings' do
107
+ expect(subject.to_wkt).to eq 'POLYGON ((0 0,0 1,0 2,1 4,0 0))'
108
+ end
109
+ end
110
+ end
111
+
112
+ context 'auto_close is true' do
113
+ subject do
114
+ gc = described_class.new
115
+ gc.add_geometry(line_string1)
116
+ gc.add_geometry(line_string2)
117
+ gc.polygon_from_edges(10, auto_close: true)
118
+ end
119
+
120
+ context 'points are not within tolerance' do
121
+ let(:line_string1) do
122
+ OGR::Geometry.create_from_wkt('LINESTRING (0 0,0 1,0 2)')
123
+ end
124
+
125
+ let(:line_string2) do
126
+ OGR::Geometry.create_from_wkt('LINESTRING (100 100,100 200,0 2)')
127
+ end
128
+
129
+ it 'raises a OGR::Failure' do
130
+ expect { subject }.to raise_exception OGR::Failure
131
+ end
132
+ end
133
+
134
+ context 'points are within tolerance, not closed' do
135
+ let(:line_string1) do
136
+ OGR::Geometry.create_from_wkt('LINESTRING (0 0,0 1,0 2)')
137
+ end
138
+
139
+ let(:line_string2) do
140
+ OGR::Geometry.create_from_wkt('LINESTRING (1 1,1 2,1 3)')
141
+ end
142
+
143
+ it 'returns a Polygon' do
144
+ expect(subject).to be_a OGR::Polygon
145
+ end
146
+
147
+ it 'returns WKT with the merged strings' do
148
+ expect(subject.to_wkt).
149
+ to eq 'POLYGON ((0 0 0,0 1 0,0 2 0,1 1 0,1 2 0,1 3 0,0 0 0))'
150
+ end
151
+ end
152
+
153
+ context 'points are within tolerance and already closed' do
154
+ let(:line_string1) do
155
+ OGR::Geometry.create_from_wkt('LINESTRING (0 0,0 1,0 2)')
156
+ end
157
+
158
+ let(:line_string2) do
159
+ OGR::Geometry.create_from_wkt('LINESTRING (0 2,1 4,0 0)')
160
+ end
161
+
162
+ it 'returns a Polygon' do
163
+ expect(subject).to be_a OGR::Polygon
164
+ end
165
+
166
+ it 'returns WKT with the merged strings' do
167
+ expect(subject.to_wkt).to eq 'POLYGON ((0 0,0 1,0 2,1 4,0 0))'
168
+ end
169
+ end
170
+
171
+ context 'unsupported geometries' do
172
+ subject do
173
+ gc = described_class.new
174
+ gc.add_geometry(OGR::MultiPolygon.new)
175
+ gc
176
+ end
177
+
178
+ it 'raises a GDAL::UnsupportedOperation or OGR::UnsupportedGeometryType' do
179
+ expect do
180
+ subject.polygon_from_edges(100, auto_close: false)
181
+ end.to raise_exception
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+ require 'ogr/geometry'
3
+
4
+ RSpec.describe OGR::LineString do
5
+ let(:open_line_string) do
6
+ g = described_class.new
7
+ g.add_point(0, 0)
8
+ g.add_point(0, 10)
9
+ g.add_point(10, 10)
10
+
11
+ g
12
+ end
13
+
14
+ let(:closed_line_string) do
15
+ g = described_class.new
16
+ g.add_point(0, 0)
17
+ g.add_point(0, 10)
18
+ g.add_point(10, 10)
19
+ g.add_point(10, 0)
20
+ g.add_point(0, 0)
21
+
22
+ g
23
+ end
24
+
25
+ it_behaves_like 'a geometry' do
26
+ let(:geometry) { open_line_string }
27
+ end
28
+
29
+ it_behaves_like 'a line string' do
30
+ let(:geometry) { open_line_string }
31
+ end
32
+
33
+ describe '#closed' do
34
+ context 'geometry is closed' do
35
+ subject { closed_line_string }
36
+ it { is_expected.to be_closed }
37
+ end
38
+
39
+ context 'geometry is not closed' do
40
+ subject { open_line_string }
41
+ it { is_expected.to_not be_closed }
42
+ end
43
+ end
44
+
45
+ describe '#name' do
46
+ subject { open_line_string.name }
47
+ it { is_expected.to eq 'LINESTRING' }
48
+ end
49
+
50
+ describe '#point_count' do
51
+ subject { open_line_string.point_count }
52
+ it { is_expected.to eq 3 }
53
+ end
54
+
55
+ describe '#intersects?' do
56
+ context 'other geometry is a point' do
57
+ context 'inside the ring' do
58
+ let(:other_geometry) do
59
+ OGR::Geometry.create_from_wkt('POINT (0 1)')
60
+ end
61
+
62
+ subject { open_line_string.intersects?(other_geometry) }
63
+ it { is_expected.to eq true }
64
+ end
65
+
66
+ context 'on a vertex of the ring' do
67
+ let(:other_geometry) do
68
+ OGR::Geometry.create_from_wkt('POINT (0 0)')
69
+ end
70
+
71
+ subject { open_line_string.intersects?(other_geometry) }
72
+ it { is_expected.to eq true }
73
+ end
74
+ end
75
+
76
+ context 'other geometry is a line string' do
77
+ context 'outside the ring' do
78
+ let(:other_geometry) do
79
+ OGR::Geometry.create_from_wkt('LINESTRING (100 100, 200 200)')
80
+ end
81
+
82
+ subject { open_line_string.intersects?(other_geometry) }
83
+ it { is_expected.to eq false }
84
+ end
85
+
86
+ context 'ends on a vertex' do
87
+ let(:other_geometry) do
88
+ OGR::Geometry.create_from_wkt('LINESTRING (50 50, 0 0)')
89
+ end
90
+
91
+ subject { open_line_string.intersects?(other_geometry) }
92
+ it { is_expected.to eq true }
93
+ end
94
+
95
+ context 'passes across the boundary' do
96
+ let(:other_geometry) do
97
+ OGR::Geometry.create_from_wkt('LINESTRING (15 5, 5 5)')
98
+ end
99
+
100
+ subject { open_line_string.intersects?(other_geometry) }
101
+ it { is_expected.to eq false }
102
+ end
103
+ end
104
+ end
105
+ end
@@ -1,8 +1,9 @@
1
1
  require 'spec_helper'
2
+ require 'ogr/geometry'
2
3
 
3
- describe OGR::LinearRing do
4
+ RSpec.describe OGR::LinearRing do
4
5
  let(:linear_ring) do
5
- g = OGR::Geometry.create(:wkbLinearRing)
6
+ g = described_class.new
6
7
  g.add_point(0, 0)
7
8
  g.add_point(0, 10)
8
9
  g.add_point(10, 10)
@@ -12,35 +13,18 @@ describe OGR::LinearRing do
12
13
  g
13
14
  end
14
15
 
15
- subject { linear_ring }
16
-
17
- describe '#closed' do
18
- it { is_expected.to be_closed }
19
- end
20
-
21
- describe '#dimension' do
22
- subject { linear_ring.dimension }
23
- it { is_expected.to eq 1 }
24
- end
25
-
26
- describe '#coordinate_dimension' do
27
- subject { linear_ring.coordinate_dimension }
28
- it { is_expected.to eq 2 }
16
+ it_behaves_like 'a geometry' do
17
+ let(:geometry) { linear_ring }
29
18
  end
30
19
 
31
- describe '#envelope' do
32
- subject { linear_ring.envelope }
33
- it { is_expected.to be_a OGR::Envelope }
20
+ it_behaves_like 'a line string' do
21
+ let(:geometry) { linear_ring }
34
22
  end
35
23
 
36
- describe '#type' do
37
- subject { linear_ring.type }
38
- it { is_expected.to eq :wkbLineString }
39
- end
24
+ subject { linear_ring }
40
25
 
41
- describe '#type_to_name' do
42
- subject { linear_ring.type }
43
- it { is_expected.to eq :wkbLineString }
26
+ describe '#closed' do
27
+ it { is_expected.to be_closed }
44
28
  end
45
29
 
46
30
  describe '#name' do
@@ -48,11 +32,6 @@ describe OGR::LinearRing do
48
32
  it { is_expected.to eq 'LINEARRING' }
49
33
  end
50
34
 
51
- describe '#count' do
52
- subject { linear_ring.count }
53
- it { is_expected.to be_zero }
54
- end
55
-
56
35
  describe '#point_count' do
57
36
  subject { linear_ring.point_count }
58
37
  it { is_expected.to eq 5 }
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'ogr/geometry'
3
+
4
+ RSpec.describe OGR::MultiLineString do
5
+ it_behaves_like 'a geometry' do
6
+ let(:geometry) { described_class.new }
7
+ end
8
+
9
+ it_behaves_like 'a container geometry' do
10
+ let(:child_geometry) do
11
+ OGR::LineString.new
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'ogr/geometry'
3
+
4
+ RSpec.describe OGR::MultiPoint do
5
+ it_behaves_like 'a geometry' do
6
+ let(:geometry) { described_class.new }
7
+ end
8
+
9
+ it_behaves_like 'a container geometry' do
10
+ let(:child_geometry) { OGR::Point.new }
11
+ let(:edge_geometry1) { OGR::Point.new }
12
+ let(:edge_geometry2) { OGR::Point.new }
13
+ end
14
+ end