ffi-gdal 1.0.0.beta5 → 1.0.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -3
  3. data/.rubocop.yml +7 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +1 -1
  6. data/History.md +143 -1
  7. data/README.md +5 -11
  8. data/Rakefile +2 -60
  9. data/TODO.md +10 -0
  10. data/examples/geometries.rb +4 -6
  11. data/examples/gridding.rb +99 -98
  12. data/examples/ogr_layer_to_layer.rb +0 -2
  13. data/examples/raster_erasing.rb +47 -0
  14. data/examples/remove_small_polygons.rb +62 -0
  15. data/examples/testing_gdal.rb +0 -3
  16. data/examples/warping.rb +140 -0
  17. data/ffi-gdal.gemspec +5 -2
  18. data/lib/ext/error_symbols.rb +1 -1
  19. data/lib/ext/ffi_library_function_checks.rb +3 -2
  20. data/lib/ext/float_ext.rb +2 -2
  21. data/lib/ext/narray_ext.rb +1 -1
  22. data/lib/ext/numeric_as_data_type.rb +1 -1
  23. data/lib/ext/to_bool.rb +2 -2
  24. data/lib/ffi/cpl/conv.rb +1 -3
  25. data/lib/ffi/cpl/error.rb +0 -3
  26. data/lib/ffi/cpl/minixml.rb +17 -21
  27. data/lib/ffi/cpl/progress.rb +27 -0
  28. data/lib/ffi/cpl/string.rb +0 -8
  29. data/lib/ffi/cpl/vsi.rb +0 -1
  30. data/lib/ffi/cpl/xml_node.rb +0 -1
  31. data/lib/ffi/cpl.rb +15 -0
  32. data/lib/ffi/gdal/alg.rb +72 -54
  33. data/lib/ffi/gdal/gdal.rb +669 -672
  34. data/lib/ffi/gdal/grid.rb +141 -24
  35. data/lib/ffi/gdal/grid_data_metrics_options.rb +1 -1
  36. data/lib/ffi/gdal/grid_moving_average_options.rb +1 -1
  37. data/lib/ffi/gdal/matching.rb +0 -2
  38. data/lib/ffi/gdal/transformer_info.rb +1 -1
  39. data/lib/ffi/gdal/version.rb +1 -1
  40. data/lib/ffi/gdal/vrt.rb +0 -2
  41. data/lib/ffi/gdal/warp_options.rb +12 -14
  42. data/lib/ffi/gdal/warper.rb +61 -6
  43. data/lib/ffi/gdal.rb +18 -3
  44. data/lib/ffi/ogr/api.rb +10 -21
  45. data/lib/ffi/ogr/core.rb +9 -12
  46. data/lib/ffi/ogr/featurestyle.rb +0 -5
  47. data/lib/ffi/ogr/geocoding.rb +0 -1
  48. data/lib/ffi/ogr/srs_api.rb +0 -4
  49. data/lib/ffi/ogr/style_value.rb +1 -2
  50. data/lib/ffi/ogr.rb +15 -12
  51. data/lib/ffi-gdal.rb +5 -3
  52. data/lib/gdal/color_entry.rb +1 -0
  53. data/lib/gdal/color_interpretation.rb +2 -2
  54. data/lib/gdal/color_table.rb +14 -14
  55. data/lib/gdal/color_table_mixins/extensions.rb +4 -4
  56. data/lib/gdal/cpl_error_handler.rb +12 -14
  57. data/lib/gdal/data_type.rb +13 -12
  58. data/lib/gdal/dataset.rb +170 -94
  59. data/lib/gdal/dataset_mixins/algorithm_methods.rb +47 -21
  60. data/lib/gdal/dataset_mixins/extensions.rb +32 -61
  61. data/lib/gdal/dataset_mixins/matching.rb +0 -2
  62. data/lib/gdal/dataset_mixins/warp_methods.rb +42 -0
  63. data/lib/gdal/driver.rb +62 -47
  64. data/lib/gdal/driver_mixins/extensions.rb +2 -7
  65. data/lib/gdal/environment_methods.rb +13 -10
  66. data/lib/gdal/exceptions.rb +24 -2
  67. data/lib/gdal/geo_transform.rb +10 -16
  68. data/lib/gdal/geo_transform_mixins/extensions.rb +58 -3
  69. data/lib/gdal/grid.rb +62 -109
  70. data/lib/gdal/{grid_types → grid_algorithms}/data_metrics_base.rb +1 -3
  71. data/lib/gdal/{grid_types → grid_algorithms}/inverse_distance_to_a_power.rb +2 -4
  72. data/lib/gdal/{grid_types → grid_algorithms}/metric_average_distance.rb +2 -2
  73. data/lib/gdal/{grid_types → grid_algorithms}/metric_average_distance_pts.rb +2 -2
  74. data/lib/gdal/{grid_types → grid_algorithms}/metric_count.rb +2 -2
  75. data/lib/gdal/{grid_types → grid_algorithms}/metric_maximum.rb +2 -2
  76. data/lib/gdal/{grid_types → grid_algorithms}/metric_minimum.rb +2 -2
  77. data/lib/gdal/{grid_types → grid_algorithms}/metric_range.rb +2 -2
  78. data/lib/gdal/{grid_types → grid_algorithms}/moving_average.rb +2 -4
  79. data/lib/gdal/{grid_types → grid_algorithms}/nearest_neighbor.rb +2 -4
  80. data/lib/gdal/grid_algorithms.rb +22 -0
  81. data/lib/gdal/gridder/point_extracting.rb +89 -0
  82. data/lib/gdal/gridder.rb +294 -0
  83. data/lib/gdal/gridder_options.rb +273 -0
  84. data/lib/gdal/internal_helpers.rb +132 -23
  85. data/lib/gdal/major_object.rb +13 -10
  86. data/lib/gdal/merger.rb +130 -0
  87. data/lib/gdal/options.rb +3 -2
  88. data/lib/gdal/raster_attribute_table.rb +74 -51
  89. data/lib/gdal/raster_attribute_table_mixins/extensions.rb +21 -3
  90. data/lib/gdal/raster_band.rb +139 -167
  91. data/lib/gdal/raster_band_classifier.rb +19 -18
  92. data/lib/gdal/raster_band_mixins/algorithm_extensions.rb +107 -0
  93. data/lib/gdal/raster_band_mixins/algorithm_methods.rb +79 -40
  94. data/lib/gdal/raster_band_mixins/coloring_extensions.rb +84 -0
  95. data/lib/gdal/raster_band_mixins/extensions.rb +34 -169
  96. data/lib/gdal/raster_band_mixins/io_extensions.rb +180 -0
  97. data/lib/gdal/rpc_info.rb +1 -2
  98. data/lib/gdal/transformer.rb +1 -6
  99. data/lib/gdal/transformers/approximate_transformer.rb +0 -4
  100. data/lib/gdal/transformers/base_general_image_projection_transformer.rb +0 -6
  101. data/lib/gdal/transformers/gcp_transformer.rb +2 -6
  102. data/lib/gdal/transformers/general_image_projection_transformer.rb +8 -7
  103. data/lib/gdal/transformers/general_image_projection_transformer2.rb +1 -1
  104. data/lib/gdal/transformers/geolocation_transformer.rb +0 -4
  105. data/lib/gdal/transformers/reprojection_transformer.rb +0 -8
  106. data/lib/gdal/transformers/rpc_transformer.rb +0 -4
  107. data/lib/gdal/transformers/tps_transformer.rb +1 -3
  108. data/lib/gdal/version_info.rb +7 -8
  109. data/lib/gdal/virtual_dataset.rb +2 -4
  110. data/lib/gdal/warp_operation.rb +17 -14
  111. data/lib/gdal/warp_options.rb +132 -0
  112. data/lib/gdal.rb +41 -2
  113. data/lib/ogr/coordinate_transformation.rb +79 -32
  114. data/lib/ogr/data_source.rb +17 -14
  115. data/lib/ogr/data_source_extensions.rb +1 -5
  116. data/lib/ogr/driver.rb +11 -14
  117. data/lib/ogr/envelope.rb +1 -1
  118. data/lib/ogr/envelope_extensions.rb +23 -6
  119. data/lib/ogr/error_handling.rb +3 -3
  120. data/lib/ogr/exceptions.rb +6 -0
  121. data/lib/ogr/feature.rb +25 -38
  122. data/lib/ogr/feature_definition.rb +6 -8
  123. data/lib/ogr/feature_definition_extensions.rb +2 -6
  124. data/lib/ogr/feature_extensions.rb +71 -41
  125. data/lib/ogr/field.rb +16 -15
  126. data/lib/ogr/field_definition.rb +4 -4
  127. data/lib/ogr/geocoder.rb +5 -5
  128. data/lib/ogr/geometries/geometry_collection.rb +4 -1
  129. data/lib/ogr/geometries/geometry_collection_25d.rb +12 -0
  130. data/lib/ogr/geometries/line_string.rb +30 -8
  131. data/lib/ogr/geometries/line_string_25d.rb +21 -0
  132. data/lib/ogr/geometries/linear_ring.rb +10 -1
  133. data/lib/ogr/geometries/multi_line_string.rb +2 -1
  134. data/lib/ogr/geometries/multi_line_string_25d.rb +13 -0
  135. data/lib/ogr/geometries/multi_point.rb +2 -1
  136. data/lib/ogr/geometries/multi_point_25d.rb +14 -0
  137. data/lib/ogr/geometries/multi_polygon.rb +3 -2
  138. data/lib/ogr/geometries/multi_polygon_25d.rb +13 -0
  139. data/lib/ogr/geometries/point.rb +20 -23
  140. data/lib/ogr/geometries/point_25d.rb +48 -0
  141. data/lib/ogr/geometries/polygon.rb +4 -1
  142. data/lib/ogr/geometries/polygon_25d.rb +14 -0
  143. data/lib/ogr/geometry.rb +125 -93
  144. data/lib/ogr/geometry_field_definition.rb +7 -5
  145. data/lib/ogr/geometry_mixins/container_mixins.rb +23 -0
  146. data/lib/ogr/geometry_mixins/extensions.rb +111 -0
  147. data/lib/ogr/geometry_types/container.rb +10 -3
  148. data/lib/ogr/geometry_types/curve.rb +68 -23
  149. data/lib/ogr/geometry_types/surface.rb +0 -9
  150. data/lib/ogr/internal_helpers.rb +3 -3
  151. data/lib/ogr/layer.rb +4 -5
  152. data/lib/ogr/layer_mixins/extensions.rb +242 -17
  153. data/lib/ogr/layer_mixins/ogr_feature_methods.rb +11 -11
  154. data/lib/ogr/layer_mixins/ogr_field_methods.rb +6 -11
  155. data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +18 -18
  156. data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +0 -2
  157. data/lib/ogr/layer_mixins/ogr_sql_methods.rb +1 -1
  158. data/lib/ogr/spatial_reference.rb +12 -37
  159. data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +53 -55
  160. data/lib/ogr/spatial_reference_mixins/exporters.rb +18 -49
  161. data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +10 -29
  162. data/lib/ogr/style_table.rb +2 -2
  163. data/lib/ogr/style_table_extensions.rb +3 -1
  164. data/lib/ogr/style_tool.rb +8 -14
  165. data/lib/ogr.rb +39 -1
  166. data/spec/ffi-gdal_spec.rb +18 -1
  167. data/spec/integration/gdal/color_table_info_spec.rb +49 -33
  168. data/spec/integration/gdal/dataset_info_spec.rb +294 -45
  169. data/spec/integration/gdal/driver_info_spec.rb +139 -31
  170. data/spec/integration/gdal/geo_transform_info_spec.rb +197 -26
  171. data/spec/integration/gdal/gridder_spec.rb +329 -0
  172. data/spec/integration/gdal/raster_attribute_table_info_spec.rb +216 -11
  173. data/spec/integration/gdal/raster_band_algorithms_spec.rb +33 -0
  174. data/spec/integration/gdal/raster_band_info_spec.rb +240 -271
  175. data/spec/integration/ogr/layer_spec.rb +3 -1
  176. data/spec/spec_helper.rb +15 -6
  177. data/spec/support/images/osgeo/gdal/data/hfa/float-rle.img +0 -0
  178. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.lgo +31 -0
  179. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif +0 -0
  180. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif.msk +0 -0
  181. data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.txt +10 -0
  182. data/spec/support/images/osgeo/geotiff/gdal_eg/cea.tif +0 -0
  183. data/spec/support/images/osgeo/geotiff/gdal_eg/cea.txt +84 -0
  184. data/spec/support/images/osgeo/geotiff/zi_imaging/image0.lgo +45 -0
  185. data/spec/support/images/osgeo/geotiff/zi_imaging/image0.tif +0 -0
  186. data/spec/support/integration_help.rb +32 -2
  187. data/spec/support/shared_examples/gdal/major_object_examples.rb +0 -6
  188. data/spec/support/shared_examples/ogr/a_geometry.rb +1 -1
  189. data/spec/unit/ffi/gdal_spec.rb +1 -1
  190. data/spec/unit/gdal/color_entry_spec.rb +1 -0
  191. data/spec/unit/gdal/color_interpretation_spec.rb +1 -0
  192. data/spec/unit/gdal/dataset_spec.rb +53 -2
  193. data/spec/unit/gdal/geo_transform_mixins/extensions_spec.rb +67 -0
  194. data/spec/unit/gdal/geo_transform_spec.rb +1 -1
  195. data/spec/unit/gdal/grid_spec.rb +83 -0
  196. data/spec/unit/gdal/gridder/point_extracting_spec.rb +99 -0
  197. data/spec/unit/gdal/gridder_options_spec.rb +183 -0
  198. data/spec/unit/gdal/gridder_spec.rb +140 -0
  199. data/spec/unit/gdal/internal_helpers_spec.rb +166 -2
  200. data/spec/unit/gdal/major_object_spec.rb +2 -0
  201. data/spec/unit/gdal/options_spec.rb +1 -0
  202. data/spec/unit/gdal/raster_band_classifier_spec.rb +70 -12
  203. data/spec/unit/gdal/raster_band_mixins/extensions_spec.rb +71 -0
  204. data/spec/unit/gdal/raster_band_mixins/io_extensions_spec.rb +133 -0
  205. data/spec/unit/gdal/raster_band_spec.rb +1 -0
  206. data/spec/unit/gdal/rpc_info_spec.rb +1 -0
  207. data/spec/unit/gdal/version_info_spec.rb +2 -0
  208. data/spec/unit/gdal/warp_operation_spec.rb +1 -0
  209. data/spec/unit/ogr/coordinate_transformation_spec.rb +102 -0
  210. data/spec/unit/ogr/data_source_spec.rb +12 -0
  211. data/spec/unit/ogr/feature_extensions_spec.rb +88 -0
  212. data/spec/unit/ogr/feature_spec.rb +30 -46
  213. data/spec/unit/ogr/geometries/geometry_collection_25d_spec.rb +23 -0
  214. data/spec/unit/ogr/geometries/geometry_collection_spec.rb +3 -3
  215. data/spec/unit/ogr/geometries/line_string_25d_spec.rb +23 -0
  216. data/spec/unit/ogr/geometries/line_string_spec.rb +2 -2
  217. data/spec/unit/ogr/geometries/linear_ring_spec.rb +2 -2
  218. data/spec/unit/ogr/geometries/multi_line_string_25d_spec.rb +23 -0
  219. data/spec/unit/ogr/geometries/multi_point_25d_spec.rb +23 -0
  220. data/spec/unit/ogr/geometries/multi_polygon_25d_spec.rb +23 -0
  221. data/spec/unit/ogr/geometries/point_25d_spec.rb +23 -0
  222. data/spec/unit/ogr/geometries/point_spec.rb +14 -24
  223. data/spec/unit/ogr/geometries/polygon_25d_spec.rb +23 -0
  224. data/spec/unit/ogr/geometries/polygon_spec.rb +1 -1
  225. data/spec/unit/ogr/geometry_field_definition_spec.rb +1 -1
  226. data/spec/unit/ogr/geometry_spec.rb +196 -30
  227. data/spec/unit/ogr/internal_helpers_spec.rb +20 -9
  228. data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +14 -6
  229. data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +9 -1
  230. data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +2 -1
  231. data/spec/unit/ogr/style_table_spec.rb +1 -1
  232. data/tmp/.keep +0 -0
  233. metadata +121 -19
  234. data/examples/points.txt +0 -127
  235. data/lib/gdal/grid_types.rb +0 -22
  236. data/lib/ogr/geometries/point_extensions.rb +0 -32
  237. data/lib/ogr/geometry_extensions.rb +0 -59
@@ -10,7 +10,7 @@ module OGR
10
10
 
11
11
  ogr_err.handle_result
12
12
  end
13
- alias_method :local_cs=, :set_local_cs
13
+ alias local_cs= set_local_cs
14
14
 
15
15
  # Set the user-visible PROJCS name.
16
16
  #
@@ -21,7 +21,7 @@ module OGR
21
21
 
22
22
  ogr_err.handle_result
23
23
  end
24
- alias_method :proj_cs=, :set_proj_cs
24
+ alias proj_cs= set_proj_cs
25
25
 
26
26
  # Set the user-visible PROJCS name.
27
27
  #
@@ -32,7 +32,7 @@ module OGR
32
32
 
33
33
  ogr_err.handle_result
34
34
  end
35
- alias_method :geoc_cs=, :set_geoc_cs
35
+ alias geoc_cs= set_geoc_cs
36
36
 
37
37
  # Set the GEOGCS based on a well-known name.
38
38
  #
@@ -45,7 +45,7 @@ module OGR
45
45
 
46
46
  ogr_err.handle_result
47
47
  end
48
- alias_method :well_known_geog_cs=, :set_well_known_geog_cs
48
+ alias well_known_geog_cs= set_well_known_geog_cs
49
49
 
50
50
  # @param definition [String]
51
51
  def set_from_user_input(definition)
@@ -71,9 +71,7 @@ module OGR
71
71
  # @param z_rotation [Float] (In arc seconds.)
72
72
  # @param scaling_factor [Float] (In parts-per-million.)
73
73
  def set_towgs84(x_distance: nil, y_distance: nil, z_distance: nil,
74
- x_rotation: 0.0, y_rotation: 0.0, z_rotation: 0.0,
75
- scaling_factor: 0.0)
76
-
74
+ x_rotation: 0.0, y_rotation: 0.0, z_rotation: 0.0, scaling_factor: 0.0)
77
75
  ogr_err = FFI::OGR::SRSAPI.OSRSetTOWGS84(
78
76
  @c_pointer,
79
77
  x_distance, y_distance, z_distance,
@@ -216,7 +214,7 @@ module OGR
216
214
 
217
215
  ogr_err.handle_result
218
216
  end
219
- alias_method :projection=, :set_projection
217
+ alias projection= set_projection
220
218
 
221
219
  # @param param_name [String]
222
220
  # @param value [Float]
@@ -264,7 +262,7 @@ module OGR
264
262
  case hemisphere
265
263
  when :north then 1
266
264
  when :south then 0
267
- else fail "Unknown hemisphere type #{hemisphere}. Please choose :north or :south."
265
+ else raise "Unknown hemisphere type #{hemisphere}. Please choose :north or :south."
268
266
  end
269
267
  north_ptr = FFI::MemoryPointer.new(:bool)
270
268
  north_ptr.write_bytes(north.to_s)
@@ -298,156 +296,156 @@ module OGR
298
296
  end
299
297
 
300
298
  def set_albers_conic_equal_area
301
- fail NotImplementedError
299
+ raise NotImplementedError
302
300
  end
303
- alias_method :set_acea, :set_albers_conic_equal_area
301
+ alias set_acea set_albers_conic_equal_area
304
302
 
305
303
  def set_ae
306
- fail NotImplementedError
304
+ raise NotImplementedError
307
305
  end
308
306
 
309
307
  def set_bonne
310
- fail NotImplementedError
308
+ raise NotImplementedError
311
309
  end
312
310
 
313
311
  def set_cea
314
- fail NotImplementedError
312
+ raise NotImplementedError
315
313
  end
316
314
 
317
315
  def set_cs
318
- fail NotImplementedError
316
+ raise NotImplementedError
319
317
  end
320
318
 
321
319
  def set_ec
322
- fail NotImplementedError
320
+ raise NotImplementedError
323
321
  end
324
322
 
325
323
  def set_eckert
326
- fail NotImplementedError
324
+ raise NotImplementedError
327
325
  end
328
326
 
329
327
  def set_eckert_iv
330
- fail NotImplementedError
328
+ raise NotImplementedError
331
329
  end
332
330
 
333
331
  def set_eckert_vi
334
- fail NotImplementedError
332
+ raise NotImplementedError
335
333
  end
336
334
 
337
335
  def set_equirectangular
338
- fail NotImplementedError
336
+ raise NotImplementedError
339
337
  end
340
338
 
341
339
  def set_equirectangular2
342
- fail NotImplementedError
340
+ raise NotImplementedError
343
341
  end
344
342
 
345
343
  def set_gc
346
- fail NotImplementedError
344
+ raise NotImplementedError
347
345
  end
348
346
 
349
347
  def set_gh
350
- fail NotImplementedError
348
+ raise NotImplementedError
351
349
  end
352
350
 
353
351
  def set_igh
354
- fail NotImplementedError
352
+ raise NotImplementedError
355
353
  end
356
354
 
357
355
  def set_geos
358
- fail NotImplementedError
356
+ raise NotImplementedError
359
357
  end
360
358
 
361
359
  def set_gauss_schreiber_transverse_mercator
362
- fail NotImplementedError
360
+ raise NotImplementedError
363
361
  end
364
362
 
365
363
  def set_gnomonic
366
- fail NotImplementedError
364
+ raise NotImplementedError
367
365
  end
368
366
 
369
367
  def set_om
370
- fail NotImplementedError
368
+ raise NotImplementedError
371
369
  end
372
370
 
373
371
  def set_hom
374
- fail NotImplementedError
372
+ raise NotImplementedError
375
373
  end
376
374
 
377
375
  def set_hom_2_pno
378
- fail NotImplementedError
376
+ raise NotImplementedError
379
377
  end
380
378
 
381
379
  def set_iwm_polyconic
382
- fail NotImplementedError
380
+ raise NotImplementedError
383
381
  end
384
382
 
385
383
  def set_krovak
386
- fail NotImplementedError
384
+ raise NotImplementedError
387
385
  end
388
386
 
389
387
  def set_laea
390
- fail NotImplementedError
388
+ raise NotImplementedError
391
389
  end
392
390
 
393
391
  def set_lcc
394
- fail NotImplementedError
392
+ raise NotImplementedError
395
393
  end
396
394
 
397
395
  def set_lcc_1sp
398
- fail NotImplementedError
396
+ raise NotImplementedError
399
397
  end
400
398
 
401
399
  def set_lccb
402
- fail NotImplementedError
400
+ raise NotImplementedError
403
401
  end
404
402
 
405
403
  def set_mc
406
- fail NotImplementedError
404
+ raise NotImplementedError
407
405
  end
408
406
 
409
407
  def set_mercator
410
- fail NotImplementedError
408
+ raise NotImplementedError
411
409
  end
412
410
 
413
411
  def set_mollweide
414
- fail NotImplementedError
412
+ raise NotImplementedError
415
413
  end
416
414
 
417
415
  def set_nzmg
418
- fail NotImplementedError
416
+ raise NotImplementedError
419
417
  end
420
418
 
421
419
  def set_os
422
- fail NotImplementedError
420
+ raise NotImplementedError
423
421
  end
424
422
 
425
423
  def set_orthographic
426
- fail NotImplementedError
424
+ raise NotImplementedError
427
425
  end
428
426
 
429
427
  def set_polyconic
430
- fail NotImplementedError
428
+ raise NotImplementedError
431
429
  end
432
430
 
433
431
  def set_ps
434
- fail NotImplementedError
432
+ raise NotImplementedError
435
433
  end
436
434
 
437
435
  def set_robinson
438
- fail NotImplementedError
436
+ raise NotImplementedError
439
437
  end
440
438
 
441
439
  def set_sinusoidal
442
- fail NotImplementedError
440
+ raise NotImplementedError
443
441
  end
444
442
 
445
443
  def set_stereographic
446
- fail NotImplementedError
444
+ raise NotImplementedError
447
445
  end
448
446
 
449
447
  def set_soc
450
- fail NotImplementedError
448
+ raise NotImplementedError
451
449
  end
452
450
 
453
451
  # @param center_lat [Float]
@@ -464,30 +462,30 @@ module OGR
464
462
 
465
463
  ogr_err.handle_result
466
464
  end
467
- alias_method :set_tm, :set_transverse_mercator
465
+ alias set_tm set_transverse_mercator
468
466
 
469
467
  def set_tm_variant
470
- fail NotImplementedError
468
+ raise NotImplementedError
471
469
  end
472
470
 
473
471
  def set_tmg
474
- fail NotImplementedError
472
+ raise NotImplementedError
475
473
  end
476
474
 
477
475
  def set_tmso
478
- fail NotImplementedError
476
+ raise NotImplementedError
479
477
  end
480
478
 
481
479
  def set_vdg
482
- fail NotImplementedError
480
+ raise NotImplementedError
483
481
  end
484
482
 
485
483
  def set_wagner
486
- fail NotImplementedError
484
+ raise NotImplementedError
487
485
  end
488
486
 
489
487
  def set_qsc
490
- fail NotImplementedError
488
+ raise NotImplementedError
491
489
  end
492
490
  end
493
491
  end
@@ -8,8 +8,7 @@ module OGR
8
8
  datum_name = FFI::MemoryPointer.new(:string)
9
9
  units = FFI::MemoryPointer.new(:string)
10
10
 
11
- ogr_err = FFI::OGR::SRSAPI.OSRExportToERM(@c_pointer, projection_name,
12
- datum_name, units)
11
+ ogr_err = FFI::OGR::SRSAPI.OSRExportToERM(@c_pointer, projection_name, datum_name, units)
13
12
  ogr_err.handle_result 'Required parameters (name, datum name, units) are not defined'
14
13
 
15
14
  {
@@ -21,12 +20,8 @@ module OGR
21
20
 
22
21
  # @return [Array<String>]
23
22
  def to_mapinfo
24
- return_ptr = FFI::MemoryPointer.new(:string)
25
- return_ptr_ptr = FFI::MemoryPointer.new(:pointer)
26
- return_ptr_ptr.write_pointer(return_ptr)
27
-
28
- ogr_err = FFI::OGR::SRSAPI.OSRExportToMICoordSys(@c_pointer,
29
- return_ptr_ptr)
23
+ return_ptr_ptr = GDAL._pointer_pointer(:string)
24
+ ogr_err = FFI::OGR::SRSAPI.OSRExportToMICoordSys(@c_pointer, return_ptr_ptr)
30
25
  ogr_err.handle_result
31
26
 
32
27
  return_ptr_ptr.get_array_of_string(0)
@@ -34,20 +29,11 @@ module OGR
34
29
 
35
30
  # @return [Hash]
36
31
  def to_pci
37
- proj = FFI::MemoryPointer.new(:string)
38
- proj_ptr = FFI::MemoryPointer.new(:pointer)
39
- proj_ptr.write_pointer(proj)
40
-
41
- units = FFI::MemoryPointer.new(:string)
42
- units_ptr = FFI::MemoryPointer.new(:pointer)
43
- units_ptr.write_pointer(units)
44
-
45
- prj_params = FFI::MemoryPointer.new(:double)
46
- prj_params_ptr = FFI::MemoryPointer.new(:pointer)
47
- prj_params_ptr.write_pointer(prj_params)
32
+ proj_ptr = GDAL._pointer_pointer(:string)
33
+ units_ptr = GDAL._pointer_pointer(:string)
34
+ prj_params_ptr = GDAL._pointer_pointer(:double)
48
35
 
49
- ogr_err = FFI::OGR::SRSAPI.OSRExportToPCI(@c_pointer, proj_ptr,
50
- units_ptr, prj_params_ptr)
36
+ ogr_err = FFI::OGR::SRSAPI.OSRExportToPCI(@c_pointer, proj_ptr, units_ptr, prj_params_ptr)
51
37
  ogr_err.handle_result
52
38
 
53
39
  {
@@ -60,14 +46,11 @@ module OGR
60
46
  # @return [String]
61
47
  # @raise [GDAL::UnsupportedOperation] If empty definition.
62
48
  def to_proj4
63
- proj4 = FFI::MemoryPointer.new(:string)
64
- proj4_ptr = FFI::MemoryPointer.new(:pointer)
65
- proj4_ptr.write_pointer(proj4)
66
-
49
+ proj4_ptr = GDAL._pointer_pointer(:string)
67
50
  ogr_err = FFI::OGR::SRSAPI.OSRExportToProj4(@c_pointer, proj4_ptr)
68
51
  ogr_err.handle_result
69
52
 
70
- proj4_ptr.read_pointer.read_string
53
+ GDAL._read_pointer_pointer_safely(proj4_ptr, :string)
71
54
  end
72
55
 
73
56
  # @return [Hash]
@@ -75,12 +58,9 @@ module OGR
75
58
  proj_sys = FFI::MemoryPointer.new(:long)
76
59
  zone = FFI::MemoryPointer.new(:long)
77
60
  datum = FFI::MemoryPointer.new(:long)
78
- prj_params = FFI::MemoryPointer.new(:double)
79
- prj_params_ptr = FFI::MemoryPointer.new(:pointer)
80
- prj_params_ptr.write_pointer(prj_params)
61
+ prj_params_ptr = GDAL._pointer_pointer(:double)
81
62
 
82
- ogr_err = FFI::OGR::SRSAPI.OSRExportToUSGS(@c_pointer, proj_sys,
83
- zone, prj_params_ptr, datum)
63
+ ogr_err = FFI::OGR::SRSAPI.OSRExportToUSGS(@c_pointer, proj_sys, zone, prj_params_ptr, datum)
84
64
  ogr_err.handle_result
85
65
 
86
66
  {
@@ -93,38 +73,27 @@ module OGR
93
73
 
94
74
  # @return [String]
95
75
  def to_wkt
96
- wkt_ptr = FFI::MemoryPointer.new(:string)
97
- wkt_ptr_ptr = FFI::MemoryPointer.new(:pointer)
98
- wkt_ptr_ptr.write_pointer(wkt_ptr)
99
-
76
+ wkt_ptr_ptr = GDAL._pointer_pointer(:string)
100
77
  ogr_err = FFI::OGR::SRSAPI.OSRExportToWkt(@c_pointer, wkt_ptr_ptr)
101
78
  ogr_err.handle_result
102
79
 
103
- wkt_ptr_ptr.read_pointer.read_string
80
+ GDAL._read_pointer_pointer_safely(wkt_ptr_ptr, :string)
104
81
  end
105
82
 
106
83
  # @param simplify [Boolean] +true+ strips off +AXIS+, +AUTHORITY+ and
107
84
  # +EXTENSION+ nodes.
108
85
  def to_pretty_wkt(simplify = false)
109
- wkt_ptr = FFI::MemoryPointer.new(:string)
110
- wkt_ptr_ptr = FFI::MemoryPointer.new(:pointer)
111
- wkt_ptr_ptr.write_pointer(wkt_ptr)
112
-
113
- ogr_err = FFI::OGR::SRSAPI.OSRExportToPrettyWkt(@c_pointer,
114
- wkt_ptr_ptr, simplify)
86
+ wkt_ptr_ptr = GDAL._pointer_pointer(:string)
87
+ ogr_err = FFI::OGR::SRSAPI.OSRExportToPrettyWkt(@c_pointer, wkt_ptr_ptr, simplify)
115
88
  ogr_err.handle_result
116
89
 
117
- wkt_ptr_ptr.read_pointer.read_string
90
+ GDAL._read_pointer_pointer_safely(wkt_ptr_ptr, :string)
118
91
  end
119
92
 
120
93
  # @return [String]
121
94
  def to_xml(dialect = nil)
122
- xml_ptr = FFI::MemoryPointer.new(:string)
123
- xml_ptr_ptr = FFI::MemoryPointer.new(:pointer)
124
- xml_ptr_ptr.write_pointer(xml_ptr)
125
-
126
- ogr_err = FFI::OGR::SRSAPI.OSRExportToXML(@c_pointer, xml_ptr_ptr,
127
- dialect)
95
+ xml_ptr_ptr = GDAL._pointer_pointer(:string)
96
+ ogr_err = FFI::OGR::SRSAPI.OSRExportToXML(@c_pointer, xml_ptr_ptr, dialect)
128
97
  ogr_err.handle_result
129
98
 
130
99
  xml_ptr_ptr.get_array_of_string(0).join
@@ -22,13 +22,10 @@ module OGR
22
22
  # of the unit type ("degree" or "radian"). +value+ is the number to
23
23
  # multiply angular distances to transform them to radians.
24
24
  def angular_units
25
- name = FFI::MemoryPointer.new(:string)
26
- name_ptr = FFI::MemoryPointer.new(:pointer)
27
- name_ptr.write_pointer(name)
28
-
25
+ name_ptr = GDAL._pointer_pointer(:string)
29
26
  value = FFI::OGR::SRSAPI.OSRGetAngularUnits(@c_pointer, name_ptr)
30
27
 
31
- { unit_name: name_ptr.read_pointer.read_string, value: value }
28
+ { unit_name: GDAL._read_pointer_pointer_safely(name_ptr, :string), value: value }
32
29
  end
33
30
 
34
31
  # @param unit_label [String]
@@ -44,13 +41,10 @@ module OGR
44
41
  # of the unit type (e.g. "Meters"). +value+ is the number to multiply
45
42
  # linear distances to transform them to meters.
46
43
  def linear_units
47
- name = FFI::MemoryPointer.new(:string)
48
- name_ptr = FFI::MemoryPointer.new(:pointer)
49
- name_ptr.write_pointer(name)
50
-
44
+ name_ptr = GDAL._pointer_pointer(:string)
51
45
  value = FFI::OGR::SRSAPI.OSRGetLinearUnits(@c_pointer, name_ptr)
52
46
 
53
- { unit_name: name_ptr.read_pointer.read_string, value: value }
47
+ { unit_name: GDAL._read_pointer_pointer_safely(name_ptr, :string), value: value }
54
48
  end
55
49
 
56
50
  # @param unit_label [String]
@@ -69,9 +63,7 @@ module OGR
69
63
  # @param transform_to_meters [Float] The value to multiply a length to
70
64
  # transform the value to meters.
71
65
  def set_linear_units_and_update_parameters(unit_label, transform_to_meters)
72
- ogr_err = FFI::OGR::SRSAPI.OSRSetLinearUnitsAndUpdateParameters(
73
- @c_pointer,
74
- unit_label,
66
+ ogr_err = FFI::OGR::SRSAPI.OSRSetLinearUnitsAndUpdateParameters(@c_pointer, unit_label,
75
67
  transform_to_meters.to_f)
76
68
 
77
69
  ogr_err.handle_result
@@ -82,13 +74,10 @@ module OGR
82
74
  # @param target_key [String] I.e. "PROJCS" or "VERT_CS".
83
75
  # @return [Hash]
84
76
  def target_linear_units(target_key)
85
- name = FFI::MemoryPointer.new(:string)
86
- name_ptr = FFI::MemoryPointer.new(:pointer)
87
- name_ptr.write_pointer(name)
88
-
77
+ name_ptr = GDAL._pointer_pointer(:string)
89
78
  value = FFI::OGR::SRSAPI.OSRGetTargetLinearUnits(@c_pointer, target_key, name_ptr)
90
79
 
91
- { unit_name: name_ptr.read_pointer.read_string, value: value }
80
+ { unit_name: GDAL._read_pointer_pointer_safely(name_ptr, :string), value: value }
92
81
  end
93
82
 
94
83
  # @param target_key [String] The keyword to set linear units for ("PROJCS",
@@ -97,25 +86,17 @@ module OGR
97
86
  # @param transform_to_meters [Float] The value to multiple a length to
98
87
  # transform the value to meters.
99
88
  def set_target_linear_units(target_key, unit_label, transform_to_meters)
100
- ogr_err = FFI::OGR::SRSAPI.OSRSetTargetLinearUnits(
101
- @c_pointer,
102
- target_key,
103
- unit_label,
104
- transform_to_meters
105
- )
89
+ ogr_err = FFI::OGR::SRSAPI.OSRSetTargetLinearUnits(@c_pointer, target_key, unit_label, transform_to_meters)
106
90
 
107
91
  ogr_err.handle_result
108
92
  end
109
93
 
110
94
  # @return [Hash]
111
95
  def prime_meridian
112
- pm = FFI::MemoryPointer.new(:string)
113
- pm_ptr = FFI::MemoryPointer.new(:pointer)
114
- pm_ptr.write_pointer(pm)
115
-
96
+ pm_ptr = GDAL._pointer_pointer(:string)
116
97
  value = FFI::OGR::SRSAPI.OSRGetPrimeMeridian(@c_pointer, pm_ptr)
117
98
 
118
- { name: pm_ptr.read_pointer.read_string, value: value }
99
+ { name: GDAL._read_pointer_pointer_safely(pm_ptr, :string), value: value }
119
100
  end
120
101
  end
121
102
  end
@@ -1,4 +1,4 @@
1
- require_relative '../ffi/ogr'
1
+ require_relative '../ogr'
2
2
  require_relative 'style_table_extensions'
3
3
 
4
4
  module OGR
@@ -12,7 +12,7 @@ module OGR
12
12
  def initialize(c_pointer = nil)
13
13
  @c_pointer = c_pointer ? c_pointer : FFI::OGR::API.OGR_STBL_Create
14
14
 
15
- fail 'Unable to create StyleTable' if @c_pointer.null?
15
+ raise 'Unable to create StyleTable' if @c_pointer.null?
16
16
  end
17
17
 
18
18
  def destroy!
@@ -10,7 +10,9 @@ module OGR
10
10
  styles = {}
11
11
  reset_style_string_reading
12
12
 
13
- while style = next_style
13
+ loop do
14
+ style = next_style
15
+ break unless style
14
16
  styles[last_style_name] = style
15
17
  end
16
18
 
@@ -1,4 +1,4 @@
1
- require_relative '../ffi/ogr'
1
+ require_relative '../ogr'
2
2
 
3
3
  module OGR
4
4
  class StyleTool
@@ -11,7 +11,7 @@ module OGR
11
11
  @c_pointer = FFI::OGR::API.OGR_ST_Create(style_tool_class)
12
12
  return if @c_pointer && !@c_pointer.null?
13
13
 
14
- fail OGR::CreateFailure, "Unable to create StyleTool using class #{style_tool_class}"
14
+ raise OGR::CreateFailure, "Unable to create StyleTool using class #{style_tool_class}"
15
15
  end
16
16
 
17
17
  # @return [String, nil]
@@ -43,14 +43,14 @@ module OGR
43
43
 
44
44
  value_is_null_ptr.read_int.to_bool ? nil : value
45
45
  end
46
- alias_method :param_as_float, :param_as_double
46
+ alias param_as_float param_as_double
47
47
 
48
48
  # @param param_number [Fixnum]
49
49
  # @param value [Float]
50
50
  def set_param_as_double(param_number, value)
51
51
  FFI::OGR::API.OGR_ST_SetParamDbl(@c_pointer, param_number, value)
52
52
  end
53
- alias_method :set_param_as_float, :set_param_as_double
53
+ alias set_param_as_float set_param_as_double
54
54
 
55
55
  # @param param_number [Fixnum]
56
56
  # @return [Fixnum, nil]
@@ -60,14 +60,14 @@ module OGR
60
60
 
61
61
  value_is_null_ptr.read_int.to_bool ? nil : value
62
62
  end
63
- alias_method :param_as_integer, :param_as_number
63
+ alias param_as_integer param_as_number
64
64
 
65
65
  # @param param_number [Fixnum]
66
66
  # @param value [Fixnum]
67
67
  def set_param_as_number(param_number, value)
68
68
  FFI::OGR::API.OGR_ST_SetParamNum(@c_pointer, param_number, value)
69
69
  end
70
- alias_method :set_param_as_integer, :set_param_as_number
70
+ alias set_param_as_integer set_param_as_number
71
71
 
72
72
  # @param param_number [Fixnum]
73
73
  # @return [String, nil]
@@ -94,14 +94,8 @@ module OGR
94
94
  blue_ptr = FFI::MemoryPointer.new(:int)
95
95
  alpha_ptr = FFI::MemoryPointer.new(:int)
96
96
 
97
- boolean_result = FFI::OGR::API.OGR_ST_GetRGBFromString(
98
- @c_pointer,
99
- color_string,
100
- red_ptr,
101
- green_ptr,
102
- blue_ptr,
103
- alpha_ptr
104
- )
97
+ boolean_result = FFI::OGR::API.OGR_ST_GetRGBFromString(@c_pointer,
98
+ color_string, red_ptr, green_ptr, blue_ptr, alpha_ptr)
105
99
 
106
100
  if boolean_result
107
101
  {
data/lib/ogr.rb CHANGED
@@ -1,8 +1,46 @@
1
- require_relative 'ffi/ogr'
1
+ require_relative 'ffi-gdal'
2
2
  require_relative 'ogr/internal_helpers'
3
+ require_relative 'ogr/exceptions'
3
4
 
4
5
  module OGR
5
6
  include InternalHelpers
6
7
 
7
8
  FFI::OGR::API.OGRRegisterAll
9
+
10
+ def self.ogr_require(path)
11
+ File.expand_path(path, __dir__)
12
+ end
13
+
14
+ # Autoload OGR Geometry object types.
15
+ autoload :GeometryCollection, ogr_require('ogr/geometries/geometry_collection')
16
+ autoload :GeometryCollection25D, ogr_require('ogr/geometries/geometry_collection_25d')
17
+ autoload :LineString, ogr_require('ogr/geometries/line_string')
18
+ autoload :LineString25D, ogr_require('ogr/geometries/line_string_25d')
19
+ autoload :LinearRing, ogr_require('ogr/geometries/linear_ring')
20
+ autoload :MultiLineString, ogr_require('ogr/geometries/multi_line_string')
21
+ autoload :MultiLineString25D, ogr_require('ogr/geometries/multi_line_string_25d')
22
+ autoload :MultiPoint, ogr_require('ogr/geometries/multi_point')
23
+ autoload :MultiPoint25D, ogr_require('ogr/geometries/multi_point_25d')
24
+ autoload :MultiPolygon, ogr_require('ogr/geometries/multi_polygon')
25
+ autoload :MultiPolygon25D, ogr_require('ogr/geometries/multi_polygon_25d')
26
+ autoload :NoneGeometry, ogr_require('ogr/geometries/none_geometry')
27
+ autoload :Point, ogr_require('ogr/geometries/point')
28
+ autoload :Point25D, ogr_require('ogr/geometries/point_25d')
29
+ autoload :Polygon, ogr_require('ogr/geometries/polygon')
30
+ autoload :Polygon25D, ogr_require('ogr/geometries/polygon_25d')
31
+ autoload :UnknownGeometry, ogr_require('ogr/geometries/unknown_geometry')
32
+
33
+ # Autoload core OGR types
34
+ autoload :CoordinateTransformation, ogr_require('ogr/coordinate_transformation')
35
+ autoload :DataSource, ogr_require('ogr/data_source')
36
+ autoload :Driver, ogr_require('ogr/driver')
37
+ autoload :Envelope, ogr_require('ogr/envelope')
38
+ autoload :Feature, ogr_require('ogr/feature')
39
+ autoload :FeatureDefinition, ogr_require('ogr/feature_definition')
40
+ autoload :FieldDefinition, ogr_require('ogr/field_definition')
41
+ autoload :Geometry, ogr_require('ogr/geometry')
42
+ autoload :GeometryFieldDefinition, ogr_require('ogr/geometry_field_definition')
43
+ autoload :Layer, ogr_require('ogr/layer')
44
+ autoload :SpatialReference, ogr_require('ogr/spatial_reference')
45
+ autoload :StyleTable, ogr_require('ogr/style_table')
8
46
  end
@@ -1,5 +1,22 @@
1
1
  require 'spec_helper'
2
2
  require 'ffi-gdal'
3
3
 
4
- RSpec.describe GDAL do
4
+ RSpec.describe FFI do
5
+ describe 'autoload CPL' do
6
+ it 'can call CPL functions' do
7
+ expect { FFI::CPL }.to_not raise_exception
8
+ end
9
+ end
10
+
11
+ describe 'autoload GDAL' do
12
+ it 'can call GDAL functions' do
13
+ expect { FFI::GDAL }.to_not raise_exception
14
+ end
15
+ end
16
+
17
+ describe 'autoload OGR' do
18
+ it 'can call OGR functions' do
19
+ expect { FFI::OGR }.to_not raise_exception
20
+ end
21
+ end
5
22
  end