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
@@ -2,7 +2,6 @@
2
2
 
3
3
  require_relative '../ogr'
4
4
  require_relative '../gdal'
5
- require_relative 'spatial_reference_extensions'
6
5
  require_relative 'spatial_reference_mixins/coordinate_system_getter_setters'
7
6
  require_relative 'spatial_reference_mixins/exporters'
8
7
  require_relative 'spatial_reference_mixins/importers'
@@ -16,7 +15,6 @@ module OGR
16
15
  # 2. "projected", where positions are measure in meters or feet.
17
16
  class SpatialReference
18
17
  include GDAL::Logger
19
- include SpatialReferenceExtensions
20
18
  include SpatialReferenceMixins::CoordinateSystemGetterSetters
21
19
  include SpatialReferenceMixins::Exporters
22
20
  include SpatialReferenceMixins::Importers
@@ -37,8 +35,9 @@ module OGR
37
35
 
38
36
  RADIAN_TO_RADIAN = 1.0
39
37
 
38
+ # @deprecated This was removed in GDAL 3.0.
40
39
  # @return [Array<String>]
41
- def self.projection_methods(strip_underscores = false)
40
+ def self.projection_methods(strip_underscores: false)
42
41
  methods_ptr_ptr = FFI::OGR::SRSAPI.OPTGetProjectionMethods
43
42
  count = FFI::CPL::String.CSLCount(methods_ptr_ptr)
44
43
 
@@ -50,6 +49,7 @@ module OGR
50
49
  strip_underscores ? list.map! { |l| l.tr('_', ' ') } : list
51
50
  end
52
51
 
52
+ # @deprecated This was removed in GDAL 3.0.
53
53
  # @param projection_method [String] One of
54
54
  # OGR::SpatialReference.projection_methods.
55
55
  # @return [Hash{parameter => Array<String>, user_visible_name => String}]
@@ -70,6 +70,7 @@ module OGR
70
70
 
71
71
  # Fetch info about a single parameter of a projection method.
72
72
  #
73
+ # @deprecated This was removed in GDAL 3.0.
73
74
  # @param projection_method [String]
74
75
  # @param parameter_name [String]
75
76
  def self.parameter_info(projection_method, parameter_name)
@@ -78,7 +79,7 @@ module OGR
78
79
  default_value_ptr = FFI::MemoryPointer.new(:double)
79
80
 
80
81
  result = FFI::OGR::SRSAPI.OPTGetParameterInfo(projection_method, parameter_name,
81
- name_ptr_ptr, type_ptr_ptr, default_value_ptr)
82
+ name_ptr_ptr, type_ptr_ptr, default_value_ptr)
82
83
 
83
84
  return {} unless result
84
85
 
@@ -103,39 +104,75 @@ module OGR
103
104
  FFI::OGR::SRSAPI.OSRCleanup
104
105
  end
105
106
 
107
+ # This static method will destroy a OGRSpatialReference. It is equivalent
108
+ # to calling delete on the object, but it ensures that the deallocation is
109
+ # properly executed within the OGR libraries heap on platforms where this
110
+ # can matter (win32).
111
+ #
112
+ # @param pointer [FFI::Pointer]
113
+ def self.destroy(pointer)
114
+ return unless pointer && !pointer.null?
115
+
116
+ FFI::OGR::SRSAPI.OSRDestroySpatialReference(pointer)
117
+ end
118
+
119
+ # Decrements the reference count by one, and destroy if zero.
120
+ #
121
+ # @param pointer [FFI::Pointer]
122
+ def self.release(pointer)
123
+ return unless pointer && !pointer.null?
124
+
125
+ FFI::OGR::SRSAPI.OSRRelease(pointer)
126
+ end
127
+
106
128
  # @return [FFI::Pointer] C pointer to the C Spatial Reference.
107
129
  attr_reader :c_pointer
108
130
 
109
131
  # Builds a spatial reference object using either the passed-in WKT string,
110
132
  # OGR::SpatialReference object, or a pointer to an in-memory
111
- # SpatialReference object. If nothing is passed in, an empty
133
+ # SpatialReference object. If nothing is passed in, an empty
112
134
  # SpatialReference object is created, in which case you'll need to populate
113
135
  # relevant attributes.
114
136
  #
115
- # @param spatial_reference_or_wkt [OGR::SpatialReference, FFI::Pointer,
116
- # String]
137
+ # If a OGR::SpatialReference is given, this clones that object so it can
138
+ # have it's own object (relevant for cleaning up when garbage collecting).
139
+ #
140
+ # @param spatial_reference_or_wkt [OGR::SpatialReference, FFI::Pointer, String]
117
141
  def initialize(spatial_reference_or_wkt = nil)
118
- @c_pointer =
142
+ pointer =
119
143
  case spatial_reference_or_wkt.class.name
120
144
  when 'OGR::SpatialReference'
121
- spatial_reference_or_wkt.c_pointer
145
+ # This is basically getting a reference to the SpatialReference that
146
+ # was passed in, thus when this SpatialReference gets garbage-collected,
147
+ # it shouldn't release anything.
148
+ ptr = spatial_reference_or_wkt.c_pointer
149
+ ptr.autorelease = false
122
150
  when 'String', 'NilClass'
123
- FFI::OGR::SRSAPI.OSRNewSpatialReference(spatial_reference_or_wkt)
124
- when 'FFI::Pointer', 'FFI::MemoryPointer'
151
+ # FWIW, the docs say:
152
+ # Note that newly created objects are given a reference count of one.
153
+ #
154
+ # ...which implies that we should use Release here instead of Destroy.
155
+ ptr = FFI::OGR::SRSAPI.OSRNewSpatialReference(spatial_reference_or_wkt)
156
+ ptr.autorelease = false
157
+
158
+ # We're instantiating a new SR, so we can use .destroy.
159
+ FFI::AutoPointer.new(ptr, SpatialReference.method(:release))
160
+ when 'FFI::AutoPointer', 'FFI::Pointer', 'FFI::MemoryPointer'
161
+ # If we got a pointer, we don't know who owns the data, so don't
162
+ # touch anything about autorelease/AutoPointer.
125
163
  spatial_reference_or_wkt
126
164
  else
127
- log "Dunno what to do with #{spatial_reference_or_wkt}"
165
+ log "Dunno what to do with #{spatial_reference_or_wkt.inspect}"
128
166
  end
129
167
 
130
- return if @c_pointer && !@c_pointer.null?
168
+ raise OGR::CreateFailure, 'Unable to create SpatialReference.' if pointer.nil? || pointer.null?
131
169
 
132
- raise OGR::CreateFailure, 'Unable to create SpatialReference.'
170
+ @c_pointer = pointer
133
171
  end
134
172
 
135
173
  def destroy!
136
- return unless @c_pointer
174
+ SpatialReference.destroy(@c_pointer)
137
175
 
138
- FFI::OGR::SRSAPI.OSRDestroySpatialReference(@c_pointer)
139
176
  @c_pointer = nil
140
177
  end
141
178
 
@@ -145,7 +182,7 @@ module OGR
145
182
  def clone
146
183
  new_spatial_ref_ptr = FFI::OGR::SRSAPI.OSRClone(@c_pointer)
147
184
 
148
- self.class.new(new_spatial_ref_ptr)
185
+ SpatialReference.new(new_spatial_ref_ptr)
149
186
  end
150
187
 
151
188
  # Makes a duplicate of the GEOGCS node of this spatial reference.
@@ -154,58 +191,58 @@ module OGR
154
191
  def clone_geog_cs
155
192
  new_spatial_ref_ptr = FFI::OGR::SRSAPI.OSRCloneGeogCS(@c_pointer)
156
193
 
157
- self.class.new(new_spatial_ref_ptr)
194
+ SpatialReference.new(new_spatial_ref_ptr)
158
195
  end
159
196
 
160
197
  # @param other_spatial_ref [OGR::SpatialReference] The SpatialReference to
161
198
  # copy GeocCS info from.
162
- # @return [Boolean]
199
+ # @raise [OGR::Failure]
163
200
  def copy_geog_cs_from(other_spatial_ref)
164
201
  other_spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, other_spatial_ref)
165
202
  raise OGR::InvalidSpatialReference if other_spatial_ref_ptr.nil? || other_spatial_ref_ptr.null?
166
203
 
167
- ogr_err = FFI::OGR::SRSAPI.OSRCopyGeogCSFrom(@c_pointer, other_spatial_ref_ptr)
168
-
169
- ogr_err.handle_result
204
+ OGR::ErrorHandling.handle_ogr_err('Unable to copy GEOGCS') do
205
+ FFI::OGR::SRSAPI.OSRCopyGeogCSFrom(@c_pointer, other_spatial_ref_ptr)
206
+ end
170
207
  end
171
208
 
172
- # @return +true+ if successful, otherwise raises an OGR exception.
209
+ # @raise [OGR::Failure]
173
210
  def validate
174
- ogr_err = FFI::OGR::SRSAPI.OSRValidate(@c_pointer)
175
-
176
- ogr_err.handle_result
211
+ OGR::ErrorHandling.handle_ogr_err('Unable to validate') do
212
+ FFI::OGR::SRSAPI.OSRValidate(@c_pointer)
213
+ end
177
214
  end
178
215
 
179
- # @return +true+ if successful, otherwise raises an OGR exception.
216
+ # @raise [OGR::Failure]
180
217
  def fixup_ordering!
181
- ogr_err = FFI::OGR::SRSAPI.OSRFixupOrdering(@c_pointer)
182
-
183
- ogr_err.handle_result
218
+ OGR::ErrorHandling.handle_ogr_err('Unable to fixup ordering') do
219
+ FFI::OGR::SRSAPI.OSRFixupOrdering(@c_pointer)
220
+ end
184
221
  end
185
222
 
186
- # @return +true+ if successful, otherwise raises an OGR exception.
223
+ # @raise [OGR::Failure]
187
224
  def fixup!
188
- ogr_err = FFI::OGR::SRSAPI.OSRFixup(@c_pointer)
189
-
190
- ogr_err.handle_result
225
+ OGR::ErrorHandling.handle_ogr_err('Unable to fixup') do
226
+ FFI::OGR::SRSAPI.OSRFixup(@c_pointer)
227
+ end
191
228
  end
192
229
 
193
230
  # Strips all OGC coordinate transformation parameters.
194
231
  #
195
- # @return +true+ if successful, otherwise raises an OGR exception.
232
+ # @raise [OGR::Failure]
196
233
  def strip_ct_parameters!
197
- ogr_err = FFI::OGR::SRSAPI.OSRStripCTParms(@c_pointer)
198
-
199
- ogr_err.handle_result
234
+ OGR::ErrorHandling.handle_ogr_err('Unable to strip coordinate transformation parameters') do
235
+ FFI::OGR::SRSAPI.OSRStripCTParms(@c_pointer)
236
+ end
200
237
  end
201
238
 
202
239
  # Sets the EPSG authority info if possible.
203
240
  #
204
- # @return +true+ if successful, otherwise raises an OGR exception.
241
+ # @raise [OGR::Failure]
205
242
  def auto_identify_epsg!
206
- ogr_err = FFI::OGR::SRSAPI.OSRAutoIdentifyEPSG(@c_pointer)
207
-
208
- ogr_err.handle_result 'Unable to determine SRS from EPSG'
243
+ OGR::ErrorHandling.handle_ogr_err('Unable to determine SRS from EPSG') do
244
+ FFI::OGR::SRSAPI.OSRAutoIdentifyEPSG(@c_pointer)
245
+ end
209
246
  end
210
247
 
211
248
  # @return [Boolean] +true+ if this coordinate system should be treated as
@@ -6,63 +6,65 @@ module OGR
6
6
  # Set the user-visible LOCAL_CS name.
7
7
  #
8
8
  # @param name [String]
9
- # @return +true+ if successful, otherwise raises an OGR exception.
10
- def set_local_cs(name)
11
- ogr_err = FFI::OGR::SRSAPI.OSRSetLocalCS(@c_pointer, name)
12
-
13
- ogr_err.handle_result
9
+ # @raise [OGR::Failure]
10
+ def set_local_cs(name) # rubocop:disable Naming/AccessorMethodName
11
+ OGR::ErrorHandling.handle_ogr_err("Unable to set LOCAL_CS to '#{name}'") do
12
+ FFI::OGR::SRSAPI.OSRSetLocalCS(@c_pointer, name)
13
+ end
14
14
  end
15
15
  alias local_cs= set_local_cs
16
16
 
17
17
  # Set the user-visible PROJCS name.
18
18
  #
19
19
  # @param name [String]
20
- # @return +true+ if successful, otherwise raises an OGR exception.
21
- def set_proj_cs(name)
22
- ogr_err = FFI::OGR::SRSAPI.OSRSetProjCS(@c_pointer, name)
23
-
24
- ogr_err.handle_result
20
+ # @raise [OGR::Failure]
21
+ def set_proj_cs(name) # rubocop:disable Naming/AccessorMethodName
22
+ OGR::ErrorHandling.handle_ogr_err("Unable to set PROJCS to '#{name}'") do
23
+ FFI::OGR::SRSAPI.OSRSetProjCS(@c_pointer, name)
24
+ end
25
25
  end
26
26
  alias proj_cs= set_proj_cs
27
27
 
28
28
  # Set the user-visible PROJCS name.
29
29
  #
30
30
  # @param name [String]
31
- # @return +true+ if successful, otherwise raises an OGR exception.
32
- def set_geoc_cs(name)
33
- ogr_err = FFI::OGR::SRSAPI.OSRSetGeocCS(@c_pointer, name)
34
-
35
- ogr_err.handle_result
31
+ # @raise [OGR::Failure]
32
+ def set_geoc_cs(name) # rubocop:disable Naming/AccessorMethodName
33
+ OGR::ErrorHandling.handle_ogr_err("Unable to set GEOCCS to '#{name}'") do
34
+ FFI::OGR::SRSAPI.OSRSetGeocCS(@c_pointer, name)
35
+ end
36
36
  end
37
37
  alias geoc_cs= set_geoc_cs
38
38
 
39
39
  # Set the GEOGCS based on a well-known name.
40
40
  #
41
41
  # @param name [String]
42
- # @return +true+ if successful, otherwise raises an OGR exception.
43
- # @raise [NotImplementedError] If your version of GDAL/OGR doesn't define
44
- # the C function needed for this.
45
- def set_well_known_geog_cs(name)
46
- ogr_err = FFI::OGR::SRSAPI.OSRSetWellKnownGeogCS(@c_pointer, name)
47
-
48
- ogr_err.handle_result
42
+ # @raise [OGR::Failure]
43
+ def set_well_known_geog_cs(name) # rubocop:disable Naming/AccessorMethodName
44
+ OGR::ErrorHandling.handle_ogr_err("Unable to set GEOGCS to '#{name}'") do
45
+ FFI::OGR::SRSAPI.OSRSetWellKnownGeogCS(@c_pointer, name)
46
+ end
49
47
  end
50
48
  alias well_known_geog_cs= set_well_known_geog_cs
51
49
 
52
50
  # @param definition [String]
53
- def set_from_user_input(definition)
54
- ogr_err = FFI::OGR::SRSAPI.OSRSetFromUserInput(@c_pointer, definition)
55
-
56
- ogr_err.handle_result 'Invalid projection info given.'
51
+ # @raise [OGR::Failure]
52
+ def set_from_user_input(definition) # rubocop:disable Naming/AccessorMethodName
53
+ OGR::ErrorHandling.handle_ogr_err('Invalid projection info given.') do
54
+ FFI::OGR::SRSAPI.OSRSetFromUserInput(@c_pointer, definition)
55
+ end
57
56
  end
58
57
 
59
58
  # @return [Array<Float>]
59
+ # @raise [OGR::Failure]
60
60
  def towgs84
61
61
  coefficients = FFI::MemoryPointer.new(:double, 7)
62
- ogr_err = FFI::OGR::SRSAPI.OSRGetTOWGS84(@c_pointer, coefficients, 7)
63
- ogr_err.handle_result
64
62
 
65
- coefficients.read_array_of_double(0)
63
+ OGR::ErrorHandling.handle_ogr_err('No TOWGS84 node available') do
64
+ FFI::OGR::SRSAPI.OSRGetTOWGS84(@c_pointer, coefficients, 7)
65
+ end
66
+
67
+ coefficients.get_array_of_double(0, 7)
66
68
  end
67
69
 
68
70
  # @param x_distance [Float] (In meters.)
@@ -72,37 +74,38 @@ module OGR
72
74
  # @param y_rotation [Float] (In arc seconds.)
73
75
  # @param z_rotation [Float] (In arc seconds.)
74
76
  # @param scaling_factor [Float] (In parts-per-million.)
75
- def set_towgs84(x_distance: nil, y_distance: nil, z_distance: nil,
77
+ # @raise [OGR::Failure]
78
+ def set_towgs84(x_distance: nil, y_distance: nil, z_distance: 0.0,
76
79
  x_rotation: 0.0, y_rotation: 0.0, z_rotation: 0.0, scaling_factor: 0.0)
77
- ogr_err = FFI::OGR::SRSAPI.OSRSetTOWGS84(
78
- @c_pointer,
79
- x_distance, y_distance, z_distance,
80
- x_rotation, y_rotation, z_rotation,
81
- scaling_factor
82
- )
83
-
84
- ogr_err.handle_result
80
+ OGR::ErrorHandling.handle_ogr_err('No existing DATUM node') do
81
+ FFI::OGR::SRSAPI.OSRSetTOWGS84(
82
+ @c_pointer,
83
+ x_distance, y_distance, z_distance,
84
+ x_rotation, y_rotation, z_rotation,
85
+ scaling_factor
86
+ )
87
+ end
85
88
  end
86
89
 
87
90
  # @param name [String]
88
91
  # @param horizontal_spatial_ref [OGR::SpatialReference] (a PROJCS or GEOGCS)
89
92
  # @param vertical_spatial_ref [OGR::SpatialReference] (a VERT_CS)
90
- # @return [Boolean]
93
+ # @raise [OGR::Failure]
91
94
  def set_compound_cs(name, horizontal_spatial_ref, vertical_spatial_ref)
92
95
  horizontal_spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, horizontal_spatial_ref)
93
96
  vertical_spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, vertical_spatial_ref)
94
97
 
95
- ogr_err = FFI::OGR::SRSAPI.OSRSetCompoundCS(
96
- @c_pointer,
97
- name,
98
- horizontal_spatial_ref_ptr,
99
- vertical_spatial_ref_ptr
100
- )
101
-
102
- ogr_err.handle_result
98
+ OGR::ErrorHandling.handle_ogr_err("Unable to set compound CS '#{name}'") do
99
+ FFI::OGR::SRSAPI.OSRSetCompoundCS(
100
+ @c_pointer,
101
+ name,
102
+ horizontal_spatial_ref_ptr,
103
+ vertical_spatial_ref_ptr
104
+ )
105
+ end
103
106
  end
104
107
 
105
- # Set the user-visible GEOCCS name.
108
+ # Set the user-visible GEOGCS name.
106
109
  #
107
110
  # @param [String] geog_name
108
111
  # @param [String] datum_name
@@ -113,18 +116,18 @@ module OGR
113
116
  # @param [Double] offset
114
117
  # @param [String] angular_unit_label
115
118
  # @param [Float] transform_to_radians
116
- # @return +true+ if successful, otherwise raises an OGR exception.
119
+ # @raise [OGR::Failure]
117
120
  def set_geog_cs(geog_name, datum_name, spheroid_name, semi_major, spheroid_inverse_flattening,
118
121
  prime_meridian, offset, angular_unit_label, transform_to_radians)
119
- ogr_err = FFI::OGR::SRSAPI.OSRSetGeogCS(
120
- @c_pointer,
121
- geog_name, datum_name, spheroid_name,
122
- semi_major, spheroid_inverse_flattening,
123
- prime_meridian, offset,
124
- angular_unit_label, transform_to_radians
125
- )
126
-
127
- ogr_err.handle_result
122
+ OGR::ErrorHandling.handle_ogr_err("Unable to set GEOGCS '#{name}'") do
123
+ FFI::OGR::SRSAPI.OSRSetGeogCS(
124
+ @c_pointer,
125
+ geog_name, datum_name, spheroid_name,
126
+ semi_major, spheroid_inverse_flattening,
127
+ prime_meridian, offset,
128
+ angular_unit_label, transform_to_radians
129
+ )
130
+ end
128
131
  end
129
132
 
130
133
  # Set the vertical coordinate system.
@@ -132,11 +135,12 @@ module OGR
132
135
  # @param name [String] User-visible name of the CS.
133
136
  # @param datum_name [String] User-visible name of the datum. It's helpful
134
137
  # to have this match the EPSG name.
135
- # @param datum_type [String] The OGC datum type, usually 2005.
138
+ # @param datum_type [Integer] The OGC datum type, usually 2005.
139
+ # @raise [OGR::Failure]
136
140
  def set_vert_cs(name, datum_name, datum_type)
137
- ogr_err = FFI::OGR::SRSAPI.OSRSetVertCS(@c_pointer, name, datum_name, datum_type)
138
-
139
- ogr_err.handle_result
141
+ OGR::ErrorHandling.handle_ogr_err("Unable to set vertical CS '#{name}'") do
142
+ FFI::OGR::SRSAPI.OSRSetVertCS(@c_pointer, name, datum_name, datum_type)
143
+ end
140
144
  end
141
145
 
142
146
  # @param return_wgs84_on_nil [Boolean] The C-API gives you the option to
@@ -144,7 +148,7 @@ module OGR
144
148
  # semi-major is found. If set to +true+, this will return that value if
145
149
  # the semi-major isn't found.
146
150
  # @return [Float]
147
- def semi_major(return_wgs84_on_nil = false)
151
+ def semi_major(return_wgs84_on_nil: false)
148
152
  err_ptr = FFI::MemoryPointer.new(:int)
149
153
  value = FFI::OGR::SRSAPI.OSRGetSemiMajor(@c_pointer, err_ptr)
150
154
  ogr_err = FFI::OGR::Core::Err[err_ptr.read_int]
@@ -158,7 +162,7 @@ module OGR
158
162
  # semi-major is found. If set to +true+, this will return that value if
159
163
  # the semi-major isn't found.
160
164
  # @return [Float]
161
- def semi_minor(return_wgs84_on_nil = false)
165
+ def semi_minor(return_wgs84_on_nil: false)
162
166
  err_ptr = FFI::MemoryPointer.new(:int)
163
167
  value = FFI::OGR::SRSAPI.OSRGetSemiMinor(@c_pointer, err_ptr)
164
168
  ogr_err = FFI::OGR::Core::Err[err_ptr.read_int]
@@ -172,7 +176,7 @@ module OGR
172
176
  # if no semi-major is found. If set to +true+, this will return that
173
177
  # value if the semi-major isn't found.
174
178
  # @return [Float]
175
- def spheroid_inverse_flattening(return_wgs84_on_nil = false)
179
+ def spheroid_inverse_flattening(return_wgs84_on_nil: false)
176
180
  err_ptr = FFI::MemoryPointer.new(:int)
177
181
  value = FFI::OGR::SRSAPI.OSRGetInvFlattening(@c_pointer, err_ptr)
178
182
  ogr_err = FFI::OGR::Core::Err[err_ptr.read_int]
@@ -184,16 +188,17 @@ module OGR
184
188
  # @param target_key [String] The partial or complete path to the node to
185
189
  # set an authority on ("PROJCS", "GEOGCS|UNIT").
186
190
  # @param authority [String] I.e. "EPSG".
187
- # @param code [Fixnum] Code value for the authority.
191
+ # @param code [Integer] Code value for the authority.
192
+ # @raise [OGR::Failure]
188
193
  def set_authority(target_key, authority, code)
189
- ogr_err = FFI::OGR::SRSAPI.OSRSetAuthority(
190
- @c_pointer,
191
- target_key,
192
- authority,
193
- code
194
- )
195
-
196
- ogr_err.handle_result
194
+ OGR::ErrorHandling.handle_ogr_err("Unable to set authority: '#{target_key}', '#{authority}', '#{code}'") do
195
+ FFI::OGR::SRSAPI.OSRSetAuthority(
196
+ @c_pointer,
197
+ target_key,
198
+ authority,
199
+ code
200
+ )
201
+ end
197
202
  end
198
203
 
199
204
  # @param target_key [String] The partial or complete path to the node to get
@@ -201,7 +206,10 @@ module OGR
201
206
  # search at the root element.
202
207
  # @return [String, nil]
203
208
  def authority_code(target_key = nil)
204
- FFI::OGR::SRSAPI.OSRGetAuthorityCode(@c_pointer, target_key)
209
+ code, ptr = FFI::OGR::SRSAPI.OSRGetAuthorityCode(@c_pointer, target_key)
210
+ ptr.autorelease = false
211
+
212
+ code
205
213
  end
206
214
 
207
215
  # @param target_key [String] The partial or complete path to the node to get
@@ -209,39 +217,56 @@ module OGR
209
217
  # search at the root element.
210
218
  # @return [String, nil]
211
219
  def authority_name(target_key = nil)
212
- FFI::OGR::SRSAPI.OSRGetAuthorityName(@c_pointer, target_key)
220
+ name, ptr = FFI::OGR::SRSAPI.OSRGetAuthorityName(@c_pointer, target_key)
221
+ ptr.autorelease = false
222
+
223
+ name
213
224
  end
214
225
 
215
226
  # @param projection_name [String]
216
- # @return +true+ if successful, otherwise raises an OGR exception.
217
- def set_projection(projection_name)
218
- ogr_err = FFI::OGR::SRSAPI.OSRSetProjection(@c_pointer, projection_name)
219
-
220
- ogr_err.handle_result
227
+ # @raise [OGR::Failure]
228
+ def set_projection(projection_name) # rubocop:disable Naming/AccessorMethodName
229
+ OGR::ErrorHandling.handle_ogr_err("Unable to set projection to '#{projection_name}'") do
230
+ FFI::OGR::SRSAPI.OSRSetProjection(@c_pointer, projection_name)
231
+ end
221
232
  end
222
233
  alias projection= set_projection
223
234
 
224
235
  # @param param_name [String]
225
236
  # @param value [Float]
237
+ # @raise [OGR::Failure]
226
238
  def set_projection_parameter(param_name, value)
227
- ogr_err = FFI::OGR::SRSAPI.OSRSetProjParm(@c_pointer, param_name, value)
228
-
229
- ogr_err.handle_result
239
+ OGR::ErrorHandling.handle_ogr_err("Unable to set projection parameter '#{param_name}' to #{value}") do
240
+ FFI::OGR::SRSAPI.OSRSetProjParm(@c_pointer, param_name, value)
241
+ end
230
242
  end
231
243
 
232
244
  # @param name [String]
233
245
  # @param default_value [Float] The value to return if the parameter
234
246
  # doesn't exist.
247
+ # @raise [OGR::Failure]
235
248
  def projection_parameter(name, default_value = 0.0)
236
- FFI::OGR::SRSAPI.OSRGetProjParm(@c_pointer, name, default_value, nil)
249
+ value = default_value
250
+
251
+ OGR::ErrorHandling.handle_ogr_err("Unable to get projection parameter '#{name}'") do
252
+ ogr_err_ptr = FFI::MemoryPointer.new(:int)
253
+ value = FFI::OGR::SRSAPI.OSRGetProjParm(@c_pointer, name, default_value, ogr_err_ptr)
254
+ ogr_err_int = ogr_err_ptr.null? ? 0 : ogr_err_ptr.read_int
255
+ FFI::OGR::Core::Err[ogr_err_int]
256
+ end
257
+
258
+ value
237
259
  end
238
260
 
239
261
  # @param param_name [String]
240
262
  # @param value [Float]
263
+ # @raise [OGR::Failure]
241
264
  def set_normalized_projection_parameter(param_name, value)
242
- ogr_err = FFI::OGR::SRSAPI.OSRSetNormProjParm(@c_pointer, param_name, value)
265
+ msg = "Unable to set normalized projection parameter '#{param_name}' to '#{value}'"
243
266
 
244
- ogr_err.handle_result
267
+ OGR::ErrorHandling.handle_ogr_err(msg) do
268
+ FFI::OGR::SRSAPI.OSRSetNormProjParm(@c_pointer, param_name, value)
269
+ end
245
270
  end
246
271
 
247
272
  # @param name [String] Name of the parameter to fetch; must be from the
@@ -252,16 +277,17 @@ module OGR
252
277
  FFI::OGR::SRSAPI.OSRGetNormProjParm(@c_pointer, name, default_value, nil)
253
278
  end
254
279
 
255
- # @param zone [Fixnum]
280
+ # @param zone [Integer]
256
281
  # @param north [Boolean] True for northern hemisphere, false for southern.
257
- def set_utm(zone, north)
258
- ogr_err = FFI::OGR::SRSAPI.OSRSetUTM(@c_pointer, zone, north)
259
-
260
- ogr_err.handle_result
282
+ # @raise [OGR::Failure]
283
+ def set_utm(zone, north: true)
284
+ OGR::ErrorHandling.handle_ogr_err("Unable to set UTM to zome #{zone} (north: #{north})") do
285
+ FFI::OGR::SRSAPI.OSRSetUTM(@c_pointer, zone, north)
286
+ end
261
287
  end
262
288
 
263
289
  # @param hemisphere [Symbol] :north or :south.
264
- # @return [Fixnum] The zone, or 0 if this isn't a UTM definition.
290
+ # @return [Integer] The zone, or 0 if this isn't a UTM definition.
265
291
  def utm_zone(hemisphere = :north)
266
292
  north =
267
293
  case hemisphere
@@ -275,30 +301,31 @@ module OGR
275
301
  FFI::OGR::SRSAPI.OSRGetUTMZone(@c_pointer, north_ptr)
276
302
  end
277
303
 
278
- # @param zone [Fixnum] State plane zone number (USGS numbering scheme).
304
+ # @param zone [Integer] State plane zone number (USGS numbering scheme).
279
305
  # @param nad83 [Boolean] Use NAD83 zone definition or not.
280
- def set_state_plane(zone, nad83 = true, override_unit_label = nil, override_unit_transform = 0.0)
281
- ogr_err = FFI::OGR::SRSAPI.OSRSetStatePlaneWithUnits(
282
- @c_pointer,
283
- zone,
284
- nad83,
285
- override_unit_label,
286
- override_unit_transform
287
- )
288
-
289
- ogr_err.handle_result
290
- end
291
-
292
- # @param axis_number [Fixnum] The Axis to query (0 or 1.)
293
- # @param target_key [String]
306
+ # @raise [OGR::Failure]
307
+ def set_state_plane(zone, override_unit_label = nil, override_unit_transform = 0.0, nad83: true)
308
+ OGR::ErrorHandling.handle_ogr_err("Unable to set state plane to zone #{zone}") do
309
+ FFI::OGR::SRSAPI.OSRSetStatePlaneWithUnits(
310
+ @c_pointer,
311
+ zone,
312
+ nad83,
313
+ override_unit_label,
314
+ override_unit_transform
315
+ )
316
+ end
317
+ end
318
+
319
+ # @param axis_number [Integer] The Axis to query (0, 1, or 2)
320
+ # @param target_key [String] 'GEOGCS' or 'PROJCS'.
294
321
  # @return [String, nil]
295
- def axis(axis_number, target_key = nil)
322
+ def axis(axis_number, target_key)
296
323
  axis_orientation_ptr = FFI::MemoryPointer.new(:int)
297
324
 
298
325
  name = FFI::OGR::SRSAPI.OSRGetAxis(@c_pointer, target_key, axis_number, axis_orientation_ptr)
299
326
  ao_value = axis_orientation_ptr.read_int
300
327
 
301
- { name: name, orientation: AxisOrientation[ao_value] }
328
+ { name: name, orientation: FFI::OGR::SRSAPI::AxisOrientation[ao_value] }
302
329
  end
303
330
 
304
331
  def set_albers_conic_equal_area
@@ -459,15 +486,19 @@ module OGR
459
486
  # @param scale [Float]
460
487
  # @param false_easting [Float]
461
488
  # @param false_northing [Float]
489
+ # @raise [OGR::Failure]
462
490
  def set_transverse_mercator(center_lat, center_long, scale, false_easting, false_northing)
463
- ogr_err = FFI::OGR::SRSAPI.OSRSetTM(
464
- @c_pointer,
465
- center_lat, center_long,
466
- scale,
467
- false_easting, false_northing
468
- )
469
-
470
- ogr_err.handle_result
491
+ msg = 'Unable to set transverse mercator: ' \
492
+ "#{center_lat}, #{center_long}, #{scale}, #{false_easting}, #{false_northing}"
493
+
494
+ OGR::ErrorHandling.handle_ogr_err(msg) do
495
+ FFI::OGR::SRSAPI.OSRSetTM(
496
+ @c_pointer,
497
+ center_lat, center_long,
498
+ scale,
499
+ false_easting, false_northing
500
+ )
501
+ end
471
502
  end
472
503
  alias set_tm set_transverse_mercator
473
504