ffi-gdal 1.0.0.beta3 → 1.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (286) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +62 -0
  4. data/Gemfile +1 -1
  5. data/History.md +53 -28
  6. data/README.md +6 -0
  7. data/Rakefile +23 -1
  8. data/examples/extract_and_colorize.rb +21 -22
  9. data/examples/geometries.rb +2 -2
  10. data/examples/gridding.rb +106 -0
  11. data/examples/ogr_layer_to_layer.rb +1 -1
  12. data/examples/points.txt +127 -0
  13. data/examples/testing_gdal.rb +3 -4
  14. data/ffi-gdal.gemspec +3 -2
  15. data/lib/ext/error_symbols.rb +2 -57
  16. data/lib/ext/ffi_library_function_checks.rb +26 -0
  17. data/lib/ext/float_ext.rb +2 -2
  18. data/lib/ext/narray_ext.rb +2 -0
  19. data/lib/ext/numeric_as_data_type.rb +19 -0
  20. data/lib/ext/to_bool.rb +4 -4
  21. data/lib/ffi/cpl/conv.rb +132 -0
  22. data/lib/ffi/cpl/error.rb +67 -0
  23. data/lib/ffi/cpl/hash_set.rb +39 -0
  24. data/lib/ffi/cpl/http.rb +25 -0
  25. data/lib/ffi/cpl/http_result.rb +18 -0
  26. data/lib/ffi/cpl/list.rb +38 -0
  27. data/lib/ffi/cpl/mime_part.rb +11 -0
  28. data/lib/ffi/cpl/minixml.rb +47 -0
  29. data/lib/ffi/cpl/port.rb +23 -0
  30. data/lib/ffi/cpl/quad_tree.rb +51 -0
  31. data/lib/ffi/{ogr/ogr_envelope.rb → cpl/rect_obj.rb} +3 -3
  32. data/lib/ffi/cpl/string.rb +95 -0
  33. data/lib/ffi/cpl/vsi.rb +115 -0
  34. data/lib/ffi/cpl/xml_node.rb +6 -6
  35. data/lib/ffi/gdal/alg.rb +385 -0
  36. data/lib/ffi/gdal/{gdal_color_entry.rb → color_entry.rb} +1 -2
  37. data/lib/ffi/gdal/exceptions.rb +6 -0
  38. data/lib/ffi/gdal/{gdal_gcp.rb → gcp.rb} +1 -3
  39. data/lib/ffi/gdal/{gdal_h.rb → gdal.rb} +253 -252
  40. data/lib/ffi/gdal/grid.rb +58 -0
  41. data/lib/ffi/gdal/{gdal_grid_data_metrics_options.rb → grid_data_metrics_options.rb} +1 -2
  42. data/lib/ffi/gdal/{gdal_grid_inverse_distance_to_a_power_options.rb → grid_inverse_distance_to_a_power_options.rb} +1 -2
  43. data/lib/ffi/gdal/{gdal_grid_moving_average_options.rb → grid_moving_average_options.rb} +1 -2
  44. data/lib/ffi/gdal/{gdal_grid_nearest_neighbor_options.rb → grid_nearest_neighbor_options.rb} +1 -2
  45. data/lib/ffi/gdal/matching.rb +20 -0
  46. data/lib/ffi/gdal/{gdal_rpc_info.rb → rpc_info.rb} +1 -2
  47. data/lib/ffi/gdal/{gdal_transformer_info.rb → transformer_info.rb} +1 -2
  48. data/lib/ffi/gdal/version.rb +1 -1
  49. data/lib/ffi/gdal/vrt.rb +92 -0
  50. data/lib/ffi/gdal/{gdal_warp_options.rb → warp_options.rb} +8 -4
  51. data/lib/ffi/gdal/warper.rb +70 -0
  52. data/lib/ffi/gdal.rb +56 -69
  53. data/lib/ffi/ogr/api.rb +567 -0
  54. data/lib/ffi/ogr/{ogr_contour_writer_info.rb → contour_writer_info.rb} +2 -3
  55. data/lib/ffi/ogr/core.rb +181 -0
  56. data/lib/ffi/ogr/envelope.rb +12 -0
  57. data/lib/ffi/ogr/{ogr_envelope_3d.rb → envelope_3d.rb} +2 -2
  58. data/lib/ffi/ogr/featurestyle.rb +29 -0
  59. data/lib/ffi/ogr/field.rb +63 -0
  60. data/lib/ffi/ogr/geocoding.rb +30 -0
  61. data/lib/ffi/ogr/srs_api.rb +407 -0
  62. data/lib/ffi/ogr/style_param.rb +13 -0
  63. data/lib/ffi/ogr/{ogr_style_value.rb → style_value.rb} +4 -3
  64. data/lib/ffi/ogr.rb +7 -7
  65. data/lib/ffi-gdal.rb +7 -145
  66. data/lib/gdal/color_entry.rb +18 -14
  67. data/lib/gdal/color_entry_mixins/extensions.rb +32 -0
  68. data/lib/gdal/color_interpretation.rb +2 -2
  69. data/lib/gdal/color_table.rb +37 -32
  70. data/lib/gdal/color_table_mixins/extensions.rb +48 -0
  71. data/lib/gdal/cpl_error_handler.rb +119 -0
  72. data/lib/gdal/data_type.rb +7 -7
  73. data/lib/gdal/dataset.rb +131 -238
  74. data/lib/gdal/dataset_mixins/algorithm_methods.rb +182 -0
  75. data/lib/gdal/dataset_mixins/extensions.rb +542 -0
  76. data/lib/gdal/dataset_mixins/matching.rb +26 -0
  77. data/lib/gdal/driver.rb +68 -92
  78. data/lib/gdal/driver_mixins/extensions.rb +93 -0
  79. data/lib/gdal/exceptions.rb +32 -4
  80. data/lib/gdal/geo_transform.rb +63 -43
  81. data/lib/gdal/geo_transform_mixins/extensions.rb +57 -0
  82. data/lib/gdal/grid.rb +144 -0
  83. data/lib/gdal/grid_types/data_metrics_base.rb +14 -0
  84. data/lib/gdal/grid_types/inverse_distance_to_a_power.rb +19 -0
  85. data/lib/gdal/grid_types/metric_average_distance.rb +12 -0
  86. data/lib/gdal/grid_types/metric_average_distance_pts.rb +12 -0
  87. data/lib/gdal/grid_types/metric_count.rb +12 -0
  88. data/lib/gdal/grid_types/metric_maximum.rb +12 -0
  89. data/lib/gdal/grid_types/metric_minimum.rb +12 -0
  90. data/lib/gdal/grid_types/metric_range.rb +12 -0
  91. data/lib/gdal/grid_types/moving_average.rb +19 -0
  92. data/lib/gdal/grid_types/nearest_neighbor.rb +19 -0
  93. data/lib/gdal/grid_types.rb +22 -0
  94. data/lib/gdal/internal_helpers.rb +94 -0
  95. data/lib/gdal/major_object.rb +4 -7
  96. data/lib/gdal/options.rb +14 -7
  97. data/lib/gdal/raster_attribute_table.rb +38 -47
  98. data/lib/gdal/raster_attribute_table_mixins/extensions.rb +41 -0
  99. data/lib/gdal/raster_band.rb +193 -227
  100. data/lib/gdal/raster_band_classifier.rb +107 -0
  101. data/lib/gdal/raster_band_mixins/algorithm_methods.rb +292 -0
  102. data/lib/gdal/raster_band_mixins/extensions.rb +238 -0
  103. data/lib/gdal/rpc_info.rb +35 -0
  104. data/lib/gdal/transformer.rb +15 -0
  105. data/lib/gdal/transformers/approximate_transformer.rb +48 -0
  106. data/lib/gdal/transformers/base_general_image_projection_transformer.rb +45 -0
  107. data/lib/gdal/transformers/gcp_transformer.rb +55 -0
  108. data/lib/gdal/transformers/general_image_projection_transformer.rb +31 -0
  109. data/lib/gdal/transformers/general_image_projection_transformer2.rb +52 -0
  110. data/lib/gdal/transformers/general_image_projection_transformer3.rb +25 -0
  111. data/lib/gdal/transformers/geolocation_transformer.rb +42 -0
  112. data/lib/gdal/transformers/reprojection_transformer.rb +39 -0
  113. data/lib/gdal/transformers/rpc_transformer.rb +56 -0
  114. data/lib/gdal/transformers/tps_transformer.rb +40 -0
  115. data/lib/gdal/virtual_dataset.rb +96 -0
  116. data/lib/gdal/warp_operation.rb +20 -23
  117. data/lib/gdal.rb +17 -0
  118. data/lib/ogr/coordinate_transformation.rb +16 -41
  119. data/lib/ogr/data_source.rb +103 -58
  120. data/lib/ogr/data_source_extensions.rb +5 -6
  121. data/lib/ogr/data_source_mixins/capability_methods.rb +27 -0
  122. data/lib/ogr/driver.rb +61 -33
  123. data/lib/ogr/driver_mixins/capability_methods.rb +16 -0
  124. data/lib/ogr/envelope.rb +29 -18
  125. data/lib/ogr/envelope_extensions.rb +70 -49
  126. data/lib/ogr/error_handling.rb +46 -0
  127. data/lib/ogr/exceptions.rb +58 -12
  128. data/lib/ogr/feature.rb +334 -86
  129. data/lib/ogr/feature_definition.rb +94 -51
  130. data/lib/ogr/feature_definition_extensions.rb +36 -13
  131. data/lib/ogr/feature_extensions.rb +62 -11
  132. data/lib/ogr/field.rb +175 -54
  133. data/lib/ogr/field_definition.rb +110 -0
  134. data/lib/ogr/{field_extensions.rb → field_definition_extensions.rb} +4 -5
  135. data/lib/ogr/{geocoding_session.rb → geocoder.rb} +14 -13
  136. data/lib/ogr/geometries/geometry_collection.rb +13 -0
  137. data/lib/ogr/geometries/line_string.rb +35 -0
  138. data/lib/ogr/geometries/linear_ring.rb +11 -0
  139. data/lib/ogr/geometries/multi_line_string.rb +16 -0
  140. data/lib/ogr/geometries/multi_point.rb +14 -0
  141. data/lib/ogr/geometries/multi_polygon.rb +21 -0
  142. data/lib/ogr/geometries/none_geometry.rb +13 -0
  143. data/lib/ogr/geometries/point.rb +65 -0
  144. data/lib/ogr/geometries/point_extensions.rb +32 -0
  145. data/lib/ogr/geometries/polygon.rb +14 -0
  146. data/lib/ogr/geometries/unknown_geometry.rb +10 -0
  147. data/lib/ogr/geometry.rb +270 -242
  148. data/lib/ogr/geometry_extensions.rb +8 -9
  149. data/lib/ogr/geometry_field_definition.rb +99 -0
  150. data/lib/ogr/geometry_field_definition_extensions.rb +19 -0
  151. data/lib/ogr/geometry_types/container.rb +75 -0
  152. data/lib/ogr/geometry_types/curve.rb +25 -28
  153. data/lib/ogr/geometry_types/surface.rb +13 -4
  154. data/lib/ogr/internal_helpers.rb +57 -0
  155. data/lib/ogr/layer.rb +60 -181
  156. data/lib/ogr/layer_mixins/capability_methods.rb +102 -0
  157. data/lib/ogr/layer_mixins/extensions.rb +59 -0
  158. data/lib/ogr/layer_mixins/ogr_feature_methods.rb +127 -0
  159. data/lib/ogr/layer_mixins/ogr_field_methods.rb +143 -0
  160. data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +163 -0
  161. data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +89 -0
  162. data/lib/ogr/layer_mixins/ogr_sql_methods.rb +48 -0
  163. data/lib/ogr/spatial_reference.rb +108 -589
  164. data/lib/ogr/spatial_reference_extensions.rb +29 -3
  165. data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +494 -0
  166. data/lib/ogr/spatial_reference_mixins/exporters.rb +134 -0
  167. data/lib/ogr/spatial_reference_mixins/importers.rb +243 -0
  168. data/lib/ogr/spatial_reference_mixins/morphers.rb +25 -0
  169. data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +122 -0
  170. data/lib/ogr/spatial_reference_mixins/type_checks.rb +62 -0
  171. data/lib/ogr/style_table.rb +53 -5
  172. data/lib/ogr/style_table_extensions.rb +21 -5
  173. data/lib/ogr/style_tool.rb +118 -0
  174. data/lib/ogr.rb +8 -0
  175. data/spec/ffi-gdal_spec.rb +1 -2
  176. data/spec/integration/{color_table_info_spec.rb → gdal/color_table_info_spec.rb} +12 -12
  177. data/spec/integration/{dataset_info_spec.rb → gdal/dataset_info_spec.rb} +2 -6
  178. data/spec/integration/{driver_info_spec.rb → gdal/driver_info_spec.rb} +5 -5
  179. data/spec/integration/{geo_transform_info_spec.rb → gdal/geo_transform_info_spec.rb} +1 -14
  180. data/spec/integration/{raster_attribute_table_info_spec.rb → gdal/raster_attribute_table_info_spec.rb} +1 -2
  181. data/spec/integration/{raster_band_info_spec.rb → gdal/raster_band_info_spec.rb} +30 -42
  182. data/spec/integration/ogr/layer_spec.rb +97 -0
  183. data/spec/spec_helper.rb +94 -5
  184. data/spec/support/integration_help.rb +1 -0
  185. data/spec/support/shared_contexts.rb +26 -0
  186. data/spec/support/shared_examples/{major_object_examples.rb → gdal/major_object_examples.rb} +5 -5
  187. data/spec/support/shared_examples/ogr/a_25D_geometry.rb +7 -0
  188. data/spec/support/shared_examples/ogr/a_container_geometry.rb +47 -0
  189. data/spec/support/shared_examples/ogr/a_geometry.rb +404 -0
  190. data/spec/support/shared_examples/ogr/a_line_string.rb +16 -0
  191. data/spec/support/test_style_table.txt +3 -0
  192. data/spec/unit/ext/error_symbols_spec.rb +41 -53
  193. data/spec/unit/ext/numeric_as_data_type_spec.rb +113 -0
  194. data/spec/unit/ffi/gdal_spec.rb +70 -0
  195. data/spec/unit/gdal/color_entry_spec.rb +5 -0
  196. data/spec/unit/gdal/color_interpretation_spec.rb +5 -0
  197. data/spec/unit/gdal/{color_table_extensions_spec.rb → color_table_mixins/extensions_spec.rb} +3 -3
  198. data/spec/unit/gdal/color_table_spec.rb +14 -16
  199. data/spec/unit/gdal/data_type_spec.rb +10 -17
  200. data/spec/unit/gdal/dataset_spec.rb +4 -7
  201. data/spec/unit/gdal/driver_mixins/extensions_spec.rb +22 -0
  202. data/spec/unit/gdal/driver_spec.rb +49 -0
  203. data/spec/unit/gdal/environment_methods_spec.rb +6 -0
  204. data/spec/unit/gdal/geo_transform_spec.rb +276 -0
  205. data/spec/unit/gdal/grid_spec.rb +5 -0
  206. data/spec/unit/gdal/internal_helpers_spec.rb +112 -0
  207. data/spec/unit/gdal/major_object_spec.rb +6 -0
  208. data/spec/unit/gdal/options_spec.rb +5 -0
  209. data/spec/unit/gdal/raster_attribute_table_spec.rb +5 -0
  210. data/spec/unit/gdal/raster_band_classifier_spec.rb +134 -0
  211. data/spec/unit/gdal/raster_band_spec.rb +5 -0
  212. data/spec/unit/gdal/rpc_info_spec.rb +5 -0
  213. data/spec/unit/gdal/version_info_spec.rb +6 -0
  214. data/spec/unit/gdal/virtual_dataset_spec.rb +32 -0
  215. data/spec/unit/gdal/warp_operation_spec.rb +5 -0
  216. data/spec/unit/ogr/data_source_mixins/capability_methods_spec.rb +30 -0
  217. data/spec/unit/ogr/data_source_spec.rb +209 -0
  218. data/spec/unit/ogr/driver_mixins/capability_methods_spec.rb +18 -0
  219. data/spec/unit/ogr/driver_spec.rb +150 -0
  220. data/spec/unit/ogr/envelope_spec.rb +322 -0
  221. data/spec/unit/ogr/feature_definition_spec.rb +313 -0
  222. data/spec/unit/ogr/feature_spec.rb +379 -0
  223. data/spec/unit/ogr/field_definition_spec.rb +135 -0
  224. data/spec/unit/ogr/field_spec.rb +193 -0
  225. data/spec/unit/ogr/geometries/geometry_collection_spec.rb +186 -0
  226. data/spec/unit/ogr/geometries/line_string_spec.rb +105 -0
  227. data/spec/unit/ogr/{linear_ring_spec.rb → geometries/linear_ring_spec.rb} +10 -31
  228. data/spec/unit/ogr/geometries/multi_line_string_spec.rb +14 -0
  229. data/spec/unit/ogr/geometries/multi_point_spec.rb +14 -0
  230. data/spec/unit/ogr/geometries/multi_polygon_spec.rb +41 -0
  231. data/spec/unit/ogr/geometries/none_geometry_spec.rb +12 -0
  232. data/spec/unit/ogr/{point_spec.rb → geometries/point_spec.rb} +19 -25
  233. data/spec/unit/ogr/geometries/polygon_spec.rb +17 -0
  234. data/spec/unit/ogr/geometries/unknown_geometry_spec.rb +10 -0
  235. data/spec/unit/ogr/geometry_field_definition_spec.rb +87 -0
  236. data/spec/unit/ogr/geometry_spec.rb +542 -0
  237. data/spec/unit/ogr/internal_helpers_spec.rb +57 -0
  238. data/spec/unit/ogr/layer_mixins/capability_methods_spec.rb +88 -0
  239. data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +145 -0
  240. data/spec/unit/ogr/layer_mixins/ogr_field_methods_spec.rb +432 -0
  241. data/spec/unit/ogr/layer_mixins/ogr_layer_method_methods_spec.rb +20 -0
  242. data/spec/unit/ogr/layer_mixins/ogr_query_filter_methods_spec.rb +42 -0
  243. data/spec/unit/ogr/layer_mixins/ogr_sql_methods_spec.rb +12 -0
  244. data/spec/unit/ogr/layer_spec.rb +66 -67
  245. data/spec/unit/ogr/spatial_reference_mixins/coordinate_system_getter_setters_spec.rb +46 -0
  246. data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +139 -0
  247. data/spec/unit/ogr/spatial_reference_mixins/importers_spec.rb +38 -0
  248. data/spec/unit/ogr/spatial_reference_mixins/morphers_spec.rb +36 -0
  249. data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +102 -0
  250. data/spec/unit/ogr/spatial_reference_mixins/type_checks_spec.rb +157 -0
  251. data/spec/unit/ogr/spatial_reference_spec.rb +42 -0
  252. data/spec/unit/ogr/style_table_spec.rb +132 -0
  253. data/spec/unit/ogr/style_tool_spec.rb +157 -0
  254. data/spec/unit/version_info_spec.rb +1 -1
  255. metadata +285 -75
  256. data/lib/ffi/cpl/conv_h.rb +0 -143
  257. data/lib/ffi/cpl/error_h.rb +0 -63
  258. data/lib/ffi/cpl/minixml_h.rb +0 -14
  259. data/lib/ffi/cpl/string_h.rb +0 -81
  260. data/lib/ffi/cpl/vsi_h.rb +0 -112
  261. data/lib/ffi/gdal/alg_h.rb +0 -127
  262. data/lib/ffi/gdal/grid_h.rb +0 -51
  263. data/lib/ffi/gdal/warper_h.rb +0 -48
  264. data/lib/ffi/ogr/api_h.rb +0 -553
  265. data/lib/ffi/ogr/core_h.rb +0 -148
  266. data/lib/ffi/ogr/featurestyle_h.rb +0 -22
  267. data/lib/ffi/ogr/geocoding_h.rb +0 -21
  268. data/lib/ffi/ogr/ogr_field.rb +0 -50
  269. data/lib/ffi/ogr/ogr_style_param.rb +0 -12
  270. data/lib/ffi/ogr/srs_api_h.rb +0 -325
  271. data/lib/gdal/color_entry_extensions.rb +0 -30
  272. data/lib/gdal/color_table_extensions.rb +0 -47
  273. data/lib/gdal/dataset_extensions.rb +0 -496
  274. data/lib/gdal/driver_extensions.rb +0 -56
  275. data/lib/gdal/geo_transform_extensions.rb +0 -90
  276. data/lib/gdal/raster_attribute_table_extensions.rb +0 -40
  277. data/lib/gdal/raster_band_extensions.rb +0 -198
  278. data/lib/ogr/geometry_types/collection.rb +0 -45
  279. data/lib/ogr/layer_extensions.rb +0 -55
  280. data/lib/ogr/line_string.rb +0 -7
  281. data/lib/ogr/linear_ring.rb +0 -6
  282. data/lib/ogr/multi_line_string.rb +0 -9
  283. data/lib/ogr/multi_point.rb +0 -7
  284. data/lib/ogr/multi_polygon.rb +0 -14
  285. data/lib/ogr/point.rb +0 -89
  286. data/lib/ogr/polygon.rb +0 -9
@@ -1,198 +0,0 @@
1
- require 'json'
2
-
3
- module GDAL
4
- module RasterBandExtensions
5
- def overviews
6
- 0.upto(overview_count - 1).map do |i|
7
- overview(i)
8
- end
9
- end
10
-
11
- # @return [Hash{x => Fixnum, y => Fixnum}]
12
- def block_count
13
- x_blocks = (x_size + block_size[:x] - 1) / block_size[:x]
14
- y_blocks = (y_size + block_size[:y] - 1) / block_size[:y]
15
-
16
- { x: x_blocks, y: y_blocks }
17
- end
18
-
19
- # The buffer size to use for block-based IO, based on #block_size.
20
- #
21
- # @return [Fixnum]
22
- def block_buffer_size
23
- block_size[:x] * block_size[:y]
24
- end
25
-
26
- # Reads through the raster, block-by-block and yields the pixel data that
27
- # it gathered.
28
- #
29
- # @param to_data_type [FFI::GDAL::GDALDataType]
30
- # @return [Enumerator, nil] Returns an Enumerable if no block is given,
31
- # allowing to chain with other Enumerable methods. Returns nil if a
32
- # block is given.
33
- def each_by_block(to_data_type=nil)
34
- return enum_for(:each_by_block) unless block_given?
35
-
36
- data_type = to_data_type || self.data_type
37
- data_pointer = GDAL._pointer_from_data_type(data_type, block_buffer_size)
38
-
39
- 0.upto(block_count[:y] - 1).each do |y_block_number|
40
- 0.upto(block_count[:x] - 1).each do |x_block_number|
41
- read_block(x_block_number, y_block_number, data_pointer)
42
-
43
- 0.upto(block_size[:y] - 1).each do |block_index|
44
- read_offset = block_size[:x] * block_index
45
- pixels = if data_type == :GDT_Byte
46
- data_pointer.get_array_of_uint8(read_offset, block_size[:x])
47
- else
48
- data_pointer.get_array_of_float(read_offset, block_size[:x])
49
- end
50
-
51
- yield(pixels)
52
- end
53
- end
54
- end
55
- end
56
-
57
- # Iterates through all lines and builds an NArray of pixels.
58
- #
59
- # @return [NArray]
60
- def to_na(to_data_type=nil)
61
- data_type = to_data_type || self.data_type
62
-
63
- values = each_by_block(to_data_type).map do |pixels|
64
- pixels
65
- end
66
-
67
- case data_type
68
- when :GDT_Byte then NArray.to_na(values).to_type(NArray::BYTE)
69
- when :GDT_UInt16 then NArray.to_na(values).to_type(NArray::SINT)
70
- when :GDT_Int16 then NArray.to_na(values).to_type(NArray::SINT)
71
- when :GDT_UInt32 then NArray.to_na(values).to_type(NArray::INT)
72
- when :GDT_Int32 then NArray.to_na(values).to_type(NArray::INT)
73
- when :GDT_Float32 then NArray.to_na(values).to_type(NArray::SFLOAT)
74
- when :GDT_Float64 then NArray.to_na(values).to_type(NArray::DFLOAT)
75
- when :GDT_CInt16 then NArray.to_na(values).to_type(NArray::SCOMPLEX)
76
- when :GDT_CInt32 then NArray.to_na(values).to_type(NArray::DCOMPLEX)
77
- when :GDT_CFloat32 then NArray.to_na(values).to_type(NArray::SCOMPLEX)
78
- when :GDT_CFloat64 then NArray.to_na(values).to_type(NArray::DCOMPLEX)
79
- else
80
- NArray.to_na(values)
81
- end
82
- end
83
-
84
- # Sets the band to be a Palette band, then applies an RGB color table using
85
- # the given colors. Colors are distributed evenly across the table based
86
- # on the number of colors given. Note that this will overwrite any existing
87
- # color table that may be set on this band.
88
- #
89
- # @param colors [Array<Fixnum, String>, Fixnum, String] Can be a single or
90
- # many colors, given as either R, G, and B integers (0-255) or as strings
91
- # of Hex.
92
- #
93
- # @example Colors as RGB values
94
- # # This will make the first 128 values black, and the last 128, red.
95
- # my_band.colorize!([[0, 0, 0], [255, 0, 0]])
96
- #
97
- # @example Colors as Hex values
98
- # # Same as above...
99
- # my_band.colorize!(%w[#000000 #FF0000])
100
- def colorize!(*colors)
101
- return if colors.empty?
102
-
103
- table = GDAL::ColorTable.create(:GPI_RGB)
104
-
105
- color_entry_index_count = if data_type == :GDT_Byte
106
- 256
107
- elsif data_type == :GDT_UInt16
108
- 65536
109
- else
110
- raise "Can't colorize a #{data_type} band--must be :GDT_Byte or :GDT_UInt16"
111
- end
112
-
113
- self.color_interpretation ||= :GCI_PaletteIndex
114
- table.add_color_entry(0, 0, 0, 0, 255)
115
- bin_count = color_entry_index_count / colors.size.to_f
116
-
117
- 1.upto(color_entry_index_count - 1) do |color_entry_index|
118
- color_number = (color_entry_index / bin_count).to_i
119
-
120
- color = colors[color_number]
121
- rgb_array = hex_to_rgb(color) unless color.is_a?(Array)
122
- table.add_color_entry(color_entry_index,
123
- rgb_array[0], rgb_array[1], rgb_array[2], 255)
124
- end
125
-
126
- self.color_table = table
127
- end
128
-
129
-
130
- # Gets the colors from the associated ColorTable and returns an Array of
131
- # those, where each ColorEntry is [R, G, B, A].
132
- #
133
- # @return [Array<Array<Fixnum>>]
134
- def colors_as_rgb
135
- return [] unless color_table
136
-
137
- color_table.color_entries_as_rgb.map do |color_entry|
138
- color_entry.to_a
139
- end
140
- end
141
-
142
- # Gets the colors from the associated ColorTable and returns an Array of
143
- # Strings, where the RGB color for each ColorEntry has been converted to
144
- # Hex.
145
- #
146
- # @return [Array<String>]
147
- def colors_as_hex
148
- colors_as_rgb.map do |rgba|
149
- rgb = rgba.to_a[0..2]
150
-
151
- "##{rgb[0].to_s(16)}#{rgb[1].to_s(16)}#{rgb[2].to_s(16)}"
152
- end
153
- end
154
-
155
- # @param hex [String]
156
- def hex_to_rgb(hex)
157
- hex.sub!(/^#/, '')
158
- matches = hex.match(/(?<red>[a-zA-Z0-9]{2})(?<green>[a-zA-Z0-9]{2})(?<blue>[a-zA-Z0-9]{2})/)
159
-
160
- [matches[:red].to_i(16), matches[:green].to_i(16), matches[:blue].to_i(16)]
161
- end
162
-
163
- # @return [Hash]
164
- def as_json
165
- {
166
- raster_band: {
167
- block_size: block_size,
168
- category_names: category_names,
169
- color_interpretation: color_interpretation,
170
- color_table: color_table,
171
- data_type: data_type,
172
- default_histogram: default_histogram(true),
173
- default_raster_attribute_table: default_raster_attribute_table,
174
- has_arbitrary_overviews: arbitrary_overviews?,
175
- mask_flags: mask_flags,
176
- maximum_value: maximum_value,
177
- minimum_value: minimum_value,
178
- no_data_value: no_data_value,
179
- number: number,
180
- offset: offset,
181
- overview_count: overview_count,
182
- overviews: overviews,
183
- scale: scale,
184
- statistics: statistics,
185
- unit_type: unit_type,
186
- x_size: x_size,
187
- y_size: y_size
188
- },
189
- metadata: all_metadata
190
- }
191
- end
192
-
193
- # @return [String]
194
- def to_json
195
- as_json.to_json
196
- end
197
- end
198
- end
@@ -1,45 +0,0 @@
1
- module OGR
2
- module GeometryTypes
3
- module Collection
4
- def collection?
5
- true
6
- end
7
-
8
- # If this geometry is a container, this fetches the geometry at the
9
- # sub_geometry_index.
10
- #
11
- # @param sub_geometry_index [Fixnum]
12
- # @return [OGR::Geometry]
13
- def geometry_at(sub_geometry_index)
14
- build_geometry do |ptr|
15
- FFI::GDAL.OGR_G_GetGeometryRef(ptr, sub_geometry_index)
16
- end
17
- end
18
-
19
- # Build a ring from a bunch of arcs.
20
- #
21
- # @param tolerance [Float]
22
- # @param auto_close [Boolean]
23
- # @return [OGR::Geometry]
24
- def polygon_from_edges(tolerance, auto_close)
25
- best_effort = false
26
- ogrerr_ptr = FFI::MemoryPointer.new(:pointer)
27
-
28
- new_geometry_ptr = FFI::GDAL.OGRBuildPolygonFromEdges(@geometry_pointer,
29
- best_effort,
30
- auto_close,
31
- tolerance,
32
- ogrerr_ptr)
33
-
34
- ogrerr_int = ogrerr_ptr.read_int
35
- ogrerr = FFI::GDAL::OGRErr[ogrerr_int]
36
-
37
- if ogrerr == :OGRERR_FAILURE
38
- raise "Couldn't create polygon"
39
- end
40
-
41
- self.class._to_geometry_type(new_geometry_ptr)
42
- end
43
- end
44
- end
45
- end
@@ -1,55 +0,0 @@
1
- require 'json'
2
-
3
- module OGR
4
- module LayerExtensions
5
-
6
- # @return [Array<OGR::Feature>]
7
- def features
8
- feature_list = 0.upto(feature_count - 1).map do |i|
9
- feature(i)
10
- end
11
-
12
- @features = feature_list
13
- end
14
-
15
- # @return [OGR::Geometry] A convex hull geometry derived from a LineString
16
- # that connects the 4 bounding box points (from the extent).
17
- def geometry_from_extent
18
- sr = spatial_reference
19
- geometry = OGR::Geometry.create(:wkbLineString)
20
- geometry.spatial_reference = sr
21
-
22
- geometry.add_point(extent.x_min, extent.y_min)
23
- geometry.add_point(extent.x_min, extent.y_max)
24
- geometry.add_point(extent.x_max, extent.y_max)
25
- geometry.add_point(extent.x_max, extent.y_min)
26
- geometry.add_point(extent.x_min, extent.y_min)
27
-
28
- geometry.convex_hull
29
- end
30
-
31
- # @return [Hash]
32
- def as_json
33
- {
34
- layer: {
35
- extent: extent.as_json,
36
- feature_count: feature_count,
37
- feature_definition: feature_definition.as_json,
38
- features: features.map(&:as_json),
39
- fid_column: fid_column,
40
- geometry_column: geometry_column,
41
- geometry_type: geometry_type,
42
- name: name,
43
- spatial_reference: spatial_reference.as_json,
44
- style_table: style_table ? style_table.as_json : nil
45
- },
46
- metadata: nil #all_metadata
47
- }
48
- end
49
-
50
- # @return [String]
51
- def to_json
52
- as_json.to_json
53
- end
54
- end
55
- end
@@ -1,7 +0,0 @@
1
- require_relative 'geometry_types/curve'
2
-
3
- module OGR
4
- class LineString < Geometry
5
- include GeometryTypes::Curve
6
- end
7
- end
@@ -1,6 +0,0 @@
1
- require_relative 'line_string'
2
-
3
- module OGR
4
- class LinearRing < LineString
5
- end
6
- end
@@ -1,9 +0,0 @@
1
- require_relative 'geometry_types/curve'
2
- require_relative 'geometry_types/collection'
3
-
4
- module OGR
5
- class MultiLineString < Geometry
6
- include GeometryTypes::Curve
7
- include GeometryTypes::Collection
8
- end
9
- end
@@ -1,7 +0,0 @@
1
- require_relative 'geometry_types/collection'
2
-
3
- module OGR
4
- class MultiPoint < Geometry
5
- include GeometryTypes::Collection
6
- end
7
- end
@@ -1,14 +0,0 @@
1
- require_relative 'geometry_types/collection'
2
- require_relative 'geometry_types/surface'
3
-
4
- module OGR
5
- class MultiPolygon < Geometry
6
- include GeometryTypes::Collection
7
- include GeometryTypes::Surface
8
-
9
- # @return [OGR::Geometry]
10
- def union_cascaded
11
- build_geometry { |ptr| FFI::GDAL.OGR_G_UnionCascaded(ptr) }
12
- end
13
- end
14
- end
data/lib/ogr/point.rb DELETED
@@ -1,89 +0,0 @@
1
- module OGR
2
- class Point < Geometry
3
- # def area
4
- # 0.0
5
- # end
6
-
7
- # @return [Float]
8
- def x
9
- return nil if empty?
10
-
11
- FFI::GDAL.OGR_G_GetX(@geometry_pointer, 0)
12
- end
13
-
14
- # @return [Float]
15
- def y
16
- return nil if empty?
17
-
18
- FFI::GDAL.OGR_G_GetY(@geometry_pointer, 0)
19
- end
20
-
21
- # @return [Float]
22
- def z
23
- return nil if empty?
24
-
25
- FFI::GDAL.OGR_G_GetZ(@geometry_pointer, 0)
26
- end
27
-
28
- # @return [Array<Float, Float, Float>] [x, y] if 2d or [x, y, z] if 3d.
29
- def point
30
- return [] if empty?
31
-
32
- x_ptr = FFI::MemoryPointer.new(:double)
33
- y_ptr = FFI::MemoryPointer.new(:double)
34
- z_ptr = FFI::MemoryPointer.new(:double)
35
-
36
- FFI::GDAL.OGR_G_GetPoint(@geometry_pointer, 0, x_ptr, y_ptr, z_ptr)
37
-
38
- if coordinate_dimension == 2
39
- [x_ptr.read_double, y_ptr.read_double]
40
- else
41
- [x_ptr.read_double, y_ptr.read_double, z_ptr.read_double]
42
- end
43
- end
44
-
45
- def set_point(x, y, z=0)
46
- FFI::GDAL.OGR_G_SetPoint(@geometry_pointer, 0, x, y, z)
47
- end
48
-
49
- # Adds a point to a LineString or Point geometry.
50
- #
51
- # @param x [Float]
52
- # @param y [Float]
53
- # @param z [Float]
54
- def add_point(x, y, z=0)
55
- FFI::GDAL.OGR_G_AddPoint(@geometry_pointer, x, y, z)
56
- end
57
-
58
- # @return [Array<Array>] An array of (x, y) or (x, y, z) points.
59
- def points
60
- return [[]] if empty?
61
-
62
- x_stride = 2
63
- y_stride = 2
64
- z_stride = coordinate_dimension == 3 ? 1 : 0
65
-
66
- buffer_size = FFI::Type::DOUBLE.size * 2 * point_count
67
-
68
- x_buffer = FFI::MemoryPointer.new(:buffer_out, buffer_size)
69
- y_buffer = FFI::MemoryPointer.new(:buffer_out, buffer_size)
70
-
71
- z_buffer = if coordinate_dimension == 3
72
- z_size = FFI::Type::DOUBLE.size * point_count
73
- FFI::MemoryPointer.new(:buffer_out, z_size)
74
- else
75
- nil
76
- end
77
-
78
- num_points = FFI::GDAL.OGR_G_GetPoints(@geometry_pointer,
79
- x_buffer,
80
- x_stride,
81
- y_buffer,
82
- y_stride,
83
- z_buffer,
84
- z_stride)
85
-
86
- [point]
87
- end
88
- end
89
- end
data/lib/ogr/polygon.rb DELETED
@@ -1,9 +0,0 @@
1
- require_relative 'geometry_types/surface'
2
- require_relative 'geometry_types/collection'
3
-
4
- module OGR
5
- class Polygon < Geometry
6
- include GeometryTypes::Surface
7
- include GeometryTypes::Collection
8
- end
9
- end