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
@@ -1,97 +1,96 @@
1
1
  require 'spec_helper'
2
+ require 'ogr/layer'
2
3
 
3
- describe OGR::Layer do
4
- let(:data_source) do
5
- OGR::DataSource.open('spec/support/shapefiles/states_21basic/states.shp', 'r')
6
- end
7
-
8
- let(:layer0) do
9
- data_source.layer(0)
10
- end
11
-
12
- subject do
13
- layer0
14
- end
4
+ RSpec.describe OGR::Layer do
5
+ include_context 'OGR::Layer, spatial_reference'
15
6
 
16
7
  describe '#name' do
17
- subject { layer0.name }
18
- it { is_expected.to eq 'states' }
8
+ it 'returns the name given to it' do
9
+ expect(subject.name).to eq 'spec layer'
10
+ end
19
11
  end
20
12
 
21
13
  describe '#geometry_type' do
22
- subject { layer0.geometry_type }
23
- it { is_expected.to eq :wkbPolygon }
14
+ it 'returns the type it was created with' do
15
+ expect(subject.geometry_type).to eq :wkbMultiPoint
16
+ end
24
17
  end
25
18
 
26
- describe '#feature_count' do
27
- subject { layer0.feature_count }
28
- it { is_expected.to eq 51 }
19
+ describe '#sync_to_disk' do
20
+ it 'does not die' do
21
+ expect { subject.sync_to_disk }.to_not raise_exception
22
+ end
29
23
  end
30
24
 
31
- describe '#feature' do
32
- subject { layer0.feature(0) }
33
- it { is_expected.to be_a OGR::Feature }
34
- end
25
+ describe '#test_capability' do
26
+ context 'some supported capabilities to check' do
27
+ let(:capabilities) do
28
+ %w[OLCRandomRead OLCCreateField OLCCurveGeometries]
29
+ end
35
30
 
36
- describe '#next_feature' do
37
- subject { layer0.next_feature }
38
- it { is_expected.to be_a OGR::Feature }
39
- end
31
+ # I don't get why these return false...
32
+ it 'returns false' do
33
+ capabilities.each do |capability|
34
+ expect(subject.test_capability(capability)).to eq false
35
+ end
36
+ end
37
+ end
40
38
 
41
- describe '#features_read' do
42
- subject { layer0.features_read }
43
- it { is_expected.to be >= 0 }
39
+ context 'unsupported capabilities to check' do
40
+ it 'returns false' do
41
+ expect(subject.test_capability('meow')).to eq false
42
+ end
43
+ end
44
44
  end
45
45
 
46
- describe '#features' do
47
- subject { layer0.features }
48
- it { is_expected.to be_an Array }
49
- specify { expect(subject.first).to be_a OGR::Feature }
50
- specify { expect(subject.size).to eq layer0.feature_count }
51
- end
46
+ describe '#spatial_reference' do
47
+ context 'no spatial ref' do
48
+ include_context 'OGR::Layer, no spatial_reference'
52
49
 
53
- describe '#feature_definition' do
54
- subject { layer0.feature_definition }
55
- it { is_expected.to be_a OGR::FeatureDefinition }
56
- end
50
+ it 'returns nil' do
51
+ expect(subject.spatial_reference).to be_nil
52
+ end
53
+ end
57
54
 
58
- describe '#spatial_reference' do
59
- subject { layer0.spatial_reference }
60
- it { is_expected.to be_a OGR::SpatialReference }
55
+ context 'with a spatial ref' do
56
+ it 'returns an OGR::SpatialReference' do
57
+ expect(subject.spatial_reference).to be_a OGR::SpatialReference
58
+ end
59
+ end
61
60
  end
62
61
 
63
62
  describe '#extent' do
64
- subject { layer0.extent }
65
- it { is_expected.to be_a OGR::Envelope }
66
- end
67
-
68
- describe '#fid_column' do
69
- subject { layer0.fid_column }
70
- it { is_expected.to be_a String }
71
- it { is_expected.to be_empty }
63
+ it 'returns an OGR::Envelope' do
64
+ expect(subject.extent).to be_a OGR::Envelope
65
+ end
72
66
  end
73
67
 
74
- describe '#geometry_column' do
75
- subject { layer0.geometry_column }
76
- it { is_expected.to be_a String }
77
- it { is_expected.to be_empty }
78
- end
68
+ describe '#extent_by_geometry' do
69
+ context 'force is false' do
70
+ it 'returns an OGR::Envelope' do
71
+ expect(subject.extent_by_geometry(0, false)).to be_a OGR::Envelope
72
+ end
73
+ end
79
74
 
80
- describe '#style_table' do
81
- subject { layer0.style_table }
82
- it { is_expected.to be_nil }
75
+ context 'force is true' do
76
+ it 'returns an OGR::Envelope' do
77
+ expect(subject.extent_by_geometry(0, true)).to be_a OGR::Envelope
78
+ end
79
+ end
83
80
  end
84
81
 
85
- describe '#geometry_from_extent' do
86
- it 'is a Polygon' do
87
- geometry = subject.geometry_from_extent
88
- expect(geometry).to be_a OGR::Polygon
82
+ describe '#style_table= + #style_table' do
83
+ context 'one is not set' do
84
+ it 'returns nil' do
85
+ expect(subject.style_table).to be_nil
86
+ end
89
87
  end
90
- end
91
88
 
92
- describe '#as_json' do
93
- specify do
94
- expect { subject.as_json }.to_not raise_exception
89
+ context 'one is set' do
90
+ it 'returns an OGR::StyleTable' do
91
+ subject.style_table = OGR::StyleTable.new
92
+ expect(subject.style_table).to be_a OGR::StyleTable
93
+ end
95
94
  end
96
95
  end
97
96
  end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'ogr/spatial_reference'
3
+
4
+ RSpec.describe OGR::SpatialReference do
5
+ describe '#set_local_cs' do
6
+ it 'sets the LOCAL_CS' do
7
+ expect do
8
+ subject.set_local_cs('darrel')
9
+ end.to change { subject.to_wkt }.from('').to('LOCAL_CS["darrel"]')
10
+ end
11
+ end
12
+
13
+ describe '#set_proj_cs' do
14
+ it 'sets the PROJCS' do
15
+ expect do
16
+ subject.set_proj_cs('darrel')
17
+ end.to change { subject.to_wkt }.from('').to('PROJCS["darrel"]')
18
+ end
19
+ end
20
+
21
+ describe '#set_geoc_cs' do
22
+ it 'sets the GEOCCS' do
23
+ expect do
24
+ subject.set_geoc_cs('darrel')
25
+ end.to change { subject.to_wkt }.from('').to('GEOCCS["darrel"]')
26
+ end
27
+ end
28
+
29
+ describe '#set_from_user_input' do
30
+ context 'valid input' do
31
+ it 'sets the GEOCCS' do
32
+ expect do
33
+ subject.set_from_user_input('GEOCCS["darrel"]')
34
+ end.to change { subject.to_wkt }.from('').to('GEOCCS["darrel"]')
35
+ end
36
+ end
37
+
38
+ context 'invalid input' do
39
+ it 'sets the GEOCCS' do
40
+ expect do
41
+ subject.set_from_user_input('darrel')
42
+ end.to raise_exception OGR::CorruptData
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+ require 'ogr/spatial_reference'
3
+
4
+ RSpec.describe OGR::SpatialReference do
5
+ describe '#to_erm' do
6
+ context 'known projection' do
7
+ subject { described_class.new_from_epsg(4322) }
8
+
9
+ it 'returns a Hash' do
10
+ expect(subject.to_erm).to eq(projection_name: 'GEODETIC', datum_name: 'WGS72DOD', units: 'METERS')
11
+ end
12
+ end
13
+
14
+ context 'empty SRS' do
15
+ it 'raises an OGR::NotEnoughData' do
16
+ expect { subject.to_erm }.to raise_exception OGR::NotEnoughData
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#to_mapinfo' do
22
+ context 'known projection' do
23
+ subject { described_class.new_from_epsg(4322) }
24
+
25
+ it 'returns a populated array' do
26
+ pending 'Understanding how to make it work'
27
+ expect(subject.to_mapinfo).to be_an Array
28
+ expect(subject.to_mapinfo).to_not be_empty
29
+ end
30
+ end
31
+
32
+ context 'empty SRS' do
33
+ it 'raises an OGR::NotEnoughData' do
34
+ pending 'Understanding how to make it work'
35
+
36
+ expect { subject.to_mapinfo }.to raise_exception OGR::NotEnoughData
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '#to_pci' do
42
+ context 'known projection' do
43
+ subject { described_class.new_from_epsg(4322) }
44
+
45
+ it 'returns a Hash' do
46
+ expect(subject.to_pci).to eq(
47
+ projection: 'LONG/LAT D001',
48
+ units: 'DEGREE',
49
+ projection_parameters: [])
50
+ end
51
+ end
52
+
53
+ context 'empty SRS' do
54
+ it 'returns default values' do
55
+ expect(subject.to_pci).to eq(
56
+ projection: 'LONG/LAT E012',
57
+ units: 'DEGREE',
58
+ projection_parameters: [])
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '#to_proj4' do
64
+ context 'known projection' do
65
+ subject { described_class.new_from_epsg(4322) }
66
+
67
+ it 'returns a PROJ4 String' do
68
+ expect(subject.to_proj4).to eq('+proj=longlat +ellps=WGS72 +towgs84=0,0,4.5,0,0,0.554,0.2263 +no_defs ')
69
+ end
70
+ end
71
+
72
+ context 'empty SRS' do
73
+ it 'raises a GDAL::UnsupportedOperation' do
74
+ expect { subject.to_proj4 }.to raise_exception GDAL::UnsupportedOperation
75
+ end
76
+ end
77
+ end
78
+
79
+ describe '#to_wkt' do
80
+ context 'known projection' do
81
+ subject { described_class.new_from_epsg(4322) }
82
+
83
+ it 'returns a well-known text String' do
84
+ expect(subject.to_wkt).to eq('GEOGCS["WGS 72",DATUM["WGS_1972",SPHEROID["WGS 72",6378135,298.26,AUTHORITY["EPSG","7043"]],TOWGS84[0,0,4.5,0,0,0.554,0.2263],AUTHORITY["EPSG","6322"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4322"]]')
85
+ end
86
+ end
87
+
88
+ context 'empty SRS' do
89
+ it 'returns an empty String' do
90
+ expect(subject.to_wkt).to eq ''
91
+ end
92
+ end
93
+ end
94
+
95
+ describe '#to_pretty_wkt' do
96
+ context 'known projection' do
97
+ subject { described_class.new_from_epsg(4322) }
98
+
99
+ it 'returns a well-known text String' do
100
+ expect(subject.to_pretty_wkt).to eq <<-WKT.strip
101
+ GEOGCS["WGS 72",
102
+ DATUM["WGS_1972",
103
+ SPHEROID["WGS 72",6378135,298.26,
104
+ AUTHORITY["EPSG","7043"]],
105
+ TOWGS84[0,0,4.5,0,0,0.554,0.2263],
106
+ AUTHORITY["EPSG","6322"]],
107
+ PRIMEM["Greenwich",0,
108
+ AUTHORITY["EPSG","8901"]],
109
+ UNIT["degree",0.0174532925199433,
110
+ AUTHORITY["EPSG","9122"]],
111
+ AUTHORITY["EPSG","4322"]]
112
+ WKT
113
+ end
114
+ end
115
+
116
+ context 'empty SRS' do
117
+ it 'returns an empty String' do
118
+ expect(subject.to_pretty_wkt).to eq ''
119
+ end
120
+ end
121
+ end
122
+
123
+ describe '#to_xml' do
124
+ context 'known projection' do
125
+ subject { described_class.new_from_epsg(4322) }
126
+
127
+ it 'returns an XML string' do
128
+ pending 'Understanding how to make it work'
129
+ expect(subject.to_xml).to eq 'something'
130
+ end
131
+ end
132
+
133
+ context 'empty SRS' do
134
+ it 'raises an OGR::UnsupportedSRS' do
135
+ expect { subject.to_xml }.to raise_exception OGR::UnsupportedSRS
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'ogr/spatial_reference'
3
+
4
+ RSpec.describe OGR::SpatialReference do
5
+ describe '#import_from_epsg' do
6
+ context 'valid code' do
7
+ it "updates self's info" do
8
+ expect do
9
+ subject.import_from_epsg(4326)
10
+ end.to change { subject.to_wkt.size }.from(0)
11
+ end
12
+
13
+ it 'does not treat as lat/lon' do
14
+ subject.import_from_epsg(4326)
15
+ expect(subject.epsg_treats_as_lat_long?).to eq false
16
+ end
17
+ end
18
+
19
+ context 'invalid code' do
20
+ it 'raises a GDAL::UnsupportedOperation' do
21
+ expect { subject.import_from_epsg 1_231_234 }.to raise_exception GDAL::UnsupportedOperation
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#import_from_epsga' do
27
+ it "updates self's info" do
28
+ expect do
29
+ subject.import_from_epsga(4326)
30
+ end.to change { subject.to_wkt.size }.from(0)
31
+ end
32
+
33
+ it 'treats as lat/lon' do
34
+ subject.import_from_epsga(4326)
35
+ expect(subject.epsg_treats_as_lat_long?).to eq true
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'ogr/spatial_reference'
3
+
4
+ RSpec.describe OGR::SpatialReference do
5
+ describe '#morph_to_esri!' do
6
+ subject { described_class.new_from_epsg 4326 }
7
+
8
+ it 'changes the SRS to ESRI' do
9
+ expect do
10
+ subject.morph_to_esri!
11
+ end.to change { subject.to_wkt.size }
12
+ end
13
+ end
14
+
15
+ describe '#morph_from_esri!' do
16
+ let(:esri) do
17
+ <<-ESRI.strip
18
+ GEOGCS["GCS_North_American_1983",
19
+ DATUM["D_North_American_1983",
20
+ SPHEROID["GRS_1980",6378137,298.257222101]],
21
+ PRIMEM["Greenwich",0],
22
+ UNIT["Degree",0.0174532925199433]]
23
+ ESRI
24
+ end
25
+
26
+ subject { described_class.new_from_esri(esri) }
27
+
28
+ it 'changes the SRS to ESRI' do
29
+ pending 'Figure out why morphing does not change anything'
30
+
31
+ expect do
32
+ subject.morph_from_esri!
33
+ end.to change { subject.to_wkt.size }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+ require 'ogr/spatial_reference'
3
+
4
+ RSpec.describe OGR::SpatialReference do
5
+ # Not sure why yet, but it seems I can only do angular unit setting with
6
+ # certain projections; 4326 is one of them.
7
+ describe '#set_angular_units + #angular_units' do
8
+ subject { OGR::SpatialReference.new_from_epsg(4326) }
9
+
10
+ context 'using a known label and value' do
11
+ it 'sets the new label and value' do
12
+ subject.set_angular_units(OGR::SpatialReference::RADIAN_LABEL, 1.0)
13
+ expect(subject.angular_units).to eq(unit_name: 'radian', value: 1.0)
14
+ end
15
+ end
16
+
17
+ context 'using an unknown label and value' do
18
+ it 'sets the new label and value' do
19
+ subject.set_angular_units('Darrels', 25.6)
20
+ expect(subject.angular_units).to eq(unit_name: 'Darrels', value: 25.6)
21
+ end
22
+ end
23
+ end
24
+
25
+ # Not sure why yet, but it seems I can only do angular unit setting with
26
+ # certain projections; 4326 is one of them.
27
+ describe '#angular_units= + #angular_units' do
28
+ subject { OGR::SpatialReference.new_from_epsg(4326) }
29
+
30
+ context 'using a known label' do
31
+ it 'sets the new label and value' do
32
+ subject.angular_units = :radian
33
+ expect(subject.angular_units).to eq(unit_name: 'radian', value: 1.0)
34
+ end
35
+ end
36
+
37
+ context 'using an unknown label and value' do
38
+ it 'raises a NameError' do
39
+ expect { subject.angular_units = 'Darrels' }.to raise_exception NameError
40
+ end
41
+ end
42
+ end
43
+
44
+ # Not sure why yet, but it seems I can only do linear unit setting with
45
+ # certain projections; 4333 is one of them.
46
+ describe '#set_linear_units + #linear_units' do
47
+ subject { OGR::SpatialReference.new_from_epsg(4333) }
48
+
49
+ context 'using a known label and value' do
50
+ it 'sets the new label and value' do
51
+ subject.set_linear_units(OGR::SpatialReference::FOOT_LABEL, OGR::SpatialReference::METER_TO_FOOT)
52
+ expect(subject.linear_units).to eq(unit_name: 'Foot (International)', value: 0.3048)
53
+ end
54
+ end
55
+
56
+ context 'using an unknown label and value' do
57
+ it 'sets the new label and value' do
58
+ subject.set_linear_units('Darrels', 25.6)
59
+ expect(subject.linear_units).to eq(unit_name: 'Darrels', value: 25.6)
60
+ end
61
+ end
62
+ end
63
+
64
+ # Not sure why yet, but it seems I can only do linear unit setting with
65
+ # certain projections; 4333 is one of them.
66
+ describe '#set_linear_units_and_update_parameters + #linear_units' do
67
+ subject { OGR::SpatialReference.new_from_epsg(4333) }
68
+
69
+ context 'using a known label and value' do
70
+ it 'sets the new label and value' do
71
+ subject.set_linear_units_and_update_parameters(OGR::SpatialReference::FOOT_LABEL, OGR::SpatialReference::METER_TO_FOOT)
72
+ expect(subject.linear_units).to eq(unit_name: 'Foot (International)', value: 0.3048)
73
+ end
74
+ end
75
+
76
+ context 'using an unknown label and value' do
77
+ it 'sets the new label and value' do
78
+ subject.set_linear_units('Darrels', 25.6)
79
+ expect(subject.linear_units).to eq(unit_name: 'Darrels', value: 25.6)
80
+ end
81
+ end
82
+ end
83
+
84
+ # Not sure why yet, but it seems I can only do linear unit setting with
85
+ # certain projections; 4333 is one of them.
86
+ describe '#linear_units= + #linear_units' do
87
+ subject { OGR::SpatialReference.new_from_epsg(4333) }
88
+
89
+ context 'using a known label' do
90
+ it 'sets the new label and value' do
91
+ subject.linear_units = :foot
92
+ expect(subject.linear_units).to eq(unit_name: 'Foot (International)', value: 0.3048)
93
+ end
94
+ end
95
+
96
+ context 'using an unknown label and value' do
97
+ it 'raises a NameError' do
98
+ expect { subject.linear_units = 'Darrels' }.to raise_exception NameError
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,157 @@
1
+ require 'spec_helper'
2
+ require 'ogr/spatial_reference'
3
+
4
+ RSpec.describe OGR::SpatialReference do
5
+ describe '#geographic?' do
6
+ context 'root is a GEOGCS node' do
7
+ subject { described_class.new_from_epsg 4326 }
8
+ it { is_expected.to be_geographic }
9
+ end
10
+
11
+ context 'root is not a GEOGCS node' do
12
+ it { is_expected.to_not be_geographic }
13
+ end
14
+ end
15
+
16
+ describe '#local?' do
17
+ context 'root is a LOCAL_CS node' do
18
+ subject do
19
+ sr = described_class.new
20
+ sr.local_cs = 'bobby'
21
+ sr
22
+ end
23
+
24
+ it { is_expected.to be_local }
25
+ end
26
+
27
+ context 'root is not a LOCAL_CS node' do
28
+ it { is_expected.to_not be_local }
29
+ end
30
+ end
31
+
32
+ describe '#projected?' do
33
+ context 'contains a PROJCS node' do
34
+ subject do
35
+ sr = described_class.new
36
+ sr.proj_cs = 'bobby'
37
+ sr
38
+ end
39
+
40
+ it { is_expected.to be_projected }
41
+ end
42
+
43
+ context 'does not contain a PROJCS node' do
44
+ it { is_expected.to_not be_projected }
45
+ end
46
+ end
47
+
48
+ describe '#compound?' do
49
+ context 'contains a COMPD_CS node' do
50
+ subject do
51
+ sr = described_class.new_from_epsg(4326)
52
+ sr.set_vert_cs('darrel', 'bobby', 2005)
53
+ sr
54
+ end
55
+
56
+ it { is_expected.to be_compound }
57
+ end
58
+
59
+ context 'does not contain a COMPD_CS node' do
60
+ it { is_expected.to_not be_compound }
61
+ end
62
+ end
63
+
64
+ describe '#geocentric?' do
65
+ context 'contains a GEOCCS node' do
66
+ subject do
67
+ sr = described_class.new
68
+ sr.geoc_cs = 'bobby'
69
+ sr
70
+ end
71
+
72
+ it { is_expected.to be_geocentric }
73
+ end
74
+
75
+ context 'does not contain a GEOCCS node' do
76
+ it { is_expected.to_not be_geocentric }
77
+ end
78
+ end
79
+
80
+ describe '#vertical?' do
81
+ context 'contains a VERT_CS node' do
82
+ subject do
83
+ sr = described_class.new
84
+ sr.set_vert_cs('darrel', 'bobby', 2005)
85
+ sr
86
+ end
87
+
88
+ it { is_expected.to be_vertical }
89
+ end
90
+
91
+ context 'does not contain a VERT_CS node' do
92
+ it { is_expected.to_not be_vertical }
93
+ end
94
+ end
95
+
96
+ describe '#same?' do
97
+ context 'SpatialReferences describe the same system' do
98
+ subject { described_class.new_from_epsg(4322) }
99
+ let(:other) { described_class.new_from_epsg(4322) }
100
+ it('returns true') { expect(subject.same?(other)).to eq true }
101
+ end
102
+
103
+ context 'SpatialReferences describe different systems' do
104
+ subject { described_class.new_from_epsg(4322) }
105
+ let(:other) { described_class.new_from_epsg(4326) }
106
+ it('returns false') { expect(subject.same?(other)).to eq false }
107
+ end
108
+ end
109
+
110
+ describe '#geog_cs_is_same?' do
111
+ context 'SpatialReferences describe the same GEOGCS system' do
112
+ subject { described_class.new_from_epsg(4322) }
113
+ let(:other) { described_class.new_from_epsg(4322) }
114
+ it('returns true') { expect(subject.geog_cs_is_same?(other)).to eq true }
115
+ end
116
+
117
+ context 'SpatialReferences describe different systems' do
118
+ subject { described_class.new_from_epsg(4322) }
119
+ let(:other) { described_class.new_from_epsg(4326) }
120
+ it('returns false') { expect(subject.geog_cs_is_same?(other)).to eq false }
121
+ end
122
+ end
123
+
124
+ describe '#vert_cs_is_same?' do
125
+ context 'SpatialReferences describe the same VERT_CS system' do
126
+ subject do
127
+ sr = described_class.new
128
+ sr.set_vert_cs('one', 'things', 2005)
129
+ sr
130
+ end
131
+
132
+ let(:other) do
133
+ sr = described_class.new
134
+ sr.set_vert_cs('one', 'things', 2005)
135
+ sr
136
+ end
137
+
138
+ it('returns true') { expect(subject.vert_cs_is_same?(other)).to eq true }
139
+ end
140
+
141
+ context 'SpatialReferences describe different systems' do
142
+ subject do
143
+ sr = described_class.new
144
+ sr.set_vert_cs('one', 'things', 2005)
145
+ sr
146
+ end
147
+
148
+ let(:other) do
149
+ sr = described_class.new
150
+ sr.set_vert_cs('two', 'other things', 2006)
151
+ sr
152
+ end
153
+
154
+ it('returns false') { expect(subject.vert_cs_is_same?(other)).to eq false }
155
+ end
156
+ end
157
+ end