ffi-gdal 1.0.0.beta16 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (324) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +17 -0
  3. data/.github/workflows/codacy.yml +61 -0
  4. data/.github/workflows/codeql.yml +74 -0
  5. data/.github/workflows/continuous-integration.yml +36 -0
  6. data/.github/workflows/dependency-review.yml +20 -0
  7. data/.github/workflows/specs-in-docker.yml +27 -0
  8. data/.gitignore +3 -0
  9. data/.rspec +1 -0
  10. data/.rubocop.yml +10 -80
  11. data/.rubocop_todo.yml +23 -40
  12. data/.ruby-version +1 -1
  13. data/Changelog-0.x.md +512 -0
  14. data/Changelog.md +12 -0
  15. data/Dockerfile.gdal2 +110 -0
  16. data/Dockerfile.gdal3 +73 -0
  17. data/README.md +25 -14
  18. data/Rakefile +0 -8
  19. data/Tiltfile +91 -0
  20. data/bin/bundle +123 -0
  21. data/bin/docker-clean +8 -0
  22. data/bin/rake +29 -0
  23. data/bin/rspec +29 -0
  24. data/bin/rubocop +29 -0
  25. data/docker-compose.yml +25 -0
  26. data/examples/extract_and_colorize.rb +0 -13
  27. data/examples/geometries.rb +14 -14
  28. data/examples/ogr_layer_to_layer.rb +1 -3
  29. data/examples/raster_erasing.rb +1 -0
  30. data/examples/remove_small_polygons.rb +1 -1
  31. data/examples/testing_gdal.rb +20 -17
  32. data/examples/warping.rb +9 -7
  33. data/ffi-gdal.gemspec +12 -6
  34. data/lib/ext/ffi_library_function_checks.rb +2 -2
  35. data/lib/ext/to_bool.rb +5 -3
  36. data/lib/ffi/cpl/conv.rb +27 -25
  37. data/lib/ffi/cpl/error.rb +19 -20
  38. data/lib/ffi/cpl/hash_set.rb +4 -4
  39. data/lib/ffi/cpl/http.rb +3 -3
  40. data/lib/ffi/cpl/http_result.rb +8 -8
  41. data/lib/ffi/cpl/list.rb +1 -1
  42. data/lib/ffi/cpl/mime_part.rb +2 -2
  43. data/lib/ffi/cpl/minixml.rb +7 -7
  44. data/lib/ffi/cpl/progress.rb +8 -8
  45. data/lib/ffi/cpl/quad_tree.rb +14 -14
  46. data/lib/ffi/cpl/rect_obj.rb +3 -3
  47. data/lib/ffi/cpl/string.rb +17 -20
  48. data/lib/ffi/cpl/vsi.rb +13 -13
  49. data/lib/ffi/cpl/xml_node.rb +3 -3
  50. data/lib/ffi/extensions/gdal/extensions/all.rb +4 -0
  51. data/lib/ffi/extensions/gdal/extensions/version.rb +9 -0
  52. data/lib/ffi/extensions/gdal/extensions.rb +12 -0
  53. data/lib/ffi/extensions/rttopo/gbox.rb +19 -0
  54. data/lib/ffi/extensions/rttopo/geom.rb +16 -0
  55. data/lib/ffi/extensions/rttopo.rb +41 -0
  56. data/lib/ffi/gdal/alg.rb +277 -277
  57. data/lib/ffi/gdal/color_entry.rb +3 -3
  58. data/lib/ffi/gdal/gcp.rb +6 -6
  59. data/lib/ffi/gdal/gdal.rb +349 -349
  60. data/lib/ffi/gdal/grid.rb +134 -134
  61. data/lib/ffi/gdal/grid_data_metrics_options.rb +4 -4
  62. data/lib/ffi/gdal/grid_inverse_distance_to_a_power_options.rb +9 -9
  63. data/lib/ffi/gdal/grid_moving_average_options.rb +4 -4
  64. data/lib/ffi/gdal/grid_nearest_neighbor_options.rb +3 -3
  65. data/lib/ffi/gdal/matching.rb +3 -3
  66. data/lib/ffi/gdal/rpc_info.rb +17 -17
  67. data/lib/ffi/gdal/transformer_info.rb +4 -4
  68. data/lib/ffi/gdal/version.rb +1 -1
  69. data/lib/ffi/gdal/vrt.rb +39 -39
  70. data/lib/ffi/gdal/warp_options.rb +34 -34
  71. data/lib/ffi/gdal/warper.rb +90 -90
  72. data/lib/ffi/gdal.rb +2 -31
  73. data/lib/ffi/ogr/api.rb +175 -167
  74. data/lib/ffi/ogr/contour_writer_info.rb +4 -4
  75. data/lib/ffi/ogr/core.rb +107 -107
  76. data/lib/ffi/ogr/envelope.rb +3 -3
  77. data/lib/ffi/ogr/envelope_3d.rb +5 -5
  78. data/lib/ffi/ogr/featurestyle.rb +3 -3
  79. data/lib/ffi/ogr/field.rb +22 -22
  80. data/lib/ffi/ogr/geocoding.rb +4 -4
  81. data/lib/ffi/ogr/srs_api.rb +154 -155
  82. data/lib/ffi/ogr/style_param.rb +3 -3
  83. data/lib/ffi/ogr/style_value.rb +4 -4
  84. data/lib/gdal/color_entry.rb +1 -5
  85. data/lib/gdal/color_interpretation.rb +7 -3
  86. data/lib/gdal/color_table.rb +46 -27
  87. data/lib/gdal/cpl_error_handler.rb +26 -6
  88. data/lib/gdal/data_type.rb +10 -3
  89. data/lib/gdal/dataset.rb +171 -85
  90. data/lib/gdal/dataset_mixins/algorithm_methods.rb +44 -44
  91. data/lib/gdal/dataset_mixins/matching.rb +1 -1
  92. data/lib/gdal/dataset_mixins/warp_methods.rb +4 -2
  93. data/lib/gdal/driver.rb +38 -21
  94. data/lib/gdal/environment_methods.rb +6 -6
  95. data/lib/gdal/extensions/all.rb +3 -0
  96. data/lib/gdal/{color_entry_mixins → extensions/color_entry}/extensions.rb +4 -1
  97. data/lib/gdal/{color_table_mixins → extensions/color_table}/extensions.rb +3 -0
  98. data/lib/gdal/extensions/dataset/extensions.rb +205 -0
  99. data/lib/gdal/{driver_mixins → extensions/driver}/extensions.rb +6 -2
  100. data/lib/gdal/{geo_transform_mixins → extensions/geo_transform}/extensions.rb +10 -8
  101. data/lib/gdal/{gridder → extensions/gridder}/point_extracting.rb +7 -5
  102. data/lib/gdal/{gridder.rb → extensions/gridder.rb} +33 -33
  103. data/lib/gdal/{gridder_options.rb → extensions/gridder_options.rb} +13 -14
  104. data/lib/gdal/{raster_attribute_table_mixins → extensions/raster_attribute_table}/extensions.rb +8 -6
  105. data/lib/gdal/{raster_band_mixins → extensions/raster_band}/algorithm_extensions.rb +8 -6
  106. data/lib/gdal/{raster_band_mixins → extensions/raster_band}/coloring_extensions.rb +6 -4
  107. data/lib/gdal/{raster_band_mixins → extensions/raster_band}/extensions.rb +9 -5
  108. data/lib/gdal/{raster_band_mixins → extensions/raster_band}/io_extensions.rb +18 -14
  109. data/lib/gdal/{raster_band_classifier.rb → extensions/raster_band_classifier.rb} +3 -5
  110. data/lib/gdal/geo_transform.rb +1 -6
  111. data/lib/gdal/grid.rb +3 -2
  112. data/lib/gdal/grid_algorithms.rb +9 -9
  113. data/lib/gdal/internal_helpers.rb +46 -9
  114. data/lib/gdal/major_object.rb +11 -3
  115. data/lib/gdal/options.rb +26 -32
  116. data/lib/gdal/raster_attribute_table.rb +63 -37
  117. data/lib/gdal/raster_band.rb +164 -116
  118. data/lib/gdal/raster_band_mixins/algorithm_methods.rb +26 -25
  119. data/lib/gdal/rpc_info.rb +3 -2
  120. data/lib/gdal/transformers/approximate_transformer.rb +12 -3
  121. data/lib/gdal/transformers/base_general_image_projection_transformer.rb +15 -2
  122. data/lib/gdal/transformers/gcp_transformer.rb +27 -19
  123. data/lib/gdal/transformers/general_image_projection_transformer.rb +8 -6
  124. data/lib/gdal/transformers/general_image_projection_transformer2.rb +9 -6
  125. data/lib/gdal/transformers/general_image_projection_transformer3.rb +6 -2
  126. data/lib/gdal/transformers/geolocation_transformer.rb +12 -4
  127. data/lib/gdal/transformers/reprojection_transformer.rb +11 -3
  128. data/lib/gdal/transformers/rpc_transformer.rb +11 -2
  129. data/lib/gdal/transformers/tps_transformer.rb +12 -4
  130. data/lib/gdal/version_info.rb +2 -2
  131. data/lib/gdal/virtual_dataset.rb +2 -0
  132. data/lib/gdal/warp_operation.rb +65 -54
  133. data/lib/gdal/warp_options.rb +9 -11
  134. data/lib/ogr/coordinate_transformation.rb +23 -9
  135. data/lib/ogr/data_source.rb +68 -37
  136. data/lib/ogr/driver.rb +18 -17
  137. data/lib/ogr/envelope.rb +0 -3
  138. data/lib/ogr/error_handling.rb +22 -24
  139. data/lib/ogr/extensions/all.rb +3 -0
  140. data/lib/ogr/{data_source_mixins → extensions/data_source}/capability_methods.rb +2 -0
  141. data/lib/ogr/extensions/data_source/data_source_extensions.rb +16 -0
  142. data/lib/ogr/{driver_mixins → extensions/driver}/capability_methods.rb +5 -1
  143. data/lib/ogr/extensions/envelope/extensions.rb +114 -0
  144. data/lib/ogr/extensions/feature/extensions.rb +87 -0
  145. data/lib/ogr/extensions/feature_definition/extensions.rb +43 -0
  146. data/lib/ogr/extensions/geometries/point/extensions.rb +19 -0
  147. data/lib/ogr/extensions/geometry/container_mixins.rb +56 -0
  148. data/lib/ogr/extensions/geometry/ewkb_io_extensions.rb +44 -0
  149. data/lib/ogr/extensions/geometry/ewkb_record.rb +94 -0
  150. data/lib/ogr/{geometry_mixins → extensions/geometry}/extensions.rb +16 -9
  151. data/lib/ogr/extensions/geometry/rttopo_extensions.rb +48 -0
  152. data/lib/ogr/extensions/geometry/wkb_record.rb +63 -0
  153. data/lib/ogr/extensions/geometry_types/curve/extensions.rb +68 -0
  154. data/lib/ogr/{layer_mixins → extensions/layer}/capability_methods.rb +4 -0
  155. data/lib/ogr/{layer_mixins → extensions/layer}/extensions.rb +11 -6
  156. data/lib/ogr/extensions/spatial_reference/extensions.rb +38 -0
  157. data/lib/ogr/extensions/spatial_reference/initializers.rb +138 -0
  158. data/lib/ogr/extensions/style_table/extensions.rb +31 -0
  159. data/lib/ogr/feature.rb +173 -88
  160. data/lib/ogr/feature_definition.rb +53 -45
  161. data/lib/ogr/field.rb +17 -19
  162. data/lib/ogr/field_definition.rb +30 -18
  163. data/lib/ogr/geocoder.rb +11 -4
  164. data/lib/ogr/geometries/line_string.rb +1 -0
  165. data/lib/ogr/geometries/line_string_25d.rb +0 -9
  166. data/lib/ogr/geometries/linear_ring.rb +2 -2
  167. data/lib/ogr/geometries/point.rb +0 -9
  168. data/lib/ogr/geometry.rb +116 -49
  169. data/lib/ogr/geometry_field_definition.rb +31 -15
  170. data/lib/ogr/geometry_types/container.rb +26 -28
  171. data/lib/ogr/geometry_types/curve.rb +5 -61
  172. data/lib/ogr/geometry_types/surface.rb +1 -1
  173. data/lib/ogr/internal_helpers.rb +2 -2
  174. data/lib/ogr/layer.rb +12 -10
  175. data/lib/ogr/layer_mixins/ogr_feature_methods.rb +39 -27
  176. data/lib/ogr/layer_mixins/ogr_field_methods.rb +66 -50
  177. data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +17 -8
  178. data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +7 -6
  179. data/lib/ogr/layer_mixins/ogr_sql_methods.rb +15 -7
  180. data/lib/ogr/spatial_reference.rb +79 -42
  181. data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +149 -118
  182. data/lib/ogr/spatial_reference_mixins/exporters.rb +87 -51
  183. data/lib/ogr/spatial_reference_mixins/importers.rb +88 -43
  184. data/lib/ogr/spatial_reference_mixins/morphers.rb +12 -8
  185. data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +27 -13
  186. data/lib/ogr/style_table.rb +15 -5
  187. data/lib/ogr/style_tool.rb +29 -15
  188. data/lib/ogr.rb +1 -0
  189. data/rakelib/docker.rake +10 -0
  190. data/sorbet/rbi/hidden-definitions/errors.txt +21790 -0
  191. data/tilt/gdal2.yml +22 -0
  192. data/tilt/gdal3.yml +22 -0
  193. metadata +116 -280
  194. data/History.md +0 -360
  195. data/lib/ext/error_symbols.rb +0 -7
  196. data/lib/gdal/dataset_mixins/extensions.rb +0 -380
  197. data/lib/gdal/merger.rb +0 -132
  198. data/lib/ogr/data_source_extensions.rb +0 -10
  199. data/lib/ogr/envelope_extensions.rb +0 -110
  200. data/lib/ogr/feature_definition_extensions.rb +0 -39
  201. data/lib/ogr/feature_extensions.rb +0 -87
  202. data/lib/ogr/geometry_mixins/container_mixins.rb +0 -25
  203. data/lib/ogr/spatial_reference_extensions.rb +0 -34
  204. data/lib/ogr/style_table_extensions.rb +0 -26
  205. data/spec/ffi-gdal_spec.rb +0 -24
  206. data/spec/integration/gdal/color_table_info_spec.rb +0 -78
  207. data/spec/integration/gdal/dataset_info_spec.rb +0 -342
  208. data/spec/integration/gdal/driver_info_spec.rb +0 -170
  209. data/spec/integration/gdal/geo_transform_info_spec.rb +0 -226
  210. data/spec/integration/gdal/gridder_spec.rb +0 -331
  211. data/spec/integration/gdal/raster_attribute_table_info_spec.rb +0 -229
  212. data/spec/integration/gdal/raster_band_algorithms_spec.rb +0 -35
  213. data/spec/integration/gdal/raster_band_info_spec.rb +0 -320
  214. data/spec/integration/ogr/layer_spec.rb +0 -95
  215. data/spec/spec_helper.rb +0 -116
  216. data/spec/support/images/123.tiff +0 -0
  217. data/spec/support/images/osgeo/gdal/data/hfa/float-rle.img +0 -0
  218. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.lgo +0 -31
  219. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif +0 -0
  220. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif.msk +0 -0
  221. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.txt +0 -10
  222. data/spec/support/images/osgeo/geotiff/gdal_eg/cea.tif +0 -0
  223. data/spec/support/images/osgeo/geotiff/gdal_eg/cea.txt +0 -84
  224. data/spec/support/images/osgeo/geotiff/zi_imaging/image0.lgo +0 -45
  225. data/spec/support/images/osgeo/geotiff/zi_imaging/image0.tif +0 -0
  226. data/spec/support/integration_help.rb +0 -34
  227. data/spec/support/shapefiles/states_21basic/states.dbf +0 -0
  228. data/spec/support/shapefiles/states_21basic/states.prj +0 -1
  229. data/spec/support/shapefiles/states_21basic/states.sbn +0 -0
  230. data/spec/support/shapefiles/states_21basic/states.sbx +0 -0
  231. data/spec/support/shapefiles/states_21basic/states.shp +0 -0
  232. data/spec/support/shapefiles/states_21basic/states.shp.xml +0 -3
  233. data/spec/support/shapefiles/states_21basic/states.shx +0 -0
  234. data/spec/support/shared_contexts.rb +0 -28
  235. data/spec/support/shared_examples/gdal/major_object_examples.rb +0 -55
  236. data/spec/support/shared_examples/ogr/a_25d_geometry.rb +0 -9
  237. data/spec/support/shared_examples/ogr/a_container_geometry.rb +0 -49
  238. data/spec/support/shared_examples/ogr/a_geometry.rb +0 -406
  239. data/spec/support/shared_examples/ogr/a_line_string.rb +0 -18
  240. data/spec/support/test_style_table.txt +0 -3
  241. data/spec/support/worldfiles/SR_50M/SR_50M.VERSION.txt +0 -1
  242. data/spec/support/worldfiles/SR_50M/SR_50M.prj +0 -1
  243. data/spec/support/worldfiles/SR_50M/SR_50M.tfw +0 -6
  244. data/spec/support/worldfiles/SR_50M/SR_50M.tif +0 -0
  245. data/spec/unit/ext/error_symbols_spec.rb +0 -69
  246. data/spec/unit/ext/numeric_as_data_type_spec.rb +0 -115
  247. data/spec/unit/ffi/gdal_spec.rb +0 -73
  248. data/spec/unit/gdal/color_entry_spec.rb +0 -8
  249. data/spec/unit/gdal/color_interpretation_spec.rb +0 -8
  250. data/spec/unit/gdal/color_table_mixins/extensions_spec.rb +0 -62
  251. data/spec/unit/gdal/color_table_spec.rb +0 -146
  252. data/spec/unit/gdal/data_type_spec.rb +0 -74
  253. data/spec/unit/gdal/dataset_mixins/warp_methods_spec.rb +0 -55
  254. data/spec/unit/gdal/dataset_spec.rb +0 -148
  255. data/spec/unit/gdal/driver_mixins/extensions_spec.rb +0 -24
  256. data/spec/unit/gdal/driver_spec.rb +0 -51
  257. data/spec/unit/gdal/environment_methods_spec.rb +0 -8
  258. data/spec/unit/gdal/geo_transform_mixins/extensions_spec.rb +0 -69
  259. data/spec/unit/gdal/geo_transform_spec.rb +0 -265
  260. data/spec/unit/gdal/grid_spec.rb +0 -98
  261. data/spec/unit/gdal/gridder/point_extracting_spec.rb +0 -101
  262. data/spec/unit/gdal/gridder_options_spec.rb +0 -185
  263. data/spec/unit/gdal/gridder_spec.rb +0 -182
  264. data/spec/unit/gdal/internal_helpers_spec.rb +0 -278
  265. data/spec/unit/gdal/major_object_spec.rb +0 -10
  266. data/spec/unit/gdal/options_spec.rb +0 -33
  267. data/spec/unit/gdal/raster_attribute_table_spec.rb +0 -7
  268. data/spec/unit/gdal/raster_band_classifier_spec.rb +0 -260
  269. data/spec/unit/gdal/raster_band_mixins/extensions_spec.rb +0 -73
  270. data/spec/unit/gdal/raster_band_mixins/io_extensions_spec.rb +0 -135
  271. data/spec/unit/gdal/raster_band_spec.rb +0 -8
  272. data/spec/unit/gdal/rpc_info_spec.rb +0 -8
  273. data/spec/unit/gdal/version_info_spec.rb +0 -10
  274. data/spec/unit/gdal/virtual_dataset_spec.rb +0 -34
  275. data/spec/unit/gdal/warp_operation_spec.rb +0 -8
  276. data/spec/unit/gdal/warp_options_spec.rb +0 -338
  277. data/spec/unit/ogr/coordinate_transformation_spec.rb +0 -104
  278. data/spec/unit/ogr/data_source_mixins/capability_methods_spec.rb +0 -32
  279. data/spec/unit/ogr/data_source_spec.rb +0 -223
  280. data/spec/unit/ogr/driver_mixins/capability_methods_spec.rb +0 -20
  281. data/spec/unit/ogr/driver_spec.rb +0 -152
  282. data/spec/unit/ogr/envelope_spec.rb +0 -324
  283. data/spec/unit/ogr/feature_definition_spec.rb +0 -296
  284. data/spec/unit/ogr/feature_extensions_spec.rb +0 -90
  285. data/spec/unit/ogr/feature_spec.rb +0 -363
  286. data/spec/unit/ogr/field_definition_spec.rb +0 -118
  287. data/spec/unit/ogr/field_spec.rb +0 -195
  288. data/spec/unit/ogr/geometries/geometry_collection_25d_spec.rb +0 -25
  289. data/spec/unit/ogr/geometries/geometry_collection_spec.rb +0 -188
  290. data/spec/unit/ogr/geometries/line_string_25d_spec.rb +0 -25
  291. data/spec/unit/ogr/geometries/line_string_spec.rb +0 -107
  292. data/spec/unit/ogr/geometries/linear_ring_spec.rb +0 -92
  293. data/spec/unit/ogr/geometries/multi_line_string_25d_spec.rb +0 -25
  294. data/spec/unit/ogr/geometries/multi_line_string_spec.rb +0 -16
  295. data/spec/unit/ogr/geometries/multi_point_25d_spec.rb +0 -25
  296. data/spec/unit/ogr/geometries/multi_point_spec.rb +0 -16
  297. data/spec/unit/ogr/geometries/multi_polygon_25d_spec.rb +0 -25
  298. data/spec/unit/ogr/geometries/multi_polygon_spec.rb +0 -43
  299. data/spec/unit/ogr/geometries/none_geometry_spec.rb +0 -14
  300. data/spec/unit/ogr/geometries/point_25d_spec.rb +0 -25
  301. data/spec/unit/ogr/geometries/point_spec.rb +0 -307
  302. data/spec/unit/ogr/geometries/polygon_25d_spec.rb +0 -25
  303. data/spec/unit/ogr/geometries/polygon_spec.rb +0 -19
  304. data/spec/unit/ogr/geometries/unknown_geometry_spec.rb +0 -12
  305. data/spec/unit/ogr/geometry_field_definition_spec.rb +0 -73
  306. data/spec/unit/ogr/geometry_spec.rb +0 -711
  307. data/spec/unit/ogr/internal_helpers_spec.rb +0 -70
  308. data/spec/unit/ogr/layer_mixins/capability_methods_spec.rb +0 -90
  309. data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +0 -155
  310. data/spec/unit/ogr/layer_mixins/ogr_field_methods_spec.rb +0 -434
  311. data/spec/unit/ogr/layer_mixins/ogr_layer_method_methods_spec.rb +0 -22
  312. data/spec/unit/ogr/layer_mixins/ogr_query_filter_methods_spec.rb +0 -44
  313. data/spec/unit/ogr/layer_mixins/ogr_sql_methods_spec.rb +0 -14
  314. data/spec/unit/ogr/layer_spec.rb +0 -98
  315. data/spec/unit/ogr/spatial_reference_mixins/coordinate_system_getter_setters_spec.rb +0 -48
  316. data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +0 -151
  317. data/spec/unit/ogr/spatial_reference_mixins/importers_spec.rb +0 -40
  318. data/spec/unit/ogr/spatial_reference_mixins/morphers_spec.rb +0 -38
  319. data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +0 -105
  320. data/spec/unit/ogr/spatial_reference_mixins/type_checks_spec.rb +0 -159
  321. data/spec/unit/ogr/spatial_reference_spec.rb +0 -44
  322. data/spec/unit/ogr/style_table_spec.rb +0 -108
  323. data/spec/unit/ogr/style_tool_spec.rb +0 -159
  324. data/spec/unit/version_info_spec.rb +0 -50
data/lib/ogr/feature.rb CHANGED
@@ -3,11 +3,15 @@
3
3
  require 'date'
4
4
  require_relative '../ogr'
5
5
  require_relative '../gdal'
6
- require_relative 'feature_extensions'
7
6
 
8
7
  module OGR
9
8
  class Feature
10
- include FeatureExtensions
9
+ # @param pointer [FFI::Pointer]
10
+ def self.release(pointer)
11
+ return unless pointer && !pointer.null?
12
+
13
+ FFI::OGR::API.OGR_F_Destroy(pointer)
14
+ end
11
15
 
12
16
  # @return [FFI::Pointer] C pointer of the C Feature.
13
17
  attr_reader :c_pointer
@@ -16,27 +20,35 @@ module OGR
16
20
  # a FeatureDefinition (i.e. normal Feature creation) or a Pointer (in the
17
21
  # case a handle to a C OGR Feature needs to be wrapped with this object).
18
22
  def initialize(fd_or_pointer)
19
- @c_pointer = if fd_or_pointer.is_a? OGR::FeatureDefinition
20
- FFI::OGR::API.OGR_F_Create(fd_or_pointer.c_pointer)
21
- else
22
- fd_or_pointer
23
- end
23
+ pointer = case fd_or_pointer
24
+ when OGR::FeatureDefinition then FFI::OGR::API.OGR_F_Create(fd_or_pointer.c_pointer)
25
+ when FFI::Pointer
26
+ fd_or_pointer.autorelease = false
27
+ fd_or_pointer
28
+ else
29
+ raise OGR::InvalidFeature, 'OGR::Feature must be instantiated with valid feature'
30
+ end
31
+
32
+ if !pointer.is_a?(FFI::Pointer) || pointer.null?
33
+ raise OGR::InvalidFeature, "Unable to create Feature with #{fd_or_pointer}"
34
+ end
24
35
 
25
- return if @c_pointer.is_a?(FFI::Pointer) && !@c_pointer.null?
36
+ # pointer.autorelease = false
26
37
 
27
- raise OGR::InvalidFeature, "Unable to create Feature with #{fd_or_pointer}"
38
+ # @c_pointer = FFI::AutoPointer.new(pointer, Feature.method(:release))
39
+ @c_pointer = pointer
28
40
  end
29
41
 
30
42
  def destroy!
31
- return unless @c_pointer
43
+ Feature.release(@c_pointer)
32
44
 
33
- FFI::OGR::API.OGR_F_Destroy(@c_pointer)
34
45
  @c_pointer = nil
35
46
  end
36
47
 
37
48
  # @return [OGR::Feature]
38
49
  # @raise [OGR::Failure] If, for some reason, the clone fails.
39
50
  def clone
51
+ # This new feature is owned by the caller and must be released accordingly.
40
52
  feature_ptr = FFI::OGR::API.OGR_F_Clone(@c_pointer)
41
53
  raise OGR::Failure, 'Unable to clone feature' if feature_ptr.nil?
42
54
 
@@ -58,43 +70,44 @@ module OGR
58
70
  # @param _other_feature [OGR::Feature]
59
71
  # @param _be_forgiving [Boolean] +true+ if the operation should continue
60
72
  # despite lacking output fields matching some of the source fields.
61
- # @param with_map [Array<Fixnum>]
73
+ # @param with_map [Array<Integer>]
74
+ # @raise [OGR::Failure]
62
75
  # TODO: Implement +with_map+
63
- def set_from!(_other_feature, _be_forgiving = false, with_map: nil)
76
+ def set_from!(_other_feature, _be_forgiving: false, with_map: nil)
64
77
  raise NotImplementedError, 'with_map: is not yet supported' if with_map
65
78
 
66
- ogr_err = FFI::OGR::API.OGR_F_SetFrom(@c_pointer, other_feature_ptr)
67
-
68
- ogr_err.handle_result
79
+ OGR::ErrorHandling.handle_ogr_err('Unable to set from other feature') do
80
+ FFI::OGR::API.OGR_F_SetFrom(@c_pointer, other_feature_ptr)
81
+ end
69
82
  end
70
83
 
71
84
  # This will always be the same as the field count for the feature
72
85
  # definition.
73
86
  #
74
- # @return [Fixnum]
87
+ # @return [Integer]
75
88
  def field_count
76
89
  FFI::OGR::API.OGR_F_GetFieldCount(@c_pointer)
77
90
  end
78
91
 
79
- # @param index [Fixnum]
92
+ # @param index [Integer]
80
93
  # @param value [String]
81
94
  def set_field_string(index, value)
82
95
  FFI::OGR::API.OGR_F_SetFieldString(@c_pointer, index, value)
83
96
  end
84
97
 
85
- # @param index [Fixnum]
86
- # @param value [Fixnum]
98
+ # @param index [Integer]
99
+ # @param value [Integer]
87
100
  def set_field_integer(index, value)
88
101
  FFI::OGR::API.OGR_F_SetFieldInteger(@c_pointer, index, value)
89
102
  end
90
103
 
91
- # @param index [Fixnum]
104
+ # @param index [Integer]
92
105
  # @param value [Float]
93
106
  def set_field_double(index, value)
94
107
  FFI::OGR::API.OGR_F_SetFieldDouble(@c_pointer, index, value)
95
108
  end
96
109
 
97
- # @param index [Fixnum]
110
+ # @param index [Integer]
98
111
  # @param values [Array<String>]
99
112
  # @raise [GDAL::Error] If index isn't valid
100
113
  def set_field_string_list(index, values)
@@ -107,8 +120,8 @@ module OGR
107
120
  )
108
121
  end
109
122
 
110
- # @param index [Fixnum]
111
- # @param values [Array<Fixnum>]
123
+ # @param index [Integer]
124
+ # @param values [Array<Integer>]
112
125
  def set_field_integer_list(index, values)
113
126
  values_ptr = FFI::MemoryPointer.new(:int, values.size)
114
127
  values_ptr.write_array_of_int(values)
@@ -121,7 +134,7 @@ module OGR
121
134
  )
122
135
  end
123
136
 
124
- # @param index [Fixnum]
137
+ # @param index [Integer]
125
138
  # @param values [Array<Float>]
126
139
  def set_field_double_list(index, values)
127
140
  values_ptr = FFI::MemoryPointer.new(:double, values.size)
@@ -135,7 +148,7 @@ module OGR
135
148
  )
136
149
  end
137
150
 
138
- # @param index [Fixnum]
151
+ # @param index [Integer]
139
152
  # @param field [OGR::Field]
140
153
  def set_field_raw(index, field)
141
154
  usable_raw_field = field.c_struct
@@ -143,7 +156,7 @@ module OGR
143
156
  FFI::OGR::API.OGR_F_SetFieldRaw(@c_pointer, index, usable_raw_field)
144
157
  end
145
158
 
146
- # @param index [Fixnum]
159
+ # @param index [Integer]
147
160
  # @param value [String]
148
161
  def set_field_binary(index, value)
149
162
  raise TypeError, 'value must be a binary string' unless value.is_a? String
@@ -159,46 +172,51 @@ module OGR
159
172
  )
160
173
  end
161
174
 
162
- # @param index [Fixnum]
175
+ # @param index [Integer]
163
176
  # @param value [Date, Time, DateTime]
164
177
  def set_field_date_time(index, value)
165
178
  time = value.to_time
166
179
  zone = OGR._format_time_zone_for_ogr(value.zone)
167
180
 
168
181
  FFI::OGR::API.OGR_F_SetFieldDateTime(@c_pointer, index,
169
- time.year,
170
- time.month,
171
- time.day,
172
- time.hour,
173
- time.min,
174
- time.sec,
175
- zone)
182
+ time.year,
183
+ time.month,
184
+ time.day,
185
+ time.hour,
186
+ time.min,
187
+ time.sec,
188
+ zone)
176
189
  end
177
190
 
178
- # @param index [Fixnum]
191
+ # NOTE: Do not modify the FieldDefinition that's returned here.
192
+ #
193
+ # @param index [Integer]
179
194
  # @return [OGR::FieldDefinition]
180
195
  def field_definition(index)
196
+ # This returns an internal reference and should not be deleted or modified
181
197
  field_pointer = FFI::OGR::API.OGR_F_GetFieldDefnRef(@c_pointer, index)
198
+ field_pointer.autorelease = false
199
+
182
200
  return nil if field_pointer.null?
183
201
 
184
202
  OGR::FieldDefinition.new(field_pointer, nil)
185
203
  end
186
204
 
187
205
  # @param name [String]
188
- # @return [Fixnum, nil]
206
+ # @return [Integer, nil]
189
207
  def field_index(name)
190
208
  result = FFI::OGR::API.OGR_F_GetFieldIndex(@c_pointer, name)
191
209
 
192
- result < 0 ? nil : result
210
+ result.negative? ? nil : result
193
211
  end
194
212
 
195
- # @param index [Fixnum]
213
+ # @param index [Integer]
196
214
  # @return [Boolean]
197
215
  def field_set?(index)
198
216
  FFI::OGR::API.OGR_F_IsFieldSet(@c_pointer, index)
199
217
  end
200
218
 
201
- # @param index [Fixnum]
219
+ # @param index [Integer]
202
220
  def unset_field(index)
203
221
  FFI::OGR::API.OGR_F_UnsetField(@c_pointer, index)
204
222
  end
@@ -206,62 +224,91 @@ module OGR
206
224
  # @return [OGR::FeatureDefinition,nil]
207
225
  def definition
208
226
  feature_defn_ptr = FFI::OGR::API.OGR_F_GetDefnRef(@c_pointer)
227
+ feature_defn_ptr.autorelease = false
228
+
209
229
  return nil if feature_defn_ptr.null?
210
230
 
211
231
  OGR::FeatureDefinition.new(feature_defn_ptr)
212
232
  end
213
233
 
234
+ # NOTE: Do not modify the Geometry that's returned here.
235
+ #
214
236
  # @return [OGR::Geometry]
215
237
  def geometry
238
+ # This returns an internal reference and should not be deleted or modified
216
239
  geometry_ptr = FFI::OGR::API.OGR_F_GetGeometryRef(@c_pointer)
240
+ geometry_ptr.autorelease = false
241
+
217
242
  return nil if geometry_ptr.null?
218
243
 
219
244
  OGR::Geometry.factory(geometry_ptr)
220
245
  end
221
246
 
247
+ # Sets the geometry of the feature by making a copy of +new_geometry+.
248
+ #
249
+ # @param new_geometry [OGR::Geometry]
250
+ # @raise [OGR::Failure]
251
+ def set_geometry(new_geometry) # rubocop:disable Naming/AccessorMethodName
252
+ OGR::ErrorHandling.handle_ogr_err('Unable to set geometry on feature') do
253
+ FFI::OGR::API.OGR_F_SetGeometry(@c_pointer, new_geometry.c_pointer)
254
+ end
255
+ end
256
+
257
+ # Sets the geometry of the feature by taking ownership of +new_geometry.
258
+ #
222
259
  # @param new_geometry [OGR::Geometry]
223
- # @return +true+ if successful, otherwise raises an OGR exception.
224
- def geometry=(new_geometry)
225
- ogr_err = FFI::OGR::API.OGR_F_SetGeometryDirectly(@c_pointer, new_geometry.c_pointer)
260
+ # @raise [OGR::Failure]
261
+ def set_geometry_directly(new_geometry) # rubocop:disable Naming/AccessorMethodName
262
+ new_geometry.c_pointer.autorelease = false
226
263
 
227
- ogr_err.handle_result
264
+ OGR::ErrorHandling.handle_ogr_err('Unable to set geometry directly on feature') do
265
+ FFI::OGR::API.OGR_F_SetGeometryDirectly(@c_pointer, new_geometry.c_pointer)
266
+ end
228
267
  end
268
+ alias geometry= set_geometry_directly
229
269
 
270
+ # Takes away ownership of the Feature's Geometry and returns it to the caller.
271
+ #
230
272
  # @return [OGR::Geometry]
231
273
  def steal_geometry
232
274
  geometry_ptr = FFI::OGR::API.OGR_F_StealGeometry(@c_pointer)
233
- raise OGR::Failure, 'Unable to steal geometry.' if geometry_ptr.nil?
275
+ raise OGR::Failure, 'Unable to steal geometry.' if geometry_ptr.nil? || geometry_ptr.null?
234
276
 
235
277
  OGR::Geometry.factory(geometry_ptr)
236
278
  end
237
279
 
238
- # @return [Fixnum]
280
+ # @return [Integer]
239
281
  def fid
240
282
  FFI::OGR::API.OGR_F_GetFID(@c_pointer)
241
283
  end
242
284
 
243
- # @param new_fid [Fixnum]
244
- # @return +true+ if successful, otherwise raises an OGR exception.
285
+ # @param new_fid [Integer]
286
+ # @raise [OGR::Failure]
245
287
  def fid=(new_fid)
246
- ogr_err = FFI::OGR::API.OGR_F_SetFID(@c_pointer, new_fid)
247
-
248
- ogr_err.handle_result
288
+ OGR::ErrorHandling.handle_ogr_err('Unable to set FID') do
289
+ FFI::OGR::API.OGR_F_SetFID(@c_pointer, new_fid)
290
+ end
249
291
  end
250
292
 
251
293
  # The number of Geometries in this feature.
252
294
  #
253
- # @return [Fixnum]
295
+ # @return [Integer]
254
296
  def geometry_field_count
255
297
  FFI::OGR::API.OGR_F_GetGeomFieldCount(@c_pointer)
256
298
  end
257
299
 
258
- # @param index [Fixnum]
300
+ # NOTE: Do not modify the GeometryFieldDefinition that's returned here.
301
+ #
302
+ # @param index [Integer]
259
303
  # @return [OGR::GeometryFieldDefinition] A read-only
260
304
  # OGR::GeometryFieldDefinition.
261
305
  # @raise [OGR::InvalidGeometryFieldDefinition] If there isn't one at
262
306
  # +index+.
263
307
  def geometry_field_definition(index)
308
+ # This returns an internal reference and should not be deleted or modified
264
309
  gfd_ptr = FFI::OGR::API.OGR_F_GetGeomFieldDefnRef(@c_pointer, index)
310
+ gfd_ptr.autorelease = false
311
+
265
312
  return nil if gfd_ptr.nil?
266
313
 
267
314
  gfd = OGR::GeometryFieldDefinition.new(gfd_ptr)
@@ -271,29 +318,54 @@ module OGR
271
318
  end
272
319
 
273
320
  # @param name [String]
274
- # @return [Fixnum]
321
+ # @return [Integer]
275
322
  def geometry_field_index(name)
276
323
  FFI::OGR::API.OGR_F_GetGeomFieldIndex(@c_pointer, name)
277
324
  end
278
325
 
279
- # @param index [Fixnum]
326
+ # NOTE: Do not modify the Geometry that's returned here.
327
+ #
328
+ # @param index [Integer]
280
329
  # @return [OGR::Geometry, nil] A read-only OGR::Geometry.
281
330
  def geometry_field(index)
331
+ # This returns an internal reference and should not be deleted or modified
282
332
  geometry_ptr = FFI::OGR::API.OGR_F_GetGeomFieldRef(@c_pointer, index)
333
+ geometry_ptr.autorelease = false
334
+
283
335
  return nil if geometry_ptr.nil? || geometry_ptr.null?
284
336
 
285
337
  OGR::Geometry.factory(geometry_ptr)
286
338
  end
287
339
 
288
- # @param index [Fixnum]
340
+ # Sets the feature geometry of a specified geometry field by making a copy
341
+ # of +geometry+.
342
+ #
343
+ # @param index [Integer]
289
344
  # @param geometry [OGR::Geometry]
345
+ # @raise [OGR::Failure]
290
346
  def set_geometry_field(index, geometry)
291
347
  geometry_ptr = GDAL._pointer(OGR::Geometry, geometry)
292
348
  raise OGR::InvalidGeometry if geometry_ptr.nil?
293
349
 
294
- ogr_err = FFI::OGR::API.OGR_F_SetGeomField(@c_pointer, index, geometry_ptr)
350
+ OGR::ErrorHandling.handle_ogr_err("Unable to set geometry field at index #{index}") do
351
+ FFI::OGR::API.OGR_F_SetGeomField(@c_pointer, index, geometry_ptr)
352
+ end
353
+ end
295
354
 
296
- ogr_err.handle_result
355
+ # Sets the feature geometry of a specified geometry field by taking ownership
356
+ # of +geometry+.
357
+ #
358
+ # @param index [Integer]
359
+ # @param geometry [OGR::Geometry]
360
+ # @raise [OGR::Failure]
361
+ def set_geometry_field_directly(index, geometry)
362
+ geometry_ptr = GDAL._pointer(OGR::Geometry, geometry, autorelease: false)
363
+
364
+ raise OGR::InvalidGeometry if geometry_ptr.nil?
365
+
366
+ OGR::ErrorHandling.handle_ogr_err("Unable to set geometry field directly at index #{index}") do
367
+ FFI::OGR::API.OGR_F_SetGeomFieldDirectly(@c_pointer, index, geometry_ptr)
368
+ end
297
369
  end
298
370
 
299
371
  # @return [Boolean]
@@ -302,68 +374,76 @@ module OGR
302
374
  end
303
375
  alias equals? equal?
304
376
 
305
- # @param index [Fixnum]
306
- # @return [Fixnum]
377
+ # @param index [Integer]
378
+ # @return [Integer]
307
379
  def field_as_integer(index)
308
380
  FFI::OGR::API.OGR_F_GetFieldAsInteger(@c_pointer, index)
309
381
  end
310
382
 
311
- # @param index [Fixnum]
312
- # @return [Array<Fixnum>]
383
+ # @param index [Integer]
384
+ # @return [Array<Integer>]
313
385
  def field_as_integer_list(index)
314
386
  list_size_ptr = FFI::MemoryPointer.new(:int)
315
- list_ptr =
316
- FFI::OGR::API.OGR_F_GetFieldAsIntegerList(@c_pointer, index, list_size_ptr)
387
+ # This list is internal, and should not be modified, or freed. Its lifetime may be very brief.
388
+ list_ptr = FFI::OGR::API.OGR_F_GetFieldAsIntegerList(@c_pointer, index, list_size_ptr)
389
+ list_ptr.autorelease = false
390
+
317
391
  return [] if list_ptr.null?
318
392
 
319
393
  list_ptr.read_array_of_int(list_size_ptr.read_int)
320
394
  end
321
395
 
322
- # @param index [Fixnum]
396
+ # @param index [Integer]
323
397
  # @return [Float]
324
398
  def field_as_double(index)
325
399
  FFI::OGR::API.OGR_F_GetFieldAsDouble(@c_pointer, index)
326
400
  end
327
401
 
328
- # @param index [Fixnum]
402
+ # @param index [Integer]
329
403
  # @return [Array<Float>]
330
404
  def field_as_double_list(index)
331
405
  list_size_ptr = FFI::MemoryPointer.new(:int)
332
- list_ptr =
333
- FFI::OGR::API.OGR_F_GetFieldAsDoubleList(@c_pointer, index, list_size_ptr)
406
+ # This list is internal, and should not be modified, or freed. Its lifetime may be very brief.
407
+ list_ptr = FFI::OGR::API.OGR_F_GetFieldAsDoubleList(@c_pointer, index, list_size_ptr)
408
+ list_ptr.autorelease = false
409
+
334
410
  return [] if list_ptr.null?
335
411
 
336
412
  list_ptr.read_array_of_double(list_size_ptr.read_int)
337
413
  end
338
414
 
339
- # @param index [Fixnum]
415
+ # @param index [Integer]
340
416
  # @return [String]
341
417
  def field_as_string(index)
342
- FFI::OGR::API.OGR_F_GetFieldAsString(@c_pointer, index).force_encoding(Encoding::UTF_8)
418
+ field, ptr = FFI::OGR::API.OGR_F_GetFieldAsString(@c_pointer, index)
419
+ ptr.autorelease = false
420
+
421
+ field.force_encoding(Encoding::UTF_8)
343
422
  end
344
423
 
345
- # @param index [Fixnum]
424
+ # @param index [Integer]
346
425
  # @return [Array<String>]
347
426
  def field_as_string_list(index)
348
- list_ptr =
349
- FFI::OGR::API.OGR_F_GetFieldAsStringList(@c_pointer, index)
427
+ # This list is internal, and should not be modified, or freed. Its lifetime may be very brief.
428
+ list_ptr = FFI::OGR::API.OGR_F_GetFieldAsStringList(@c_pointer, index)
429
+ list_ptr.autorelease = false
430
+
350
431
  return [] if list_ptr.null?
351
432
 
352
433
  list_ptr.get_array_of_string(0)
353
434
  end
354
435
 
355
- # @param index [Fixnum]
436
+ # @param index [Integer]
356
437
  # @return [String]
357
438
  def field_as_binary(index)
358
439
  byte_count_ptr = FFI::MemoryPointer.new(:int)
359
- binary_data = FFI::OGR::API.OGR_F_GetFieldAsBinary(
360
- @c_pointer,
361
- index,
362
- byte_count_ptr
363
- )
440
+
441
+ # This list is internal, and should not be modified, or freed. Its lifetime may be very brief.
442
+ binary_data_ptr = FFI::OGR::API.OGR_F_GetFieldAsBinary(@c_pointer, index, byte_count_ptr)
443
+ binary_data_ptr.autorelease = false
364
444
 
365
445
  byte_count = byte_count_ptr.read_int
366
- string = byte_count > 0 ? binary_data.read_bytes(byte_count) : ''
446
+ string = byte_count.positive? ? binary_data_ptr.read_bytes(byte_count) : ''
367
447
 
368
448
  string.unpack('C*')
369
449
  end
@@ -377,7 +457,7 @@ module OGR
377
457
  second_ptr = FFI::MemoryPointer.new(:int)
378
458
  time_zone_flag_ptr = FFI::MemoryPointer.new(:int)
379
459
 
380
- result = FFI::OGR::API.OGR_F_GetFieldAsDateTime(
460
+ success = FFI::OGR::API.OGR_F_GetFieldAsDateTime(
381
461
  @c_pointer,
382
462
  index,
383
463
  year_ptr,
@@ -388,11 +468,10 @@ module OGR
388
468
  second_ptr,
389
469
  time_zone_flag_ptr
390
470
  )
391
- return nil unless result
471
+ return nil unless success
392
472
 
393
473
  formatted_tz = OGR._format_time_zone_for_ruby(time_zone_flag_ptr.read_int)
394
474
 
395
- # rubocop:disable Style/DateTime
396
475
  if formatted_tz
397
476
  DateTime.new(
398
477
  year_ptr.read_int,
@@ -413,12 +492,14 @@ module OGR
413
492
  second_ptr.read_int
414
493
  )
415
494
  end
416
- # rubocop:enable Style/DateTime
417
495
  end
418
496
 
419
497
  # @return [String]
420
498
  def style_string
421
- FFI::OGR::API.OGR_F_GetStyleString(@c_pointer)
499
+ style, ptr = FFI::OGR::API.OGR_F_GetStyleString(@c_pointer)
500
+ ptr.autorelease = false
501
+
502
+ style
422
503
  end
423
504
 
424
505
  # @param new_style [String]
@@ -429,6 +510,8 @@ module OGR
429
510
  # @return [OGR::StyleTable]
430
511
  def style_table
431
512
  style_table_ptr = FFI::OGR::API.OGR_F_GetStyleTable(@c_pointer)
513
+ style_table_ptr.autorelease = false
514
+
432
515
  return nil if style_table_ptr.nil? || style_table_ptr.null?
433
516
 
434
517
  OGR::StyleTable.new(style_table_ptr)
@@ -436,7 +519,8 @@ module OGR
436
519
 
437
520
  # @param new_style_table [OGR::StyleTable]
438
521
  def style_table=(new_style_table)
439
- new_style_table_ptr = GDAL._pointer(OGR::StyleTable, new_style_table)
522
+ new_style_table_ptr = GDAL._pointer(OGR::StyleTable, new_style_table, autorelease: false)
523
+
440
524
  raise OGR::InvalidStyleTable unless new_style_table_ptr
441
525
 
442
526
  FFI::OGR::API.OGR_F_SetStyleTableDirectly(@c_pointer, new_style_table_ptr)
@@ -445,9 +529,10 @@ module OGR
445
529
  private
446
530
 
447
531
  def c_pointer_from(feature)
448
- if feature.is_a? OGR::Feature
532
+ case feature
533
+ when OGR::Feature
449
534
  feature.c_pointer
450
- elsif feature.is_a? FFI::Pointer
535
+ when FFI::Pointer
451
536
  feature
452
537
  end
453
538
  end