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
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bindata'
4
+ require 'ffi-gdal'
5
+ require 'ogr'
6
+
7
+ module OGR
8
+ module Geometry
9
+ # Parses raw WKB and turns into a data structure. Only really exists for
10
+ # converting to and from EWKB.
11
+ #
12
+ # @see OGR::Geometry::EWKBRecord
13
+ class WKBRecord < BinData::Record
14
+ uint8 :endianness, assert: -> { [0, 1].include?(value) }
15
+
16
+ # Choose the type based on the endianness
17
+ choice :wkb_type, selection: :endianness do
18
+ uint32be 0
19
+ uint32le 1
20
+ end
21
+
22
+ # Make sure the geometry_type is one OGR knows about.
23
+ virtual assert: -> { FFI::OGR::Core::WKBGeometryType.symbol_map.value?(geometry_type) }
24
+
25
+ # The #geometry attribute is just the rest of the data. We don't care what
26
+ # kind of geom it actually is; that doesn't matter for building EWKB.
27
+ rest :geometry
28
+
29
+ WKB_Z = 0x8000_0000
30
+
31
+ # @param ewkb_record [OGR::Geometry::EWKBRecord]
32
+ # @return [OGR::Geometry::WKBRecord]
33
+ def self.from_ewkb_record(ewkb_record)
34
+ new(endianness: ewkb_record.endianness,
35
+ wkb_type: ewkb_record.geometry_type,
36
+ geometry: ewkb_record.geometry)
37
+ end
38
+
39
+ # @param ewkb_data [String] Binary string with the EWKB data.
40
+ # @return [OGR::Geometry::WKBRecord]
41
+ def self.from_ewkb(ewkb_data)
42
+ from_ewkb_record(EWKBRecord.read(ewkb_data))
43
+ end
44
+
45
+ # @return [Boolean] Is the Z flag set?
46
+ def has_z? # rubocop:disable Naming/PredicateName
47
+ geometry_type & WKB_Z != 0
48
+ end
49
+
50
+ # @return [Fixnum] Enum number that matches the FFI::OGR::Core::WKBGeometryType.
51
+ # Defined to keep the API consistent with EWKBRecord.
52
+ def geometry_type
53
+ # ISO SQL/MM style Z types are between 1001 and 1007
54
+ if wkb_type.value >= 1001 && wkb_type.value <= 1007
55
+ raw_type_int = wkb_type.value - 1000
56
+ raw_type_int | WKB_Z
57
+ else
58
+ wkb_type.value
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ogr/geometry'
4
+ require 'gdal/extensions/geo_transform/extensions'
5
+
6
+ module OGR
7
+ module GeometryTypes
8
+ module Curve
9
+ module Extensions
10
+ # It seems as if {{#point}} should return an OGR::Point, but since OGR's
11
+ # OGR_G_GetPoint only returns coordinates, this allows getting the point
12
+ # as an OGR::Point.
13
+ #
14
+ # @param number [Integer] Index of the point to get.
15
+ # @return [OGR::Point]
16
+ def point_geometry(number)
17
+ coords = point(number)
18
+ point = OGR::Point.new
19
+ point.set_point(0, *coords)
20
+
21
+ point
22
+ end
23
+
24
+ # @return [Enumerator]
25
+ # @yieldparam [OGR::Point]
26
+ def each_point_geometry
27
+ return enum_for(:each_point_geometry) unless block_given?
28
+
29
+ point_count.times do |point_num|
30
+ yield point_as_geometry(point_num)
31
+ end
32
+ end
33
+
34
+ # @return [Array<OGR::Point>]
35
+ # @see #each_point_geometry, #point_geometry
36
+ def point_geometries
37
+ each_point_geometry.to_a
38
+ end
39
+
40
+ # @param geo_transform [GDAL::GeoTransform]
41
+ # @return [Array<Array>]
42
+ def pixels(geo_transform)
43
+ log "points count: #{point_count}"
44
+ points.map do |x_and_y|
45
+ result = geo_transform.world_to_pixel(*x_and_y)
46
+
47
+ [result[:pixel].to_i.abs, result[:line].to_i.abs]
48
+ end
49
+ end
50
+
51
+ def start_point
52
+ point(0)
53
+ end
54
+
55
+ def end_point
56
+ point(point_count - 1)
57
+ end
58
+
59
+ def closed?
60
+ start_point == end_point
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ OGR::LineString.include(OGR::GeometryTypes::Curve::Extensions)
68
+ OGR::MultiLineString.include(OGR::GeometryTypes::Curve::Extensions)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ogr/layer'
4
+
3
5
  module OGR
4
6
  module LayerMixins
5
7
  # Helper methods for checking what the Layer is capable of.
@@ -102,3 +104,5 @@ module OGR
102
104
  end
103
105
  end
104
106
  end
107
+
108
+ OGR::Layer.include(OGR::LayerMixins::CapabilityMethods)
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
3
+ require 'ogr/layer'
4
4
 
5
5
  module OGR
6
- module LayerMixins
6
+ class Layer
7
7
  # Methods not part of the C Layer API.
8
8
  module Extensions
9
9
  # Enumerates through all associated features. Beware: it calls
10
10
  # {#reset_reading} both before and after it's called. If you're using
11
- # {OGR::Layer#next_feature} for iterating through features somewhere in
11
+ # {OGR::LayerMixins::OGRFeatureMethods#next_feature} for iterating through features somewhere in
12
12
  # your code, this will reset that reading.
13
13
  #
14
14
  # @return [Enumerator]
@@ -115,7 +115,7 @@ module OGR
115
115
  return [] if feature_count.zero?
116
116
 
117
117
  field_indices = with_attributes.keys.map { |field_name| find_field_index(field_name) }
118
- values = Array.new(feature_count) { Array.new(2 + with_attributes.size) }
118
+ values = Array.new(feature_count) { Array.new(with_attributes.size + 2) }
119
119
  start = Time.now
120
120
  i = 0
121
121
 
@@ -128,7 +128,7 @@ module OGR
128
128
  # I've tried refactoring chunks of this out to separate methods and
129
129
  # performance suffers greatly. Since this is a key part of gridding (at
130
130
  # least at this point), it needs to be as fast as possible.
131
- each_feature_pointer do |feature_ptr|
131
+ each_feature_pointer do |feature_ptr| # rubocop:todo Metrics/BlockLength
132
132
  field_values = field_indices.map.with_index do |j, attribute_index|
133
133
  FFI::OGR::API.send("OGR_F_GetFieldAs#{with_attributes.values[attribute_index].capitalize}", feature_ptr, j)
134
134
  end
@@ -160,6 +160,7 @@ module OGR
160
160
 
161
161
  count.times do |ring_num|
162
162
  next if ring_num.zero?
163
+
163
164
  ring_ptr = FFI::OGR::API.OGR_G_GetGeometryRef(geom_ptr, ring_num)
164
165
 
165
166
  extract_ring_points(ring_ptr, x_ptr, y_ptr) do |points|
@@ -197,6 +198,7 @@ module OGR
197
198
 
198
199
  count.times do |ring_num|
199
200
  next if ring_num.zero?
201
+
200
202
  ring_ptr = FFI::OGR::API.OGR_G_GetGeometryRef(polygon_ptr, ring_num)
201
203
  ring_ptr.autorelease = false
202
204
 
@@ -207,7 +209,7 @@ module OGR
207
209
  end
208
210
  end
209
211
  else raise OGR::UnsupportedGeometryType,
210
- "Not sure how to extract point_values for a #{geom_type}"
212
+ "Not sure how to extract point_values for a #{geom_type}"
211
213
  end
212
214
  end
213
215
 
@@ -224,6 +226,7 @@ module OGR
224
226
 
225
227
  each_feature_pointer do |feature_ptr|
226
228
  break if found_z_geom
229
+
227
230
  geom_ptr = FFI::OGR::API.OGR_F_GetGeometryRef(feature_ptr)
228
231
  geom_ptr.autorelease = false
229
232
  coordinate_dimension = FFI::OGR::API.OGR_G_GetCoordinateDimension(geom_ptr)
@@ -264,3 +267,5 @@ module OGR
264
267
  end
265
268
  end
266
269
  end
270
+
271
+ OGR::Layer.include(OGR::Layer::Extensions)
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ogr/spatial_reference'
4
+
5
+ module OGR
6
+ class SpatialReference
7
+ module Extensions
8
+ # @param unit_label [Symbol, String] Must match one of the known angular
9
+ # unit types from FFI::GDAL::SRS_UA. Since there are only two, pick either
10
+ # :radian or :degree.
11
+ # @raise [NameError] If the +unit_label+ isn't of a known type.
12
+ def angular_units=(unit_label)
13
+ unit_name = unit_label.to_s.upcase
14
+ unit_label = self.class.const_get("#{unit_name}_LABEL".to_sym)
15
+ unit_value = self.class.const_get("RADIAN_TO_#{unit_name}".to_sym)
16
+
17
+ set_angular_units(unit_label, unit_value)
18
+ rescue NameError
19
+ raise NameError, "Param must be a known angular unit type: #{unit_label}"
20
+ end
21
+
22
+ # @param unit_label [Symbol, String] Must match one of the known linear
23
+ # unit types from FFI::GDAL::SRS_UL. I.e. :us_foot.
24
+ # @raise [NameError] If the +unit_label+ isn't of a known type.
25
+ def linear_units=(unit_label)
26
+ unit_name = unit_label.to_s.upcase
27
+ unit_label = self.class.const_get("#{unit_name}_LABEL".to_sym)
28
+ unit_value = self.class.const_get("METER_TO_#{unit_name}".to_sym)
29
+
30
+ set_linear_units(unit_label, unit_value)
31
+ rescue NameError
32
+ raise NameError, "Param must be a known linear unit type: #{unit_label}"
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ OGR::SpatialReference.include(OGR::SpatialReference::Extensions)
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ogr/spatial_reference'
4
+
5
+ module OGR
6
+ module SpatialReferenceMixins
7
+ module Initializers
8
+ def self.included(base)
9
+ base.extend ClassMethods
10
+ end
11
+
12
+ module ClassMethods
13
+ # @param code [Integer]
14
+ # @return [OGR::SpatialReference]
15
+ def new_from_epsg(code)
16
+ srs = new
17
+ srs.import_from_epsg(code)
18
+
19
+ srs
20
+ end
21
+
22
+ # @param code [Integer]
23
+ # @return [OGR::SpatialReference]
24
+ def new_from_epsga(code)
25
+ srs = new
26
+ srs.import_from_epsga(code)
27
+
28
+ srs
29
+ end
30
+
31
+ # @param projection_name [String] I.e. "NUTM11" or "GEOGRAPHIC".
32
+ # @param datum_name [String] I.e. "NAD83".
33
+ # @param linear_unit_name [String] Plural form of linear units, i.e. "FEET".
34
+ # @return [OGR::SpatialReference]
35
+ def new_from_erm(projection_name, datum_name, linear_unit_name)
36
+ srs = new
37
+ srs.import_from_erm(projection_name, datum_name, linear_unit_name)
38
+
39
+ srs
40
+ end
41
+
42
+ # @param prj_text [Array<String>]
43
+ # @return [OGR::SpatialReference]
44
+ def new_from_esri(prj_text)
45
+ srs = new
46
+ srs.import_from_esri(prj_text)
47
+
48
+ srs
49
+ end
50
+
51
+ # @param coord_sys [String] The Mapinfo style CoordSys definition string.
52
+ # @return [OGR::SpatialReference]
53
+ def new_from_mapinfo(coord_sys)
54
+ srs = new
55
+ srs.import_from_mapinfo(coord_sys)
56
+
57
+ srs
58
+ end
59
+
60
+ # @param proj [String]
61
+ # @param units [String]
62
+ # @param proj_params [Array<String>]
63
+ # @return [OGR::SpatialReference]
64
+ def new_from_pci(proj, units, *proj_params)
65
+ srs = new
66
+ srs.import_from_pci(proj, units, *proj_params)
67
+
68
+ srs
69
+ end
70
+
71
+ # @param proj4 [String]
72
+ # @return [OGR::SpatialReference]
73
+ def new_from_proj4(proj4)
74
+ srs = new
75
+ srs.import_from_proj4(proj4)
76
+
77
+ srs
78
+ end
79
+
80
+ # @param url [String] URL to fetch the spatial reference from.
81
+ # @return [OGR::SpatialReference]
82
+ def new_from_url(url)
83
+ srs = new
84
+ srs.import_from_url(url)
85
+
86
+ srs
87
+ end
88
+
89
+ # @param projection_system_code
90
+ # @return [OGR::SpatialReference]
91
+ def new_from_usgs(projection_system_code, zone, datum, *proj_params)
92
+ srs = new
93
+ srs.import_from_usgs(projection_system_code, zone, datum, *proj_params)
94
+
95
+ srs
96
+ end
97
+
98
+ # This wipes the existing SRS definition and reassigns it based on the
99
+ # contents of +wkt+.
100
+ #
101
+ # @param wkt [String]
102
+ # @return [OGR::SpatialReference]
103
+ def new_from_wkt(wkt)
104
+ srs = new
105
+ srs.import_from_wkt(wkt)
106
+
107
+ srs
108
+ end
109
+
110
+ # Use for importing a GML coordinate system.
111
+ #
112
+ # @param xml [String]
113
+ # @return [OGR::SpatialReference]
114
+ def new_from_xml(xml)
115
+ srs = new
116
+ srs.import_from_xml(xml)
117
+
118
+ srs
119
+ end
120
+
121
+ # @return [OGR::SpatialReference]
122
+ # @raise [OGR::Failure]
123
+ def build_spatial_ref(spatial_reference_or_wkt = nil)
124
+ object = new(spatial_reference_or_wkt)
125
+ ogr_err = yield object.c_pointer
126
+
127
+ OGR::ErrorHandling.handle_ogr_err('Unable to build SpatialReference') do
128
+ ogr_err
129
+ end
130
+
131
+ object
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ OGR::SpatialReference.include(OGR::SpatialReferenceMixins::Initializers)
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ogr/style_table'
4
+
5
+ module OGR
6
+ class StyleTable
7
+ module Extensions
8
+ # Gets all of the styles as Hash. Note that this calls
9
+ # #reset_style_string_reading.
10
+ #
11
+ # @return [Hash{name => style}]
12
+ def styles
13
+ styles = {}
14
+ reset_style_string_reading
15
+
16
+ loop do
17
+ style = next_style
18
+ break unless style
19
+
20
+ styles[last_style_name] = style
21
+ end
22
+
23
+ reset_style_string_reading
24
+
25
+ styles
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ OGR::StyleTable.include(OGR::StyleTable::Extensions)