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
@@ -10,8 +10,9 @@ module OGR
10
10
  datum_name = FFI::MemoryPointer.new(:string, 32)
11
11
  units = FFI::MemoryPointer.new(:string, 32)
12
12
 
13
- ogr_err = FFI::OGR::SRSAPI.OSRExportToERM(@c_pointer, projection_name, datum_name, units)
14
- ogr_err.handle_result 'Required parameters (name, datum name, units) are not defined'
13
+ OGR::ErrorHandling.handle_ogr_err('Required parameters (name, datum name, units) are not defined') do
14
+ FFI::OGR::SRSAPI.OSRExportToERM(@c_pointer, projection_name, datum_name, units)
15
+ end
15
16
 
16
17
  {
17
18
  projection_name: projection_name.read_string,
@@ -21,85 +22,120 @@ module OGR
21
22
  end
22
23
 
23
24
  # @return [Array<String>]
25
+ # @raise [OGR::Failure]
24
26
  def to_mapinfo
25
- return_ptr_ptr = GDAL._pointer_pointer(:string)
26
- ogr_err = FFI::OGR::SRSAPI.OSRExportToMICoordSys(@c_pointer, return_ptr_ptr)
27
- ogr_err.handle_result
28
-
29
- return_ptr_ptr.get_array_of_string(0)
27
+ GDAL._cpl_read_and_free_string do |return_ptr_ptr|
28
+ OGR::ErrorHandling.handle_ogr_err('Unable to export to MapInfo') do
29
+ FFI::OGR::SRSAPI.OSRExportToMICoordSys(@c_pointer, return_ptr_ptr)
30
+ end
31
+ end
30
32
  end
31
33
 
32
34
  # @return [Hash]
35
+ # @raise [OGR::Failure]
33
36
  def to_pci
34
- proj_ptr = GDAL._pointer_pointer(:string)
35
- units_ptr = GDAL._pointer_pointer(:string)
36
- prj_params_ptr = GDAL._pointer_pointer(:double)
37
+ proj_ptr_ptr = GDAL._pointer_pointer(:string)
38
+ proj_ptr_ptr.autorelease = false
39
+ units_ptr_ptr = GDAL._pointer_pointer(:string)
40
+ units_ptr_ptr.autorelease = false
41
+ prj_params_ptr_ptr = GDAL._pointer_pointer(:double)
42
+ prj_params_ptr_ptr.autorelease = false
43
+
44
+ OGR::ErrorHandling.handle_ogr_err('Unable to export to PCI') do
45
+ FFI::OGR::SRSAPI.OSRExportToPCI(@c_pointer, proj_ptr_ptr, units_ptr_ptr, prj_params_ptr_ptr)
46
+ end
47
+
48
+ projection = proj_ptr_ptr.read_pointer.read_string
49
+ units = units_ptr_ptr.read_pointer.read_string
50
+ projection_parameters = prj_params_ptr_ptr.read_array_of_double(0)
51
+
52
+ result = {
53
+ projection: projection,
54
+ units: units,
55
+ projection_parameters: projection_parameters
56
+ }
37
57
 
38
- ogr_err = FFI::OGR::SRSAPI.OSRExportToPCI(@c_pointer, proj_ptr, units_ptr, prj_params_ptr)
39
- ogr_err.handle_result
58
+ FFI::CPL::VSI.VSIFree(proj_ptr_ptr)
59
+ FFI::CPL::VSI.VSIFree(units_ptr_ptr)
60
+ FFI::CPL::VSI.VSIFree(prj_params_ptr_ptr)
40
61
 
41
- {
42
- projection: proj_ptr.read_pointer.read_string,
43
- units: units_ptr.read_pointer.read_string,
44
- projection_parameters: prj_params_ptr.read_array_of_double(0)
45
- }
62
+ result
46
63
  end
47
64
 
48
65
  # @return [String]
49
66
  # @raise [GDAL::UnsupportedOperation] If empty definition.
50
67
  def to_proj4
51
- proj4_ptr = GDAL._pointer_pointer(:string)
52
- ogr_err = FFI::OGR::SRSAPI.OSRExportToProj4(@c_pointer, proj4_ptr)
53
- ogr_err.handle_result
54
-
55
- GDAL._read_pointer_pointer_safely(proj4_ptr, :string)
68
+ GDAL._cpl_read_and_free_string do |proj4_ptr_ptr|
69
+ OGR::ErrorHandling.handle_ogr_err('Unable to export to PROJ.4') do
70
+ FFI::OGR::SRSAPI.OSRExportToProj4(@c_pointer, proj4_ptr_ptr)
71
+ end
72
+ end
56
73
  end
57
74
 
58
75
  # @return [Hash]
76
+ # @raise [OGR::Failure]
59
77
  def to_usgs
60
- proj_sys = FFI::MemoryPointer.new(:long)
61
- zone = FFI::MemoryPointer.new(:long)
62
- datum = FFI::MemoryPointer.new(:long)
63
- prj_params_ptr = GDAL._pointer_pointer(:double)
78
+ proj_sys_ptr = FFI::MemoryPointer.new(:long)
79
+ zone_ptr = FFI::MemoryPointer.new(:long)
80
+ datum_ptr = FFI::MemoryPointer.new(:long)
81
+ prj_params_ptr_ptr = GDAL._pointer_pointer(:double)
82
+ prj_params_ptr_ptr.autorelease = false
83
+
84
+ OGR::ErrorHandling.handle_ogr_err('Unable to export to USGS GCTP') do
85
+ FFI::OGR::SRSAPI.OSRExportToUSGS(@c_pointer, proj_sys_ptr, zone_ptr, prj_params_ptr_ptr, datum_ptr)
86
+ end
87
+
88
+ projection_system_code = proj_sy_ptrs.read_long
89
+ zone = zon_ptre.read_long
90
+ projection_parameters = prj_params_pt_ptrr.read_array_of_double(0)
91
+ datum = datu_ptrm.read_long
92
+
93
+ result = {
94
+ projection_system_code: projection_system_code,
95
+ zone: zone,
96
+ projection_parameters: projection_parameters,
97
+ datum: datum
98
+ }
64
99
 
65
- ogr_err = FFI::OGR::SRSAPI.OSRExportToUSGS(@c_pointer, proj_sys, zone, prj_params_ptr, datum)
66
- ogr_err.handle_result
100
+ FFI::CPL::VSI.VSIFree(prj_params_ptr_ptr)
67
101
 
68
- {
69
- projection_system_code: proj_sys.read_long,
70
- zone: zone.read_long,
71
- projection_parameters: prj_params_ptr.read_array_of_double(0),
72
- datum: datum.read_long
73
- }
102
+ result
74
103
  end
75
104
 
76
105
  # @return [String]
106
+ # @raise [OGR::Failure]
77
107
  def to_wkt
78
- wkt_ptr_ptr = GDAL._pointer_pointer(:string)
79
- ogr_err = FFI::OGR::SRSAPI.OSRExportToWkt(@c_pointer, wkt_ptr_ptr)
80
- ogr_err.handle_result
81
-
82
- GDAL._read_pointer_pointer_safely(wkt_ptr_ptr, :string)
108
+ GDAL._cpl_read_and_free_string do |wkt_ptr_ptr|
109
+ OGR::ErrorHandling.handle_ogr_err('Unable to export to WKT') do
110
+ FFI::OGR::SRSAPI.OSRExportToWkt(@c_pointer, wkt_ptr_ptr)
111
+ end
112
+ end
83
113
  end
84
114
 
85
115
  # @param simplify [Boolean] +true+ strips off +AXIS+, +AUTHORITY+ and
86
116
  # +EXTENSION+ nodes.
87
- def to_pretty_wkt(simplify = false)
88
- wkt_ptr_ptr = GDAL._pointer_pointer(:string)
89
- ogr_err = FFI::OGR::SRSAPI.OSRExportToPrettyWkt(@c_pointer, wkt_ptr_ptr, simplify)
90
- ogr_err.handle_result
91
-
92
- GDAL._read_pointer_pointer_safely(wkt_ptr_ptr, :string)
117
+ # @raise [OGR::Failure]
118
+ # @return [String]
119
+ def to_pretty_wkt(simplify: false)
120
+ return +'' if @c_pointer.null?
121
+
122
+ GDAL._cpl_read_and_free_string do |wkt_ptr_ptr|
123
+ OGR::ErrorHandling.handle_ogr_err('Unable to export to pretty WKT') do
124
+ FFI::OGR::SRSAPI.OSRExportToPrettyWkt(@c_pointer, wkt_ptr_ptr, simplify)
125
+ end
126
+ end
93
127
  end
94
128
 
95
129
  # @return [String]
96
- def to_xml(dialect = nil)
97
- xml_ptr_ptr = GDAL._pointer_pointer(:string)
98
- ogr_err = FFI::OGR::SRSAPI.OSRExportToXML(@c_pointer, xml_ptr_ptr, dialect)
99
- ogr_err.handle_result
100
-
101
- xml_ptr_ptr.get_array_of_string(0).join
130
+ # @raise [OGR::Failure]
131
+ def to_xml
132
+ GDAL._cpl_read_and_free_string do |xml_ptr_ptr|
133
+ OGR::ErrorHandling.handle_ogr_err('Unable to export to XML (GML)') do
134
+ FFI::OGR::SRSAPI.OSRExportToXML(@c_pointer, xml_ptr_ptr, nil)
135
+ end
136
+ end
102
137
  end
138
+ alias to_gml to_xml
103
139
  end
104
140
  end
105
141
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../error_handling'
4
+
3
5
  module OGR
4
6
  module SpatialReferenceMixins
5
7
  module Importers
@@ -8,7 +10,7 @@ module OGR
8
10
  end
9
11
 
10
12
  module ClassMethods
11
- # @param code [Fixnum]
13
+ # @param code [Integer]
12
14
  # @return [OGR::SpatialReference]
13
15
  def new_from_epsg(code)
14
16
  srs = new
@@ -17,11 +19,11 @@ module OGR
17
19
  srs
18
20
  end
19
21
 
20
- # @param code [Fixnum]
22
+ # @param code [Integer]
21
23
  # @return [OGR::SpatialReference]
22
24
  def new_from_epsga(code)
23
25
  srs = new
24
- srs.import_from_epsg(code)
26
+ srs.import_from_epsga(code)
25
27
 
26
28
  srs
27
29
  end
@@ -117,59 +119,81 @@ module OGR
117
119
  end
118
120
 
119
121
  # @return [OGR::SpatialReference]
122
+ # @raise [OGR::Failure]
120
123
  def build_spatial_ref(spatial_reference_or_wkt = nil)
121
124
  object = new(spatial_reference_or_wkt)
122
125
  ogr_err = yield object.c_pointer
123
- ogr_err.handle_result
126
+
127
+ OGR::ErrorHandling.handle_ogr_err('Unable to build SpatialReference') do
128
+ ogr_err
129
+ end
124
130
 
125
131
  object
126
132
  end
127
133
  end
128
134
 
129
- # @param code [Fixnum]
135
+ # @param code [Integer]
136
+ # @return [OGR::SpatialReference] `self`, but updated with the EPSG code.
130
137
  # @raise [GDAL::UnsupportedOperation] On unknown EPSG code.
131
138
  def import_from_epsg(code)
132
- ogr_err = FFI::OGR::SRSAPI.OSRImportFromEPSG(@c_pointer, code)
139
+ OGR::ErrorHandling.handle_ogr_err("Unable to import from EPSG: #{code}") do
140
+ FFI::OGR::SRSAPI.OSRImportFromEPSG(@c_pointer, code)
141
+ end
133
142
 
134
- ogr_err.handle_result
143
+ self
135
144
  end
136
145
 
137
- # @param code [Fixnum]
146
+ # @param code [Integer]
147
+ # @raise [OGR::Failure]
138
148
  def import_from_epsga(code)
139
- ogr_err = FFI::OGR::SRSAPI.OSRImportFromEPSGA(@c_pointer, code)
149
+ OGR::ErrorHandling.handle_ogr_err("Unable to import from EPSGA: #{code}") do
150
+ FFI::OGR::SRSAPI.OSRImportFromEPSGA(@c_pointer, code)
151
+ end
140
152
 
141
- ogr_err.handle_result
153
+ self
142
154
  end
143
155
 
144
156
  # @param wkt [String]
157
+ # @raise [OGR::Failure]
145
158
  def import_from_wkt(wkt)
146
159
  wkt_ptr = FFI::MemoryPointer.from_string(wkt)
147
160
  wkt_ptr_ptr = FFI::MemoryPointer.new(:pointer)
148
161
  wkt_ptr_ptr.write_pointer(wkt_ptr)
149
- ogr_err = FFI::OGR::SRSAPI.OSRImportFromWkt(@c_pointer, wkt_ptr_ptr)
150
162
 
151
- ogr_err.handle_result
163
+ OGR::ErrorHandling.handle_ogr_err("Unable to import from WKT: #{wkt}") do
164
+ FFI::OGR::SRSAPI.OSRImportFromWkt(@c_pointer, wkt_ptr_ptr)
165
+ end
166
+
167
+ self
152
168
  end
153
169
 
154
170
  # @param proj4 [String]
171
+ # @raise [OGR::Failure]
155
172
  def import_from_proj4(proj4)
156
- ogr_err = FFI::OGR::SRSAPI.OSRImportFromProj4(@c_pointer, proj4)
173
+ OGR::ErrorHandling.handle_ogr_err("Unable to import from PROJ.4: #{proj4}") do
174
+ FFI::OGR::SRSAPI.OSRImportFromProj4(@c_pointer, proj4)
175
+ end
157
176
 
158
- ogr_err.handle_result
177
+ self
159
178
  end
160
179
 
161
180
  # @param esri_text [Array<String>]
181
+ # @raise [OGR::Failure]
162
182
  def import_from_esri(esri_text)
163
183
  text_array = esri_text.split("\n")
164
184
  esri_ptr_ptr = GDAL._string_array_to_pointer(text_array)
165
- ogr_err = FFI::OGR::SRSAPI.OSRImportFromESRI(@c_pointer, esri_ptr_ptr)
166
185
 
167
- ogr_err.handle_result
186
+ OGR::ErrorHandling.handle_ogr_err("Unable to import from ESRI: #{esri_text}") do
187
+ FFI::OGR::SRSAPI.OSRImportFromESRI(@c_pointer, esri_ptr_ptr)
188
+ end
189
+
190
+ self
168
191
  end
169
192
 
170
193
  # @param proj [String]
171
194
  # @param units [String]
172
195
  # @param proj_params [Array<String>]
196
+ # @raise [OGR::Failure]
173
197
  def import_from_pci(proj, units, *proj_params)
174
198
  if proj_params.empty?
175
199
  proj_ptr = nil
@@ -178,15 +202,18 @@ module OGR
178
202
  proj_ptr.write_array_of_double(proj_params)
179
203
  end
180
204
 
181
- ogr_err = FFI::OGR::SRSAPI.OSRImportFromPCI(@c_pointer, proj, units, proj_ptr)
205
+ OGR::ErrorHandling.handle_ogr_err("Unable to import from PCI: #{proj}") do
206
+ FFI::OGR::SRSAPI.OSRImportFromPCI(@c_pointer, proj, units, proj_ptr)
207
+ end
182
208
 
183
- ogr_err.handle_result
209
+ self
184
210
  end
185
211
 
186
- # @param projection_system_code [Fixnum]
187
- # @param zone [Fixnum]
188
- # @param datum [Fixnum]
212
+ # @param projection_system_code [Integer]
213
+ # @param zone [Integer]
214
+ # @param datum [Integer]
189
215
  # @param proj_params [Array<Float>]
216
+ # @raise [OGR::Failure]
190
217
  def import_from_usgs(projection_system_code, zone, datum, *proj_params)
191
218
  if proj_params.empty?
192
219
  proj_ptr = nil
@@ -195,52 +222,70 @@ module OGR
195
222
  proj_ptr.write_array_of_double(proj_params)
196
223
  end
197
224
 
198
- ogr_err = FFI::OGR::SRSAPI.OSRImportFromUSGS(
199
- @c_pointer,
200
- projection_system_code,
201
- zone,
202
- proj_ptr,
203
- datum
204
- )
225
+ msg = "Unable to import from USGS: #{projection_system_code}, #{zone}, #{datum}, #{proj_params}"
205
226
 
206
- ogr_err.handle_result
227
+ OGR::ErrorHandling.handle_ogr_err(msg) do
228
+ FFI::OGR::SRSAPI.OSRImportFromUSGS(
229
+ @c_pointer,
230
+ projection_system_code,
231
+ zone,
232
+ proj_ptr,
233
+ datum
234
+ )
235
+ end
236
+
237
+ self
207
238
  end
208
239
 
209
240
  # Use for importing a GML coordinate system.
210
241
  #
211
242
  # @param xml [String]
243
+ # @raise [OGR::Failure]
212
244
  def import_from_xml(xml)
213
- ogr_err = FFI::OGR::SRSAPI.OSRImportFromXML(@c_pointer, xml)
245
+ OGR::ErrorHandling.handle_ogr_err("Unable to import from XML: #{xml}") do
246
+ FFI::OGR::SRSAPI.OSRImportFromXML(@c_pointer, xml)
247
+ end
214
248
 
215
- ogr_err.handle_result
249
+ self
216
250
  end
217
251
 
218
252
  # @param coord_sys [String] The Mapinfo style CoordSys definition string.
253
+ # @raise [OGR::Failure]
219
254
  def import_from_mapinfo(coord_sys)
220
- ogr_err = FFI::OGR::SRSAPI.OSRImportFromMICoordSys(@c_pointer, coord_sys)
255
+ OGR::ErrorHandling.handle_ogr_err("Unable to import from MapInfo: #{coord_sys}") do
256
+ FFI::OGR::SRSAPI.OSRImportFromMICoordSys(@c_pointer, coord_sys)
257
+ end
221
258
 
222
- ogr_err.handle_result
259
+ self
223
260
  end
224
261
 
225
262
  # @param projection_name [String] I.e. "NUTM11" or "GEOGRAPHIC".
226
263
  # @param datum_name [String] I.e. "NAD83".
227
264
  # @param linear_unit_name [String] Plural form of linear units, i.e. "FEET".
265
+ # @raise [OGR::Failure]
228
266
  def import_from_erm(projection_name, datum_name, linear_unit_name)
229
- ogr_err = FFI::OGR::SRSAPI.OSRImportFromERM(
230
- @c_pointer,
231
- projection_name,
232
- datum_name,
233
- linear_unit_name
234
- )
235
-
236
- ogr_err.handle_result
267
+ msg = "Unable to import from ERMapper: #{projection_name}, #{datum_name}, #{linear_unit_name}"
268
+
269
+ OGR::ErrorHandling.handle_ogr_err(msg) do
270
+ FFI::OGR::SRSAPI.OSRImportFromERM(
271
+ @c_pointer,
272
+ projection_name,
273
+ datum_name,
274
+ linear_unit_name
275
+ )
276
+ end
277
+
278
+ self
237
279
  end
238
280
 
239
281
  # @param url [String] URL to fetch the spatial reference from.
282
+ # @raise [OGR::Failure]
240
283
  def import_from_url(url)
241
- ogr_err = FFI::OGR::SRSAPI.OSRImportFromUrl(@c_pointer, url)
284
+ OGR::ErrorHandling.handle_ogr_err("Unable to import from URL: #{url}") do
285
+ FFI::OGR::SRSAPI.OSRImportFromUrl(@c_pointer, url)
286
+ end
242
287
 
243
- ogr_err.handle_result
288
+ self
244
289
  end
245
290
  end
246
291
  end
@@ -5,22 +5,26 @@ module OGR
5
5
  module Morphers
6
6
  # Converts, in place, to ESRI WKT format.
7
7
  #
8
- # @return [OGR::SpatialReference, false] If successful, returns self.
8
+ # @return [OGR::SpatialReference] If successful, returns self.
9
+ # @raise [OGR::Failure]
9
10
  def morph_to_esri!
10
- ogr_err = FFI::OGR::SRSAPI.OSRMorphToESRI(@c_pointer)
11
- result = ogr_err.handle_result
11
+ OGR::ErrorHandling.handle_ogr_err('Unable to morph self to ESRI') do
12
+ FFI::OGR::SRSAPI.OSRMorphToESRI(@c_pointer)
13
+ end
12
14
 
13
- result ? self : result
15
+ self
14
16
  end
15
17
 
16
18
  # Converts, in place, from ESRI WKT format.
17
19
  #
18
- # @return [OGR::SpatialReference, false] If successful, returns self.
20
+ # @return [OGR::SpatialReference] If successful, returns self.
21
+ # @raise [OGR::Failure]
19
22
  def morph_from_esri!
20
- ogr_err = FFI::OGR::SRSAPI.OSRMorphFromESRI(@c_pointer)
21
- result = ogr_err.handle_result
23
+ OGR::ErrorHandling.handle_ogr_err('Unable to morph self from ESRI') do
24
+ FFI::OGR::SRSAPI.OSRMorphFromESRI(@c_pointer)
25
+ end
22
26
 
23
- result ? self : result
27
+ self
24
28
  end
25
29
  end
26
30
  end
@@ -4,7 +4,7 @@ module OGR
4
4
  module SpatialReferenceMixins
5
5
  module ParameterGetterSetters
6
6
  # @param name [String] The case-insensitive tree node to look for.
7
- # @param child [Fixnum] The child of the node to fetch.
7
+ # @param child [Integer] The child of the node to fetch.
8
8
  # @return [String, nil]
9
9
  def attribute_value(name, child = 0)
10
10
  FFI::OGR::SRSAPI.OSRGetAttrValue(@c_pointer, name, child)
@@ -14,10 +14,11 @@ module OGR
14
14
  # pipe symbol to denote nesting. i.e. 'GEOCCS|UNIT'.
15
15
  # @param value [String] The new value for the node/path. Should be a String,
16
16
  # but if not, will be converted for you.
17
+ # @raise [OGR::Failure]
17
18
  def set_attribute_value(path, value)
18
- ogr_err = FFI::OGR::SRSAPI.OSRSetAttrValue(@c_pointer, path, value.to_s)
19
-
20
- ogr_err.handle_result
19
+ OGR::ErrorHandling.handle_ogr_err("Unable to set attribute (#{path}) to value #{value}") do
20
+ FFI::OGR::SRSAPI.OSRSetAttrValue(@c_pointer, path, value.to_s)
21
+ end
21
22
  end
22
23
 
23
24
  # @return [Hash{unit_name: String, value: Float}] +unit_name+ is the name
@@ -33,10 +34,13 @@ module OGR
33
34
  # @param unit_label [String]
34
35
  # @param transform_to_radians [Float] The value to multiply an angle to
35
36
  # transform the value to radians.
37
+ # @raise [OGR::Failure]
36
38
  def set_angular_units(unit_label, transform_to_radians)
37
- ogr_err = FFI::OGR::SRSAPI.OSRSetAngularUnits(@c_pointer, unit_label, transform_to_radians.to_f)
39
+ msg = "Unable to set angular units to #{unit_label} (transform to radians? #{transform_to_radians})"
38
40
 
39
- ogr_err.handle_result
41
+ OGR::ErrorHandling.handle_ogr_err(msg) do
42
+ FFI::OGR::SRSAPI.OSRSetAngularUnits(@c_pointer, unit_label, transform_to_radians.to_f)
43
+ end
40
44
  end
41
45
 
42
46
  # @return [Hash{unit_name: String, value: Float}] +unit_name+ is the name
@@ -52,10 +56,13 @@ module OGR
52
56
  # @param unit_label [String]
53
57
  # @param transform_to_meters [Float] The value to multiply a length to
54
58
  # transform the value to meters.
59
+ # @raise [OGR::Failure]
55
60
  def set_linear_units(unit_label, transform_to_meters)
56
- ogr_err = FFI::OGR::SRSAPI.OSRSetLinearUnits(@c_pointer, unit_label, transform_to_meters.to_f)
61
+ msg = "Unable to set linear units to #{unit_label} (transform to meters? #{transform_to_meters})"
57
62
 
58
- ogr_err.handle_result
63
+ OGR::ErrorHandling.handle_ogr_err(msg) do
64
+ FFI::OGR::SRSAPI.OSRSetLinearUnits(@c_pointer, unit_label, transform_to_meters.to_f)
65
+ end
59
66
  end
60
67
 
61
68
  # Does the same as #set_linear_units, but also converts parameters to use
@@ -64,11 +71,14 @@ module OGR
64
71
  # @param unit_label [String]
65
72
  # @param transform_to_meters [Float] The value to multiply a length to
66
73
  # transform the value to meters.
74
+ # @raise [OGR::Failure]
67
75
  def set_linear_units_and_update_parameters(unit_label, transform_to_meters)
68
- ogr_err = FFI::OGR::SRSAPI.OSRSetLinearUnitsAndUpdateParameters(@c_pointer, unit_label,
69
- transform_to_meters.to_f)
76
+ msg = "Unable to set linear units to #{unit_label} (transform to meters? #{transform_to_meters}) and update" \
77
+ 'parameters'
70
78
 
71
- ogr_err.handle_result
79
+ OGR::ErrorHandling.handle_ogr_err(msg) do
80
+ FFI::OGR::SRSAPI.OSRSetLinearUnitsAndUpdateParameters(@c_pointer, unit_label, transform_to_meters.to_f)
81
+ end
72
82
  end
73
83
 
74
84
  # The linear units for the projection.
@@ -87,10 +97,14 @@ module OGR
87
97
  # @param unit_label [String] Name of the units to be used.
88
98
  # @param transform_to_meters [Float] The value to multiple a length to
89
99
  # transform the value to meters.
100
+ # @raise [OGR::Failure]
90
101
  def set_target_linear_units(target_key, unit_label, transform_to_meters)
91
- ogr_err = FFI::OGR::SRSAPI.OSRSetTargetLinearUnits(@c_pointer, target_key, unit_label, transform_to_meters)
102
+ msg = "Unable to set target (#{target_key}) linear units to #{unit_label} " \
103
+ "(transform to meters? #{transform_to_meters})"
92
104
 
93
- ogr_err.handle_result
105
+ OGR::ErrorHandling.handle_ogr_err(msg) do
106
+ FFI::OGR::SRSAPI.OSRSetTargetLinearUnits(@c_pointer, target_key, unit_label, transform_to_meters)
107
+ end
94
108
  end
95
109
 
96
110
  # @return [Hash]
@@ -1,26 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../gdal'
3
4
  require_relative '../ogr'
4
- require_relative 'style_table_extensions'
5
5
 
6
6
  module OGR
7
7
  class StyleTable
8
- include StyleTableExtensions
8
+ # @param pointer [FFI::Pointer]
9
+ def self.release(pointer)
10
+ return unless pointer && !pointer.null?
11
+
12
+ FFI::OGR::API.OGR_STBL_Destroy(pointer)
13
+ end
9
14
 
10
15
  # @return [FFI::Pointer] C pointer to the C style table.
11
16
  attr_reader :c_pointer
12
17
 
13
18
  # @param [FFI::Pointer] c_pointer
14
19
  def initialize(c_pointer = nil)
15
- @c_pointer = c_pointer ? c_pointer : FFI::OGR::API.OGR_STBL_Create
20
+ @c_pointer = if c_pointer
21
+ c_pointer
22
+ else
23
+ pointer = FFI::OGR::API.OGR_STBL_Create
24
+ pointer.autorelease = false
25
+ FFI::AutoPointer.new(pointer, StyleTable.method(:release))
26
+ end
16
27
 
17
28
  raise 'Unable to create StyleTable' if @c_pointer.null?
18
29
  end
19
30
 
20
31
  def destroy!
21
- return unless @c_pointer
32
+ StyleTable.release(@c_pointer)
22
33
 
23
- FFI::OGR::API.OGR_STBL_Destroy(@c_pointer)
24
34
  @c_pointer = nil
25
35
  end
26
36