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,143 @@
1
+ require_relative '../field_definition'
2
+ require_relative '../field'
3
+ require_relative '../geometry_field_definition'
4
+
5
+ module OGR
6
+ module LayerMixins
7
+ module OGRFieldMethods
8
+ # Creates and writes a new field to the layer. This adds the field to the
9
+ # internal FeatureDefinition; C API says not to update the FeatureDefinition
10
+ # directly.
11
+ #
12
+ # @param field_definition [OGR::FieldDefinition]
13
+ # @param approx_ok [Boolean] If +true+ the field may be created in a slightly
14
+ # different form, depending on the limitations of the format driver.
15
+ # @return [Boolean]
16
+ def create_field(field_definition, approx_ok = false)
17
+ unless can_create_field?
18
+ fail OGR::UnsupportedOperation, 'This layer does not support field creation.'
19
+ end
20
+
21
+ field_definition_ptr = GDAL._pointer(OGR::FieldDefinition, field_definition)
22
+ ogr_err = FFI::OGR::API.OGR_L_CreateField(@c_pointer, field_definition_ptr, approx_ok)
23
+
24
+ ogr_err.handle_result
25
+ end
26
+
27
+ # Deletes the field definition from the layer.
28
+ #
29
+ # @return +true+ if successful, otherwise raises an OGR exception.
30
+ def delete_field(field_id)
31
+ unless can_delete_field?
32
+ fail OGR::UnsupportedOperation, 'This driver does not support field deletion.'
33
+ end
34
+
35
+ ogr_err = FFI::OGR::API.OGR_L_DeleteField(@c_pointer, field_id)
36
+
37
+ ogr_err.handle_result
38
+ end
39
+
40
+ # @param new_order [Array<Fixnum>] An array that orders field indexes by
41
+ # which they should be reordered. I.e. [0, 2, 3, 1, 4].
42
+ # @return [Boolean]
43
+ def reorder_fields(*new_order)
44
+ unless can_reorder_fields?
45
+ fail OGR::UnsupportedOperation, 'This driver does not support field reordering.'
46
+ end
47
+
48
+ return false if new_order.empty?
49
+ return false if new_order.any? { |i| i > feature_definition.field_count }
50
+
51
+ map_array_ptr = FFI::MemoryPointer.new(:int, new_order.size).write_array_of_int(new_order)
52
+ ogr_err = FFI::OGR::API.OGR_L_ReorderFields(@c_pointer, map_array_ptr)
53
+
54
+ ogr_err.handle_result
55
+ end
56
+
57
+ # Puts the field whose index is +old_position+ into index at +new_position+
58
+ # and shuffles the other indexes accordingly.
59
+ #
60
+ # @param old_position [Fixnum]
61
+ # @param new_position [Fixnum]
62
+ def reorder_field(old_position, new_position)
63
+ unless can_reorder_fields?
64
+ fail OGR::UnsupportedOperation, 'This driver does not support field reordering.'
65
+ end
66
+
67
+ ogr_err = FFI::OGR::API.OGR_L_ReorderField(@c_pointer, old_position, new_position)
68
+
69
+ ogr_err.handle_result
70
+ end
71
+
72
+ # @param field_index [Fixnum]
73
+ # @param new_field_definition [OGR::FieldDefinition] The definition for
74
+ # which to base the Field at +field_index+ off of.
75
+ # @param flags [Fixnum] ALTER_NAME_FLAG, ALTER_TYPE_FLAG,
76
+ # ALTER_WIDTH_PRECISION_FLAG, or ALTER_ALL_FLAG.
77
+ def alter_field_definition(field_index, new_field_definition, flags)
78
+ unless can_alter_field_definition?
79
+ fail OGR::UnsupportedOperation, 'This layer does not support field definition altering.'
80
+ end
81
+
82
+ new_field_definition_ptr = GDAL._pointer(OGR::FieldDefinition, new_field_definition)
83
+
84
+ ogr_err = FFI::OGR::API.OGR_L_AlterFieldDefn(
85
+ @c_pointer,
86
+ field_index,
87
+ new_field_definition_ptr,
88
+ flags)
89
+
90
+ ogr_err.handle_result
91
+ end
92
+
93
+ # Finds the index of a field in this Layer.
94
+ #
95
+ # @param field_name [String]
96
+ # @param exact_match [Boolean] If +false+ and the field doesn't exist in the
97
+ # given form, the driver will try to make changes to make a match.
98
+ # @return [Fixnum] Index of the field or +nil+ if the field doesn't exist.
99
+ def find_field_index(field_name, exact_match = true)
100
+ result = FFI::OGR::API.OGR_L_FindFieldIndex(@c_pointer, field_name, exact_match)
101
+
102
+ result < 0 ? nil : result
103
+ end
104
+
105
+ # Creates and writes a new geometry to the layer. Note: not all drivers
106
+ # support this.
107
+ #
108
+ # @param geometry_field_def [OGR::GeometryFieldDefinition] The definition
109
+ # to use for creating the new field.
110
+ # @param approx_ok [Boolean]
111
+ # @return [Boolean]
112
+ def create_geometry_field(geometry_field_def, approx_ok = false)
113
+ unless can_create_geometry_field?
114
+ fail OGR::UnsupportedOperation, 'This layer does not support geometry field creation'
115
+ end
116
+
117
+ geometry_field_definition_ptr = GDAL._pointer(OGR::GeometryFieldDefinition, geometry_field_def)
118
+
119
+ ogr_err = FFI::OGR::API.OGR_L_CreateGeomField(
120
+ @c_pointer,
121
+ geometry_field_definition_ptr,
122
+ approx_ok)
123
+
124
+ ogr_err.handle_result
125
+ end
126
+
127
+ # If the driver supports this functionality, it will not fetch the
128
+ # specified fields in subsequent calls to #feature / #next_feature and
129
+ # thus save some processing time and/or bandwidth.
130
+ #
131
+ # @param field_names [Array<String>]
132
+ # @return [Boolean]
133
+ def set_ignored_fields(*field_names)
134
+ return false if field_names.empty?
135
+
136
+ fields_ptr = GDAL._string_array_to_pointer(field_names)
137
+ ogr_err = FFI::OGR::API.OGR_L_SetIgnoredFields(@c_pointer, fields_ptr)
138
+
139
+ ogr_err.handle_result "Unable to ignore fields with names: #{field_names}"
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,163 @@
1
+ module OGR
2
+ module LayerMixins
3
+ # OGR::Layer methods: Ruby methods that operate on a OGR::Layer using a
4
+ # "method layer". The method layer is combined with the current layer in some
5
+ # fashion, which results in a new OGR::Layer.
6
+ module OGRLayerMethodMethods
7
+ # Clip off areas of this layer that are not covered by the method layer. The
8
+ # result layer contains features whose geometries represent areas that are
9
+ # in the input layer and in the method layer. The features in the result
10
+ # layer have the (possibly clipped) areas of features in the input layer and
11
+ # the attributes from the same features.
12
+ #
13
+ # @param method_layer [OGR::Layer]
14
+ # @param options [Hash]
15
+ # @option options [:yes, :no] skip_failures (:no) Setting to :yes lets
16
+ # the function continue even when a feature could not be inserted.
17
+ # @option options [:yes, :no] promote_to_multi (:no) Setting to :yes
18
+ # converts Polygons to MultiPolygons, LineStrings to MultiLineStrings.
19
+ # @option options [String] input_prefix Set a prefix for the field names
20
+ # that will be created from the fields of the input Layer.
21
+ # @option options [String] method_prefix Set a prefix for the field names
22
+ # that will be created from the fields of the method Layer.
23
+ def clip(method_layer, **options, &progress)
24
+ run_layer_method(:OGR_L_Clip, method_layer, **options, &progress)
25
+ end
26
+
27
+ # Remove areas in this layer that are covered by the method layer.
28
+ #
29
+ # The result layer contains features whose geometries represent areas that
30
+ # are in this layer but not in the method layer. The features in the result
31
+ # layer have attributes from this layer.
32
+ #
33
+ # @param method_layer [OGR::Layer]
34
+ # @param options [Hash]
35
+ # @option options [:yes, :no] skip_failures (:no) Setting to :yes lets
36
+ # the function continue even when a feature could not be inserted.
37
+ # @option options [:yes, :no] promote_to_multi (:no) Setting to :yes
38
+ # converts Polygons to MultiPolygons, LineStrings to MultiLineStrings.
39
+ # @option options [String] input_prefix Set a prefix for the field names
40
+ # that will be created from the fields of the input Layer.
41
+ # @option options [String] method_prefix Set a prefix for the field names
42
+ # that will be created from the fields of the method Layer.
43
+ def erase(method_layer, **options, &progress)
44
+ run_layer_method(:OGR_L_Erase, method_layer, **options, &progress)
45
+ end
46
+
47
+ # The result layer contains features whose geometries represent areas that
48
+ # are in the input layer. The features in the result layer have attributes
49
+ # from both input and method layers.
50
+ #
51
+ # @param method_layer [OGR::Layer]
52
+ # @param options [Hash]
53
+ # @option options [:yes, :no] skip_failures (:no) Setting to :yes lets
54
+ # the function continue even when a feature could not be inserted.
55
+ # @option options [:yes, :no] promote_to_multi (:no) Setting to :yes
56
+ # converts Polygons to MultiPolygons, LineStrings to MultiLineStrings.
57
+ # @option options [String] input_prefix Set a prefix for the field names
58
+ # that will be created from the fields of the input Layer.
59
+ # @option options [String] method_prefix Set a prefix for the field names
60
+ # that will be created from the fields of the method Layer.
61
+ def identity(method_layer, **options, &progress)
62
+ run_layer_method(:OGR_L_Identity, method_layer, **options, &progress)
63
+ end
64
+
65
+ # Intersection of this layer and +method_layer+.
66
+ #
67
+ # @param method_layer [OGR::Layer]
68
+ # @param options [Hash]
69
+ # @option options [:yes, :no] skip_failures (:no) Setting to :yes lets
70
+ # the function continue even when a feature could not be inserted.
71
+ # @option options [:yes, :no] promote_to_multi (:no) Setting to :yes
72
+ # converts Polygons to MultiPolygons, LineStrings to MultiLineStrings.
73
+ # @option options [String] input_prefix Set a prefix for the field names
74
+ # that will be created from the fields of the input Layer.
75
+ # @option options [String] method_prefix Set a prefix for the field names
76
+ # that will be created from the fields of the method Layer.
77
+ def intersection(method_layer, **options, &progress)
78
+ run_layer_method(:OGR_L_Intersection, method_layer, **options, &progress)
79
+ end
80
+
81
+ # The result layer contains features whose geometries represent areas that
82
+ # are either in this layer or the method layer, but not in both. The
83
+ # features in the result layer have attributes from both this layer and
84
+ # the method layer. For features which represent areas that are only in
85
+ # this layer or the method layer, the respective attributes have undefined
86
+ # values.
87
+ #
88
+ # @param method_layer [OGR::Layer]
89
+ # @param options [Hash]
90
+ # @option options [:yes, :no] skip_failures (:no) Setting to :yes lets
91
+ # the function continue even when a feature could not be inserted.
92
+ # @option options [:yes, :no] promote_to_multi (:no) Setting to :yes
93
+ # converts Polygons to MultiPolygons, LineStrings to MultiLineStrings.
94
+ # @option options [String] input_prefix Set a prefix for the field names
95
+ # that will be created from the fields of the input Layer.
96
+ # @option options [String] method_prefix Set a prefix for the field names
97
+ # that will be created from the fields of the method Layer.
98
+ def symmetrical_difference(method_layer, **options, &progress)
99
+ run_layer_method(:OGR_L_SymDifference, method_layer, **options, &progress)
100
+ end
101
+
102
+ # The result layer contains features whose geometries represent areas that
103
+ # are either in this layer or the method layer. The features in the result
104
+ # layer have attributes from both this layer and the method layer. For
105
+ # features which represent areas that are only in this or in the method
106
+ # layer, the respective attributes have undefined values.
107
+ #
108
+ # @param method_layer [OGR::Layer]
109
+ # @param options [Hash]
110
+ # @option options [:yes, :no] skip_failures (:no) Setting to :yes lets
111
+ # the function continue even when a feature could not be inserted.
112
+ # @option options [:yes, :no] promote_to_multi (:no) Setting to :yes
113
+ # converts Polygons to MultiPolygons, LineStrings to MultiLineStrings.
114
+ # @option options [String] input_prefix Set a prefix for the field names
115
+ # that will be created from the fields of the input Layer.
116
+ # @option options [String] method_prefix Set a prefix for the field names
117
+ # that will be created from the fields of the method Layer.
118
+ def union(method_layer, **options, &progress)
119
+ run_layer_method(:OGR_L_Union, method_layer, **options, &progress)
120
+ end
121
+
122
+ # Update this layer with features from the update layer. The result layer
123
+ # contains features whose geometries represent areas that are either in this
124
+ # layer or the method layer. The features in the result layer have areas
125
+ # of the features of the method layer or those areas of the features of this
126
+ # layer that are not covered by the method layer. The features of the result
127
+ # layer get their attributes from this layer.
128
+ #
129
+ # @param method_layer [OGR::Layer]
130
+ # @param options [Hash]
131
+ # @option options [:yes, :no] skip_failures (:no) Setting to :yes lets
132
+ # the function continue even when a feature could not be inserted.
133
+ # @option options [:yes, :no] promote_to_multi (:no) Setting to :yes
134
+ # converts Polygons to MultiPolygons, LineStrings to MultiLineStrings.
135
+ # @option options [String] input_prefix Set a prefix for the field names
136
+ # that will be created from the fields of the input Layer.
137
+ # @option options [String] method_prefix Set a prefix for the field names
138
+ # that will be created from the fields of the method Layer.
139
+ def update(method_layer, **options, &progress)
140
+ run_layer_method(:OGR_L_Update, method_layer, **options, &progress)
141
+ end
142
+
143
+ private
144
+
145
+ def run_layer_method(method_name, method_layer, **options, &progress)
146
+ method_layer_ptr = GDAL._pointer(OGR::Layer, method_layer)
147
+ options_ptr = GDAL::Options.pointer(options)
148
+ result_layer_ptr = FFI::MemoryPointer.new(:OGRLayerH)
149
+
150
+ ogr_err = FFI::GDAL.send(method_name,
151
+ @c_pointer,
152
+ method_layer_ptr,
153
+ result_layer_ptr,
154
+ options_ptr,
155
+ progress,
156
+ nil)
157
+ ogr_err.handle_result
158
+
159
+ OGR::Layer.new(result_layer_ptr)
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,89 @@
1
+ require_relative '../geometry'
2
+
3
+ module OGR
4
+ module LayerMixins
5
+ module OGRQueryFilterMethods
6
+ # TODO: per the GDAL docs: "The returned pointer is to an internally owned
7
+ # object, and should not be altered or deleted by the caller."
8
+ #
9
+ # @return [OGR::Geometry]
10
+ def spatial_filter
11
+ filter_pointer = FFI::OGR::API.OGR_L_GetSpatialFilter(@c_pointer)
12
+ return nil if filter_pointer.null?
13
+
14
+ OGR::Geometry.factory(filter_pointer)
15
+ end
16
+
17
+ # @param new_spatial_filter [OGR::Geometry, FFI::Pointer]
18
+ def spatial_filter=(new_spatial_filter)
19
+ spatial_filter_ptr = GDAL._pointer(OGR::Geometry, new_spatial_filter)
20
+
21
+ FFI::OGR::API.OGR_L_SetSpatialFilter(@c_pointer, spatial_filter_ptr)
22
+ end
23
+
24
+ # Only feature which intersect the filter geometry will be returned.
25
+ #
26
+ # @param geometry_field_index [Fixnum] The spatial filter operates on this
27
+ # geometry field.
28
+ # @param geometry [OGR::Geometry] Use this geometry as the filtering
29
+ # region.
30
+ def set_spatial_filter_ex(geometry_field_index, geometry)
31
+ geometry_ptr = GDAL._pointer(OGR::Geometry, geometry)
32
+
33
+ FFI::OGR::API.OGR_L_SetSpatialFilterEx(
34
+ @c_pointer, geometry_field_index, geometry_ptr)
35
+ end
36
+
37
+ # Only features that geometrically intersect the given rectangle will be
38
+ # returned. X/Y values should be in the same coordinate system as the
39
+ # layer as a whole (different from #set_spatial_filter_rectangle_ex). To
40
+ # clear the filter, set #spatial_filter = nil.
41
+ #
42
+ # @param min_x [Float]
43
+ # @param min_y [Float]
44
+ # @param max_x [Float]
45
+ # @param max_y [Float]
46
+ def set_spatial_filter_rectangle(min_x, min_y, max_x, max_y)
47
+ FFI::OGR::API.OGR_L_SetSpatialFilterRect(
48
+ @c_pointer,
49
+ min_x,
50
+ min_y,
51
+ max_x,
52
+ max_y)
53
+ end
54
+
55
+ # Only features that geometrically intersect the given rectangle will be
56
+ # returned. X/Y values should be in the same coordinate system as the
57
+ # layer as the given GeometryFieldDefinition at the given index (different
58
+ # from #set_spatial_filter_rectangle). To clear the filter, set
59
+ # #spatial_filter = nil.
60
+ #
61
+ # @param geometry_field_index [Fixnum]
62
+ # @param min_x [Float]
63
+ # @param min_y [Float]
64
+ # @param max_x [Float]
65
+ # @param max_y [Float]
66
+ def set_spatial_filter_rectangle_ex(geometry_field_index, min_x, min_y, max_x, max_y)
67
+ FFI::OGR::API.OGR_L_SetSpatialFilterRectEx(
68
+ @c_pointer,
69
+ geometry_field_index,
70
+ min_x,
71
+ min_y,
72
+ max_x,
73
+ max_y)
74
+ end
75
+
76
+ # Sets the attribute query string to be used when fetching Features using
77
+ # #next_feature. Should be in the form of an `SQL WHERE` clause. Note
78
+ # that this will generally result in resetting the current reading position.
79
+ #
80
+ # @param query [String]
81
+ # @see http://ogdi.sourceforge.net/prop/6.2.CapabilitiesMetadata.html
82
+ def set_attribute_filter(query)
83
+ ogr_err = FFI::OGR::API.OGR_L_SetAttributeFilter(@c_pointer, query)
84
+
85
+ ogr_err.handle_result
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,48 @@
1
+ module OGR
2
+ module LayerMixins
3
+ module OGRSQLMethods
4
+ # @return [Boolean]
5
+ def start_transaction
6
+ transact { FFI::OGR::API.OGR_L_StartTransaction(@c_pointer) }
7
+ end
8
+
9
+ # @return [Boolean]
10
+ def commit_transaction
11
+ transact { FFI::OGR::API.OGR_L_CommitTransaction(@c_pointer) }
12
+ end
13
+
14
+ # @return [Boolean]
15
+ def rollback_transaction
16
+ transact { FFI::OGR::API.OGR_L_RollbackTransaction(@c_pointer) }
17
+ end
18
+
19
+ # The name of the underlying database column or "" if not supported.
20
+ #
21
+ # @return [String]
22
+ def fid_column
23
+ FFI::OGR::API.OGR_L_GetFIDColumn(@c_pointer)
24
+ end
25
+
26
+ # The name of the underlying database column being used as the geometry
27
+ # column. Returns "" if not supported.
28
+ #
29
+ # @return [String]
30
+ def geometry_column
31
+ FFI::OGR::API.OGR_L_GetGeometryColumn(@c_pointer)
32
+ end
33
+
34
+ private
35
+
36
+ # @return [Boolean]
37
+ def transact
38
+ unless supports_transactions?
39
+ fail OGR::UnsupportedOperation, 'This layer does not support transactions.'
40
+ end
41
+
42
+ ogr_err = yield
43
+
44
+ ogr_err.handle_result
45
+ end
46
+ end
47
+ end
48
+ end