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
@@ -4,95 +4,106 @@ require_relative '../gdal'
4
4
 
5
5
  module GDAL
6
6
  class WarpOperation
7
+ # @param pointer [FFI::Pointer]
8
+ def self.release(pointer)
9
+ return unless pointer && !pointer.null?
10
+
11
+ FFI::GDAL::Warper.GDALDestroyWarpOperation(pointer)
12
+ end
13
+
7
14
  # @return [FFI::Pointer]
8
15
  attr_reader :c_pointer
9
16
 
10
17
  # @param warp_options [GDAL::WarpOptions]
11
18
  def initialize(warp_options)
12
- @c_pointer = FFI::GDAL::Warper.GDALCreateWarpOperation(warp_options.c_struct)
13
- raise GDAL::Error, 'Unable to create warp operation' if @c_pointer.null?
19
+ pointer = FFI::GDAL::Warper.GDALCreateWarpOperation(warp_options.c_struct)
20
+
21
+ raise GDAL::Error, 'Unable to create warp operation' if pointer.null?
22
+
23
+ @c_pointer = FFI::AutoPointer.new(pointer, WarpOperation.method(:release))
14
24
  end
15
25
 
16
26
  def destroy!
17
- return unless @c_pointer
27
+ WarpOperation.release(@c_pointer)
18
28
 
19
- FFI::GDAL::Warper.GDALDestroyWarpOperation(@c_pointer)
20
29
  @c_pointer = nil
21
30
  end
22
31
 
23
- # @param x_offset [Fixnum] X offset of the destination image.
24
- # @param y_offset [Fixnum] Y offset of the destination image.
25
- # @param x_size [Fixnum] X size (width) of the destination image.
26
- # @param y_size [Fixnum] Y size (height) of the destination image.
32
+ # @param x_offset [Integer] X offset of the destination image.
33
+ # @param y_offset [Integer] Y offset of the destination image.
34
+ # @param x_size [Integer] X size (width) of the destination image.
35
+ # @param y_size [Integer] Y size (height) of the destination image.
27
36
  def chunk_and_warp_image(x_offset, y_offset, x_size, y_size)
28
37
  !!FFI::GDAL::Warper.GDALChunkAndWarpImage(@c_pointer,
29
- x_offset,
30
- y_offset,
31
- x_size,
32
- y_size)
38
+ x_offset,
39
+ y_offset,
40
+ x_size,
41
+ y_size)
33
42
  end
34
43
 
35
- # @param x_offset [Fixnum] X offset of the destination image.
36
- # @param y_offset [Fixnum] Y offset of the destination image.
37
- # @param x_size [Fixnum] X size (width) of the destination image.
38
- # @param y_size [Fixnum] Y size (height) of the destination image.
44
+ # @param x_offset [Integer] X offset of the destination image.
45
+ # @param y_offset [Integer] Y offset of the destination image.
46
+ # @param x_size [Integer] X size (width) of the destination image.
47
+ # @param y_size [Integer] Y size (height) of the destination image.
39
48
  def chunk_and_warp_multi(x_offset, y_offset, x_size, y_size)
40
49
  FFI::GDAL::Warper.GDALChunkAndWarpMulti(@c_pointer,
41
- x_offset,
42
- y_offset,
43
- x_size,
44
- y_size)
50
+ x_offset,
51
+ y_offset,
52
+ x_size,
53
+ y_size)
45
54
  end
46
55
 
47
- # @param destination_x_offset [Fixnum] X offset of the destination image.
48
- # @param destination_y_offset [Fixnum] Y offset of the destination image.
49
- # @param destination_x_size [Fixnum] X size (width) of the destination image.
50
- # @param destination_y_size [Fixnum] Y size (height) of the destination image.
51
- # @param source_x_offset [Fixnum] X offset of the source image.
52
- # @param source_y_offset [Fixnum] Y offset of the source image.
53
- # @param source_x_size [Fixnum] X size (width) of the source image.
54
- # @param source_y_size [Fixnum] Y size (height) of the source image.
56
+ # @param destination_x_offset [Integer] X offset of the destination image.
57
+ # @param destination_y_offset [Integer] Y offset of the destination image.
58
+ # @param destination_x_size [Integer] X size (width) of the destination image.
59
+ # @param destination_y_size [Integer] Y size (height) of the destination image.
60
+ # @param source_x_offset [Integer] X offset of the source image.
61
+ # @param source_y_offset [Integer] Y offset of the source image.
62
+ # @param source_x_size [Integer] X size (width) of the source image.
63
+ # @param source_y_size [Integer] Y size (height) of the source image.
55
64
  def warp_region(destination_x_offset, destination_y_offset,
56
65
  destination_x_size, destination_y_size,
57
66
  source_x_offset, source_y_offset,
58
67
  source_x_size, source_y_size)
59
68
  !!FFI::GDAL::Warper.GDALWarpRegion(@c_pointer,
60
- destination_x_offset,
61
- destination_y_offset,
62
- destination_x_size,
63
- destination_y_size,
64
- source_x_offset,
65
- source_y_offset,
66
- source_x_size,
67
- source_y_size)
69
+ destination_x_offset,
70
+ destination_y_offset,
71
+ destination_x_size,
72
+ destination_y_size,
73
+ source_x_offset,
74
+ source_y_offset,
75
+ source_x_size,
76
+ source_y_size)
68
77
  end
69
78
 
70
- # @param destination_x_offset [Fixnum] X offset of the destination image.
71
- # @param destination_y_offset [Fixnum] Y offset of the destination image.
72
- # @param destination_x_size [Fixnum] X size (width) of the destination image.
73
- # @param destination_y_size [Fixnum] Y size (height) of the destination image.
79
+ # @param destination_x_offset [Integer] X offset of the destination image.
80
+ # @param destination_y_offset [Integer] Y offset of the destination image.
81
+ # @param destination_x_size [Integer] X size (width) of the destination image.
82
+ # @param destination_y_size [Integer] Y size (height) of the destination image.
74
83
  # @param buffer [FFI::Pointer]
75
84
  # @param data_type [FFI::GDAL::DataType]
76
- # @param source_x_offset [Fixnum] X offset of the source image.
77
- # @param source_y_offset [Fixnum] Y offset of the source image.
78
- # @param source_x_size [Fixnum] X size (width) of the source image.
79
- # @param source_y_size [Fixnum] Y size (height) of the source image.
85
+ # @param source_x_offset [Integer] X offset of the source image.
86
+ # @param source_y_offset [Integer] Y offset of the source image.
87
+ # @param source_x_size [Integer] X size (width) of the source image.
88
+ # @param source_y_size [Integer] Y size (height) of the source image.
89
+ # rubocop:disable Metrics/ParameterLists
80
90
  def warp_region_to_buffer(destination_x_offset, destination_y_offset,
81
91
  destination_x_size, destination_y_size,
82
92
  buffer, data_type,
83
93
  source_x_offset, source_y_offset,
84
94
  source_x_size, source_y_size)
85
95
  !!FFI::GDAL::Warper.GDALWarpRegionToBuffer(@c_pointer,
86
- destination_x_offset,
87
- destination_y_offset,
88
- destination_x_size,
89
- destination_y_size,
90
- buffer,
91
- data_type,
92
- source_x_offset,
93
- source_y_offset,
94
- source_x_size,
95
- source_y_size)
96
+ destination_x_offset,
97
+ destination_y_offset,
98
+ destination_x_size,
99
+ destination_y_size,
100
+ buffer,
101
+ data_type,
102
+ source_x_offset,
103
+ source_y_offset,
104
+ source_x_size,
105
+ source_y_size)
96
106
  end
107
+ # rubocop:enable Metrics/ParameterLists
97
108
  end
98
109
  end
@@ -4,10 +4,7 @@ require_relative '../gdal'
4
4
 
5
5
  module GDAL
6
6
  class WarpOptions
7
- attr_reader :c_struct
8
- attr_reader :source_dataset
9
- attr_reader :destination_dataset
10
- attr_reader :cutline
7
+ attr_reader :c_struct, :source_dataset, :destination_dataset, :cutline
11
8
 
12
9
  def initialize(options = {})
13
10
  @c_struct = FFI::GDAL::WarpOptions.new
@@ -23,8 +20,8 @@ module GDAL
23
20
  else
24
21
  @c_struct[k] = options[k]
25
22
  end
26
- rescue ArgumentError => ex
27
- new_message = "#{k}; #{ex.message}"
23
+ rescue ArgumentError => e
24
+ new_message = "#{k}; #{e.message}"
28
25
  raise $ERROR_INFO, new_message, $ERROR_INFO.backtrace
29
26
  end
30
27
  end
@@ -58,7 +55,7 @@ module GDAL
58
55
  @c_struct[:destination_dataset] = dataset.c_pointer
59
56
  end
60
57
 
61
- # @param band_numbers [Array<Fixnum>]
58
+ # @param band_numbers [Array<Integer>]
62
59
  def source_bands=(band_numbers)
63
60
  bands_ptr = FFI::MemoryPointer.new(:int, band_numbers.length)
64
61
  bands_ptr.write_array_of_int(band_numbers)
@@ -67,7 +64,7 @@ module GDAL
67
64
  @c_struct[:band_count] = band_numbers.length if band_numbers.length > @c_struct[:band_count]
68
65
  end
69
66
 
70
- # @return [Array<Fixnum>]
67
+ # @return [Array<Integer>]
71
68
  def source_bands
72
69
  pointer = @c_struct[:source_bands]
73
70
  return [] if pointer.null?
@@ -75,7 +72,7 @@ module GDAL
75
72
  pointer.read_array_of_int(@c_struct[:band_count])
76
73
  end
77
74
 
78
- # @param band_numbers [Array<Fixnum>]
75
+ # @param band_numbers [Array<Integer>]
79
76
  def destination_bands=(band_numbers)
80
77
  bands_ptr = FFI::MemoryPointer.new(:pointer, band_numbers.length)
81
78
  bands_ptr.write_array_of_int(band_numbers)
@@ -84,7 +81,7 @@ module GDAL
84
81
  @c_struct[:band_count] = band_numbers.length if band_numbers.length > @c_struct[:band_count]
85
82
  end
86
83
 
87
- # @return [Array<Fixnum>]
84
+ # @return [Array<Integer>]
88
85
  def destination_bands
89
86
  pointer = @c_struct[:destination_bands]
90
87
  return [] if pointer.null?
@@ -101,6 +98,7 @@ module GDAL
101
98
  # @param geometry [OGR::Geometry]
102
99
  def cutline=(geometry)
103
100
  raise 'Not a geom' unless geometry.is_a?(OGR::Geometry)
101
+
104
102
  @cutline = geometry
105
103
 
106
104
  @c_struct[:cutline] = geometry.c_pointer
@@ -171,7 +169,7 @@ module GDAL
171
169
  end
172
170
 
173
171
  # Set a Proc per source band; number of procs in +band_procs+ should equal
174
- # {band_count}.
172
+ # the internal +band_count+.
175
173
  #
176
174
  # @param band_procs [Array<Proc>]
177
175
  def source_per_band_validity_mask_function=(band_procs)
@@ -13,10 +13,17 @@ module OGR
13
13
  FFI::GDAL::GDAL.OCTProj4Normalize(proj4_source)
14
14
  else
15
15
  raise OGR::UnsupportedOperation,
16
- 'Your version of GDAL/OGR does not support OCTProj4Normalize'
16
+ 'Your version of GDAL/OGR does not support OCTProj4Normalize'
17
17
  end
18
18
  end
19
19
 
20
+ # @param pointer [FFI::Pointer]
21
+ def self.release(pointer)
22
+ return unless pointer && !pointer.null?
23
+
24
+ FFI::OGR::SRSAPI.OCTDestroyCoordinateTransformation(pointer)
25
+ end
26
+
20
27
  # @return [OGR::SpatialReference]
21
28
  attr_reader :source_coordinate_system
22
29
 
@@ -31,16 +38,23 @@ module OGR
31
38
  def initialize(source_srs, destination_srs)
32
39
  source_ptr = GDAL._pointer(OGR::SpatialReference, source_srs)
33
40
  destination_ptr = GDAL._pointer(OGR::SpatialReference, destination_srs)
34
- @c_pointer = FFI::OGR::SRSAPI.OCTNewCoordinateTransformation(source_ptr, destination_ptr)
35
41
 
36
- raise OGR::Failure, 'Unable to create coordinate transformation' if @c_pointer.null?
42
+ # Input spatial reference system objects are assigned by copy (calling clone() method)
43
+ # and no ownership transfer occurs.
44
+ # NOTE: In GDAL 3, this will cause the GDAL error handler to raise a
45
+ # GDAL::Error; in < 3, this just returns a null pointer, then gets handled
46
+ # by the null-pointer check below.
47
+ pointer = FFI::OGR::SRSAPI.OCTNewCoordinateTransformation(source_ptr, destination_ptr)
48
+
49
+ raise GDAL::Error, 'Unable to create coordinate transformation' if pointer.null?
50
+
51
+ @c_pointer = pointer
37
52
  end
38
53
 
39
54
  # Deletes the object and deallocates all related C resources.
40
55
  def destroy!
41
- return unless @c_pointer
56
+ CoordinateTransformation.release(@c_pointer)
42
57
 
43
- FFI::OGR::SRSAPI.OCTDestroyCoordinateTransformation(@c_pointer)
44
58
  @c_pointer = nil
45
59
  end
46
60
 
@@ -83,10 +97,10 @@ module OGR
83
97
  # @param x_vertices [Array<Float>]
84
98
  # @param y_vertices [Array<Float>]
85
99
  # @param z_vertices [Array<Float>]
86
- # @yieldparam point_count [Fixnum]
87
- # @yieldparam x_ptr [FFI::MemortyPointer]
88
- # @yieldparam y_ptr [FFI::MemortyPointer]
89
- # @yieldparam z_ptr [FFI::MemortyPointer]
100
+ # @yieldparam point_count [Integer]
101
+ # @yieldparam x_ptr [FFI::MemoryPointer]
102
+ # @yieldparam y_ptr [FFI::MemoryPointer]
103
+ # @yieldparam z_ptr [FFI::MemoryPointer]
90
104
  # @yieldreturn [Boolean]
91
105
  # @return [Array<Array<Float>,Array<Float>,Array<Float>>] [[x1, x2, etc], [y1, y2, etc]]
92
106
  # Will include a 3rd array of Z values if z vertices are given.
@@ -1,18 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
3
  require_relative '../gdal'
5
4
  require_relative '../ogr'
6
- require_relative 'data_source_extensions'
7
- require_relative 'data_source_mixins/capability_methods'
8
5
  require_relative '../gdal/major_object'
9
6
 
10
7
  module OGR
11
8
  class DataSource
12
9
  include GDAL::MajorObject
13
10
  include GDAL::Logger
14
- include DataSourceExtensions
15
- include DataSourceMixins::CapabilityMethods
16
11
 
17
12
  # Same as +.new+.
18
13
  #
@@ -31,6 +26,23 @@ module OGR
31
26
  end
32
27
  end
33
28
 
29
+ # @param pointer [FFI::Pointer]
30
+ def self.release(pointer)
31
+ return unless pointer && !pointer.null?
32
+
33
+ FFI::OGR::API.OGR_DS_Destroy(pointer)
34
+ end
35
+
36
+ # Use to release the resulting data pointer from #execute_sql.
37
+ #
38
+ # @param data_source_pointer [FFI::Pointer]
39
+ # @param layer_pointer [FFI::Pointer]
40
+ def self.release_result_set(data_source_pointer, layer_pointer)
41
+ return unless data_source_pointer && !data_source_pointer.null? && layer_pointer && !layer_pointer.null?
42
+
43
+ FFI::OGR::API.OGR_DS_ReleaseResultSet(data_source_pointer, layer_pointer)
44
+ end
45
+
34
46
  # @return [FFI::Pointer]
35
47
  attr_reader :c_pointer
36
48
 
@@ -45,16 +57,23 @@ module OGR
45
57
  path_or_pointer
46
58
  end
47
59
 
48
- raise OGR::OpenFailure, path_or_pointer if @c_pointer.null?
60
+ if @c_pointer.null?
61
+ error_msg, ptr = FFI::CPL::Error.CPLGetLastErrorMsg
62
+ ptr.autorelease = false
63
+
64
+ error_type = FFI::CPL::Error.CPLGetLastErrorType
65
+ FFI::CPL::Error.CPLErrorReset
66
+
67
+ raise OGR::OpenFailure, "#{error_type}: #{error_msg} (#{path_or_pointer})"
68
+ end
49
69
 
50
70
  @layers = []
51
71
  end
52
72
 
53
73
  # Closes opened data source and releases allocated resources.
54
74
  def destroy!
55
- return unless @c_pointer
75
+ DataSource.release(@c_pointer)
56
76
 
57
- FFI::OGR::API.OGR_DS_Destroy(@c_pointer)
58
77
  @c_pointer = nil
59
78
  end
60
79
  alias close destroy!
@@ -63,7 +82,11 @@ module OGR
63
82
  #
64
83
  # @return [String]
65
84
  def name
66
- FFI::OGR::API.OGR_DS_GetName(@c_pointer)
85
+ # This is an internal string and should not be modified or freed.
86
+ name_ptr = FFI::OGR::API.OGR_DS_GetName(@c_pointer)
87
+ name_ptr.autorelease = false
88
+
89
+ name_ptr.read_string_to_null
67
90
  end
68
91
 
69
92
  # @return [OGR::Driver]
@@ -74,16 +97,19 @@ module OGR
74
97
  OGR::Driver.new(driver_ptr)
75
98
  end
76
99
 
77
- # @return [Fixnum]
100
+ # @return [Integer]
78
101
  def layer_count
79
102
  FFI::OGR::API.OGR_DS_GetLayerCount(@c_pointer)
80
103
  end
81
104
 
82
- # @param index [Fixnum] 0-offset index of the layer to retrieve.
105
+ # @param index [Integer] 0-offset index of the layer to retrieve.
83
106
  # @return [OGR::Layer]
84
107
  def layer(index)
85
108
  @layers.fetch(index) do
109
+ # The returned layer remains owned by the OGRDataSource and should not be deleted by the application.
86
110
  layer_pointer = FFI::OGR::API.OGR_DS_GetLayer(@c_pointer, index)
111
+ layer_pointer.autorelease = false
112
+
87
113
  return nil if layer_pointer.null?
88
114
 
89
115
  l = OGR::Layer.new(layer_pointer)
@@ -96,7 +122,10 @@ module OGR
96
122
  # @param name [String]
97
123
  # @return [OGR::Layer]
98
124
  def layer_by_name(name)
125
+ # The returned layer remains owned by the OGRDataSource and should not be deleted by the application.
99
126
  layer_pointer = FFI::OGR::API.OGR_DS_GetLayerByName(@c_pointer, name)
127
+ layer_pointer.autorelease = false
128
+
100
129
  return nil if layer_pointer.null?
101
130
 
102
131
  OGR::Layer.new(layer_pointer)
@@ -109,13 +138,16 @@ module OGR
109
138
  # @param options [Hash] Driver-specific options.
110
139
  # @return [OGR::Layer]
111
140
  def create_layer(name, geometry_type: :wkbUnknown, spatial_reference: nil, **options)
112
- raise OGR::UnsupportedOperation, 'This data source does not support creating layers.' unless can_create_layer?
141
+ unless test_capability('CreateLayer')
142
+ raise OGR::UnsupportedOperation,
143
+ 'This data source does not support creating layers.'
144
+ end
113
145
 
114
- spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, spatial_reference) if spatial_reference
146
+ spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, spatial_reference, autorelease: false) if spatial_reference
115
147
  options_obj = GDAL::Options.pointer(options)
116
148
 
117
- layer_ptr = FFI::OGR::API.OGR_DS_CreateLayer(@c_pointer, name,
118
- spatial_ref_ptr, geometry_type, options_obj)
149
+ layer_ptr =
150
+ FFI::OGR::API.OGR_DS_CreateLayer(@c_pointer, name, spatial_ref_ptr, geometry_type, options_obj)
119
151
 
120
152
  raise OGR::InvalidLayer, "Unable to create layer '#{name}'." unless layer_ptr
121
153
 
@@ -133,20 +165,23 @@ module OGR
133
165
  options_ptr = GDAL::Options.pointer(options)
134
166
 
135
167
  layer_ptr = FFI::OGR::API.OGR_DS_CopyLayer(@c_pointer, source_layer_ptr,
136
- new_name, options_ptr)
168
+ new_name, options_ptr)
137
169
  return nil if layer_ptr.null?
138
170
 
139
171
  OGR::Layer.new(layer_ptr)
140
172
  end
141
173
 
142
- # @param index [Fixnum]
143
- # @return +true+ if successful, otherwise raises an OGR exception.
174
+ # @param index [Integer]
175
+ # @raise [OGR::Failure]
144
176
  def delete_layer(index)
145
- raise OGR::UnsupportedOperation, 'This data source does not support deleting layers.' unless can_delete_layer?
146
-
147
- ogr_err = FFI::OGR::API.OGR_DS_DeleteLayer(@c_pointer, index)
177
+ unless test_capability('DeleteLayer')
178
+ raise OGR::UnsupportedOperation,
179
+ 'This data source does not support deleting layers.'
180
+ end
148
181
 
149
- ogr_err.handle_result "Unable to delete layer #{index}"
182
+ OGR::ErrorHandling.handle_ogr_err("Unable to delete layer at index #{index}") do
183
+ FFI::OGR::API.OGR_DS_DeleteLayer(@c_pointer, index)
184
+ end
150
185
  end
151
186
 
152
187
  # @param command [String] The SQL to execute.
@@ -158,25 +193,21 @@ module OGR
158
193
  def execute_sql(command, spatial_filter = nil, dialect = nil)
159
194
  geometry_ptr = GDAL._pointer(OGR::Geometry, spatial_filter) if spatial_filter
160
195
 
161
- layer_ptr = FFI::OGR::API.OGR_DS_ExecuteSQL(@c_pointer, command, geometry_ptr,
162
- dialect)
196
+ layer_ptr = FFI::OGR::API.OGR_DS_ExecuteSQL(@c_pointer, command, geometry_ptr, dialect)
197
+ layer_ptr.autorelease = false
163
198
 
164
199
  return nil if layer_ptr.null?
165
200
 
166
- OGR::Layer.new(layer_ptr)
167
- end
168
-
169
- # Use to release the resulting data pointer from #execute_sql.
170
- #
171
- # @param layer [OGR::Layer, FFI::Pointer]
172
- def release_result_set(layer)
173
- layer_ptr = GDAL._pointer(OGR::Layer, layer)
174
- FFI::OGR::API.OGR_DS_ReleaseResultSet(@c_pointer, layer_ptr)
201
+ OGR::Layer.new(FFI::AutoPointer.new(layer_ptr, lambda { |ptr|
202
+ DataSource.release_result_set(@c_pointer, ptr)
203
+ }))
175
204
  end
176
205
 
177
206
  # @return [OGR::StyleTable, nil]
178
207
  def style_table
179
208
  style_table_ptr = FFI::OGR::API.OGR_DS_GetStyleTable(@c_pointer)
209
+ style_table_ptr.autorelease = false
210
+
180
211
  return nil if style_table_ptr.null?
181
212
 
182
213
  OGR::StyleTable.new(style_table_ptr)
@@ -203,11 +234,11 @@ module OGR
203
234
  FFI::OGR::API.OGR_DS_TestCapability(@c_pointer, capability)
204
235
  end
205
236
 
206
- # @return [Boolean]
237
+ # @raise [OGR::Failure]
207
238
  def sync_to_disk
208
- ogr_err = FFI::OGR::API.OGR_DS_SyncToDisk(@c_pointer)
209
-
210
- ogr_err.handle_result
239
+ OGR::ErrorHandling.handle_ogr_err('Unable to syn datasource to disk') do
240
+ FFI::OGR::API.OGR_DS_SyncToDisk(@c_pointer)
241
+ end
211
242
  end
212
243
  end
213
244
  end
data/lib/ogr/driver.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  require_relative '../ogr'
4
4
  require_relative '../gdal'
5
5
  require_relative '../gdal/major_object'
6
- require_relative 'driver_mixins/capability_methods'
7
6
 
8
7
  module OGR
9
8
  # Wrapper for OGR's Driver class. In this case, to use a driver, find the
@@ -14,9 +13,8 @@ module OGR
14
13
  class Driver
15
14
  include GDAL::MajorObject
16
15
  include GDAL::Logger
17
- include DriverMixins::CapabilityMethods
18
16
 
19
- # @return [Fixnum]
17
+ # @return [Integer]
20
18
  def self.count
21
19
  FFI::OGR::API.OGRGetDriverCount
22
20
  end
@@ -31,7 +29,7 @@ module OGR
31
29
  new(driver_ptr)
32
30
  end
33
31
 
34
- # @param index [Fixnum] Index of the registered driver. Must be less than
32
+ # @param index [Integer] Index of the registered driver. Must be less than
35
33
  # OGR::Driver.count.
36
34
  # @return [OGR::Driver]
37
35
  # @raise [OGR::DriverNotFound] if a driver at +index+ isn't found.
@@ -39,7 +37,6 @@ module OGR
39
37
  raise OGR::DriverNotFound, index if index > count
40
38
 
41
39
  driver_ptr = FFI::OGR::API.OGRGetDriver(index)
42
- return nil if driver_ptr.null?
43
40
  raise OGR::DriverNotFound, index if driver_ptr.null?
44
41
 
45
42
  new(driver_ptr)
@@ -63,7 +60,10 @@ module OGR
63
60
 
64
61
  # @return [String]
65
62
  def name
66
- FFI::OGR::API.OGR_Dr_GetName(@c_pointer)
63
+ name, ptr = FFI::OGR::API.OGR_Dr_GetName(@c_pointer)
64
+ ptr.autorelease = false
65
+
66
+ name
67
67
  end
68
68
 
69
69
  # @param file_name [String]
@@ -87,15 +87,15 @@ module OGR
87
87
  # @param options [Hash]
88
88
  # @return [OGR::DataSource, nil]
89
89
  def create_data_source(file_name, **options)
90
- unless can_create_data_source?
90
+ unless test_capability('CreateDataSource')
91
91
  raise OGR::UnsupportedOperation, 'This driver does not support data source creation.'
92
92
  end
93
93
 
94
94
  options_ptr = GDAL::Options.pointer(options)
95
95
 
96
96
  data_source_ptr = FFI::OGR::API.OGR_Dr_CreateDataSource(@c_pointer,
97
- file_name, options_ptr)
98
- return nil if data_source_ptr.null?
97
+ file_name, options_ptr)
98
+ raise OGR::CreateFailure, "Unable to create DataSource '#{file_name}'" if data_source_ptr.null?
99
99
 
100
100
  ds = OGR::DataSource.new(data_source_ptr, 'w')
101
101
  yield ds if block_given?
@@ -104,15 +104,15 @@ module OGR
104
104
  end
105
105
 
106
106
  # @param file_name [String]
107
- # @return +true+ if successful, otherwise raises an OGR exception.
107
+ # @raise [OGR::Failure]
108
108
  def delete_data_source(file_name)
109
- unless can_delete_data_source?
109
+ unless test_capability('DeleteDataSource')
110
110
  raise OGR::UnsupportedOperation, 'This driver does not support deleting data sources.'
111
111
  end
112
112
 
113
- ogr_err = FFI::OGR::API.OGR_Dr_DeleteDataSource(@c_pointer, file_name)
114
-
115
- ogr_err.handle_result
113
+ OGR::ErrorHandling.handle_ogr_err("Unable to delete data source '#{file_name}'") do
114
+ FFI::OGR::API.OGR_Dr_DeleteDataSource(@c_pointer, file_name)
115
+ end
116
116
  end
117
117
 
118
118
  # @param source_data_source [OGR::DataSource, FFI::Pointer]
@@ -126,9 +126,10 @@ module OGR
126
126
 
127
127
  options_ptr = GDAL::Options.pointer(options)
128
128
 
129
- data_source_ptr = FFI::OGR::API.OGR_Dr_CopyDataSource(@c_pointer,
130
- source_ptr, new_file_name, options_ptr)
131
- return nil if data_source_ptr.null?
129
+ data_source_ptr =
130
+ FFI::OGR::API.OGR_Dr_CopyDataSource(@c_pointer, source_ptr, new_file_name, options_ptr)
131
+
132
+ raise OGR::InvalidDataSource, "Unable to copy data source to #{new_file_name}" if data_source_ptr.null?
132
133
 
133
134
  OGR::DataSource.new(data_source_ptr, nil)
134
135
  end
data/lib/ogr/envelope.rb CHANGED
@@ -1,12 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../ogr'
4
- require_relative 'envelope_extensions'
5
4
 
6
5
  module OGR
7
6
  class Envelope
8
- include EnvelopeExtensions
9
-
10
7
  # @return [FFI::OGR::Envelope, FFI::OGR::Envelope3D] The C struct that this
11
8
  # object wraps.
12
9
  attr_reader :c_struct