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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5e2273d2b75bb5a7af15693af6a84cb32c74852
4
- data.tar.gz: f986fe1b75a472ce0a0d663d13ceed15714e0ef0
3
+ metadata.gz: 82ca64b9a92e057bf506f537804b6e26aee42281
4
+ data.tar.gz: 96ce8a17293f28885113c73df4f06b53780a518d
5
5
  SHA512:
6
- metadata.gz: 584e34e7de26e51fff046707de49750f8071d937dac8259ad594387f1ff60c7bca2fa72c22fad48525fdd3cf42a6d734a564d4d054aac675ba48c7a55ed4e3e8
7
- data.tar.gz: c8eca7619a1eeaf878582c8efead2bde968a52149e92cd64ad37fbb3475bcc2f25ba2182da3cfa200e9ce8925ca90c60a55be5b59b43998d1d2a867843f35e7a
6
+ metadata.gz: 0c44973c096820715f5c8860c5ac55f85fa90b94f06a88fec64e257e78478c64f192d4938ec25b38efbac6e74f29289b5ff7cf93a229864c0416365bb058a33c
7
+ data.tar.gz: f9a8fba2bdcbe83bb2359c48c4559e257b9fed4d30667eb8e878e7bdb0ac1e5afde35fce330636377f5ef7b1fec2bea6436fdd4b3a6088fed5cbb5014557ec52
data/.gitignore CHANGED
@@ -14,21 +14,25 @@ rdoc
14
14
  spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
- tmp
17
+ tmp/*
18
18
  *.bundle
19
19
  *.so
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
23
  .idea/
24
- spec/support/images
25
24
  tags
26
25
  *.sqlite
27
26
  vendor/bundle
28
- *.tif
29
27
  *.xml
30
28
  *.dbf
31
29
  *.shx
32
30
  .rake_tasks
33
31
  valgrind_output.log
34
32
  *.xsd
33
+
34
+ *.swp
35
+
36
+ .byebug_history
37
+
38
+ .tags
data/.rubocop.yml CHANGED
@@ -51,12 +51,19 @@ Style/PercentLiteralDelimiters:
51
51
  '%w': '[]'
52
52
  '%W': '[]'
53
53
 
54
+ Style/PredicateName:
55
+ Exclude:
56
+ - lib/ogr/geometry_mixins/extensions.rb
57
+
54
58
  Style/SymbolArray:
55
59
  Enabled: true
56
60
 
57
61
  AllCops:
62
+ DisplayCopNames: true
63
+ DisplayStyleGuide: true
58
64
  Include:
59
65
  - Gemfile
60
66
  - ffi-gdal.gemspec
61
67
  Exclude:
62
68
  - vendor/bundle/**/*
69
+ TargetRubyVersion: 2.2
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.0
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in ffi-gdal.gemspec
4
4
  gemspec
5
5
 
6
- gem 'byebug'
6
+ gem 'thor'
data/History.md CHANGED
@@ -2,6 +2,148 @@
2
2
 
3
3
  Format for this file derived from [http://keepachangelog.com](http://keepachangelog.com).
4
4
 
5
+ ## 1.0.0.beta6 / 2016-04-18
6
+
7
+ ### New Features
8
+
9
+ #### GDAL
10
+
11
+ * Added wrappers for the Grid API. It uses `GDAL::Gridder`, which is the
12
+ programmatic equivalent to the `gdal_grid` command-line utility,
13
+ `GDAL::GridderOptions`, which is an object used to mimic the options you pass
14
+ to `gdal_grid`, and `GDAL::Grid`, which is the simple object that performs the
15
+ gridding.
16
+ * Added first wrapper of `gdalwarper.h` methods, found in
17
+ `GDAL::DatasetMixins::WarpMethods`.
18
+
19
+ #### OGR
20
+
21
+ * Added `OGR::CoordinateTransform#transform_ex`.
22
+
23
+ ### Improvements
24
+
25
+ * Removed all `ObjectSpace.define_finalizer` calls that "cleaned up" C pointers
26
+ for Ruby-wrapped objects that had not yet been closed/destroyed. This was
27
+ keeping those Ruby objects from getting collected (?) and effectively causing
28
+ lots of unnecessary memory use.
29
+
30
+ #### GDAL
31
+
32
+ * Added `GDAL::GeoTransformMixins::Extensions.new_from_envelope` which lets you
33
+ create a `GDAL::GeoTransform` using the points from an `OGR::Envelope` and the
34
+ destination raster's width and height. It's convenient because it calculates
35
+ the pixel size for you.
36
+ * Renamed `GDAL::GridTypes` to `GDAL::GridAlgorithms`. This shouldn't impact
37
+ anyone/thing since it's only relative to the newly added Grid API wrapper.
38
+ There just happened to me some Grid cruft that had been laying around for some
39
+ time.
40
+ * Added `GDAL::RasterBand#write_block`. Somehow this went missing from previous
41
+ `RasterBand` wrapping.
42
+ * Renamed `GDAL::RasterBandMixins::Extenions#each_by_block` to `#read_by_block`.
43
+ Its functionality was doing reading, yet implied reading or writing; since
44
+ writing by block isn't needed anywhere internally yet, I just renamed this.
45
+ * Renamed `GDAL::RasterBandMixins#write_array` to `#write_xy_narray`. This
46
+ method's name inferred that it could write any old Array, but that's not the
47
+ case--it only writes 2D NArray data.
48
+ * Added `GDAL::InternalHelpers._buffer_from_data_type` to compliment the
49
+ existing `._pointer_from_data_type`. Useful for creating buffer-specific
50
+ pointers from a GDAL data type.
51
+ * `GDAL::DatasetMixins::Extensions#extent` now manually builds an `OGR::Polygon`
52
+ instead of polygonizing the entire dataset and taking the envelope of that.
53
+ Much faster this way.
54
+ * Refactored `GDAL::RasterBandMixins::Exsentions#projected_points` to return a
55
+ 3D NArray (indicating pixel/row position) instead of just a 2D NArray of
56
+ coordinates.
57
+ * Added `GDAL::InternalHelpers` methods for creating NArrays based on GDAL
58
+ data types.
59
+ * `GDAL::Options` values all have `#to_s` called on them to ensure they're
60
+ Strings before handing them over to GDAL. The GDAL options "hash" requires
61
+ that both keys and values be Strings.
62
+ * `GDAL::RasterBandMixins::AlgorithmMethods` that use GDALProgressFunc functions
63
+ can now participate in GDALScaledProgress functions.
64
+ * Added `GDAL::RasterBandMixins::Extensions#pixel_count`.
65
+ * Allow `GDAL::RasterBand#create_mask_band` to take a single flag or many.
66
+ * Allow `GDAL::Dataset`s to be open in shared mode vs non-shared mode. All
67
+ Datasets now default to use shared mode.
68
+ * Allow `GDAL::Driver#create_dataset` and `GDAL::Dataset.open` to take a block,
69
+ yielding the dataset then closing it afterwards.
70
+ * `GDAL::RasterBandClassifier` now uses NArray to classify. Can result in quite
71
+ a large performance gain.
72
+ * `GDAL::Driver#copy_dataset` now properly takes progress block arguments.
73
+ * `GDAL::Driver#copy_dataset` now yields a writable Dataset.
74
+ * Swapped order of params in `GDAL::Driver#rename_dataset` to be (old, new)
75
+ instead of (new, old).
76
+ * Added enumerator `RasterAttributeTableMixins::Extensions#each_column` to allow
77
+ nicer iterating over columns.
78
+ * `GDAL::RasterAttributeTable` methods that returned -1 when a value can't be
79
+ returned now return nil instead.
80
+ * Renamed `GDAL::RasterAttributeTable#value_to_*` methods to be named after
81
+ their C functions. Also, renamed `#add_value` to `#set_value` and refactored
82
+ into `RasterAttributeTableMixins::Extensions`.
83
+
84
+ #### OGR
85
+
86
+ * Added `OGR::FeatureExtensions#field()` which gets the field using the
87
+ associated `OGR::FieldDefinition#type`. Makes so you don't always have to
88
+ request the field by its type (`field_as_double`).
89
+ * Added `OGR::LayerMixins::Extensions#point_values()` which gets values for all
90
+ of the points in the layer. It also allows you to specify getting field values
91
+ with that, which helps retrieving data for the Grid API. You can also pass it
92
+ a block to filter out points that don't match some criteria defined in the
93
+ block.
94
+ * Added `OGR::LayerMixins::Extensions#any_geometries_with_z?` which simply
95
+ checks to see if the layer has any geometries with Z values.
96
+ * `GDAL::DataType.by_name` always calls `#to_s` on the param now, letting you
97
+ pass in Symbols.
98
+ * Added `OGR::Point#set_point`, `OGR::Point25#set_point`, and
99
+ `OGR::GeometryTypes::Curve#set_point` wrappers for `OGR_G_SetPoint_2D` and
100
+ `OGR_G_SetPoint`.
101
+ * Added `OGR::LineString#add_geometry` to allow adding a OGR::Point object to
102
+ the LineString instead of having to pass coordinates in to #add_point.
103
+ * `OGR::LayerMixins::Extensions#geometry_from_extent` now builds an
104
+ `OGR::Polygon` using the same algorithm that
105
+ `GDAL::DatasetMixins::Extensions#extent` uses. One could argue that there was
106
+ also a bug here in that `geometry_from_extent` used to return the convex hull
107
+ of the extent, not the extent itself.
108
+ * Extracted `OGR::LayerMixins::Extensions#each_feature` from
109
+ `OGR::LayerMixins::Extensions#features` to provide an Enumerator. This lets
110
+ consumers utilize yielded `OGR::Feature`s as they're retrieved instead of
111
+ after the `features` Array has been built.
112
+ `OGR::LayerMixins::Extensions#features` now uses this too.
113
+ * Added `OGR::GeometryMixins::Extensions#invalid?` to compliment
114
+ `OGR::Geometry#valid?`.
115
+ * Added `OGR::LayerMixins::Extensions#point_geometry`, `#each_point_geometry`,
116
+ and `point_geometries`. Since `#point` implies it returns a Point object, but
117
+ the OGR API's related method returns point values (x, y, z), it seemed like
118
+ it would be useful to have a method that returned a geometry.
119
+ * `OGR::DataSource.open` can now take a block, yielding the data source, then
120
+ closing it afterwards.
121
+
122
+ ### Bug Fixes
123
+
124
+ * Cleanup `OGR::Feature`s that were a result of `OGR::Layer#next_feature`.
125
+ According to GDAL docs, these *must* be cleaned up before the layer is.
126
+
127
+ #### GDAL
128
+
129
+ * `GDAL::RasterBandMixins::AlgorithmMethods#fill_nodata!` was calling the old
130
+ name of the C function.
131
+ * `GDAL::EnvironmentMethods#dump_open_datasets` now works.
132
+
133
+ #### OGR
134
+
135
+ * `OGR::Field#date=` was casting the passed value to a `Time` object, which in
136
+ doing so was setting the time zone. If a user passes in an object that doesn't
137
+ have the TZ set, the method shouldn't be setting it for them.
138
+ * `OGR::Geometry#point_on_surface` now properly returns a geometry object.
139
+ * `OGR::CoordinateTransform#transform` never worked. Fixed.
140
+ * `OGR::GeometryMixins::Extensions#utm_zone` no longer creates invalid geometry.
141
+ * `OGR::Feature#dump_readable` never worked. Fixed.
142
+ * `OGR::Geometry#dump_readable` never worked. Fixed.
143
+ * Added missing output_layer param to `OGR::LayerMixins::OGRLayerMethodMethods`.
144
+ * `FFI::OGR::Core::WKBGeometryType` was using an INT32 instead of UINT32 and
145
+ thus 25D geometry types weren't completely accurate.
146
+
5
147
  ## 1.0.0.beta5 / 2015-06-16
6
148
 
7
149
  * Improvements
@@ -72,7 +214,7 @@ Lots of changes, so just the highlights here...
72
214
  * Allow loading, even when C functions aren't defined in the version of
73
215
  GDAL that you're using.
74
216
  * Split out additions to GDAL/OGR in `*_extensions.rb` modules. Methods
75
- contained in `Extentions` modules don't directly wrap GDAL/OGR functions,
217
+ contained in `Extensions` modules don't directly wrap GDAL/OGR functions,
76
218
  but either provide new functionality or attempt to make library usage more
77
219
  Rubyesque.
78
220
  * Added `#as_json`, `#to_json` to many classes.
data/README.md CHANGED
@@ -28,13 +28,11 @@ you'll just want to use the Ruby-fied library, but if for some reason that
28
28
  doesn't get you what you want, direct access to the FFI wrapper (which is
29
29
  really just direct access to the C API) is available.
30
30
 
31
-
32
31
  ### The Ruby-fied Library
33
32
 
34
33
  To distinguish this gem from the already-existing gdal gem, you
35
34
  `require ffi-gdal` to get access to the `GDAL` module and its children.
36
35
 
37
-
38
36
  ### The direct FFI wrapper
39
37
 
40
38
  Following RubyGem conventions, to get access to the FFI wrapper, you
@@ -46,20 +44,16 @@ For classes that are enabled with logging capabilities, you can turn logging on
46
44
  and off like `GDAL::RasterBand.logging_enabled = true`. If you're using ffi-gdal
47
45
  in Rails, you can `GDAL::Logger.logger = Rails.logger`.
48
46
 
47
+ Additional Libraries
48
+ --------------------
49
49
 
50
- Testing
51
- -------
52
-
53
- You'll need some images to run the integration specs against, and instead of
54
- keeping those as part of this repo, there's a Rake task that will pull OSGeo's
55
- set of sample geotiffs down via FTP. Running `rake get_tiffs` will pull
56
- everything down from ftp://downloads.osgeo.org/geotiff/samples and put the
57
- files under spec/support/images/osgeo/geotiff.
50
+ [ffi-gdal-extensions](https://bitbucket.org/agrian/ffi-gdal-extensions) provides
51
+ additional functionality, not provided in this core, GDAL-wrapper library.
58
52
 
59
53
  Contributing
60
54
  ------------
61
55
 
62
- 1. Fork it ( https://github.com/turboladen/ffi-gdal/fork )
56
+ 1. Fork it ( https://bitbucket.org/agrian/ffi-gdal/fork )
63
57
  2. Create your feature branch (`git checkout -b my-new-feature`)
64
58
  3. Commit your changes (`git commit -am 'Add some feature'`)
65
59
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1,64 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
 
4
- desc 'Download files for running integration tests against'
5
- task :get_tiffs do
6
- require 'net/ftp'
7
- require 'fileutils'
8
-
9
- base_dest_dir = 'spec/support/images/osgeo/geotiff'
10
-
11
- if Dir.exist? base_dest_dir
12
- puts 'Tiff dir already exists. Exiting.'
13
- exit
14
- end
15
-
16
- Net::FTP.open('downloads.osgeo.org') do |ftp|
17
- ftp.login
18
- ftp.binary = true
19
-
20
- base_dir = 'geotiff/samples'
21
- _, dirs = files_and_dirs(base_dir, ftp)
22
-
23
- dirs.each do |dir_name|
24
- path = "#{base_dir}/#{dir_name}"
25
- files, dirs = files_and_dirs(path, ftp)
26
- dest_dir = "#{base_dest_dir}/#{dir_name}"
27
-
28
- FileUtils.mkdir_p(dest_dir) unless Dir.exist?(dest_dir)
29
-
30
- files.each do |file|
31
- src_file = "#{path}/#{file}"
32
- dest_file = "#{dest_dir}/#{file}"
33
-
34
- puts "Getting file '#{src_file}' to '#{dest_file}'..."
35
- ftp.get("#{src_file}", "#{dest_file}")
36
- end
37
- end
38
- end
39
- end
40
-
41
- # @return [Array{files => Array, dirs => Array}]
42
- def files_and_dirs(in_dir, ftp)
43
- dirs = []
44
- files = []
45
-
46
- puts "Getting stuff from #{in_dir}..."
47
-
48
- ftp.list("#{in_dir}/*") do |item|
49
- item_name = item.split(' ').last
50
-
51
- if item.start_with? 'd'
52
- dirs << item_name
53
- else
54
- files << item_name
55
- end
56
- end
57
-
58
- [files, dirs]
59
- end
60
-
61
-
62
4
  namespace :spec do
63
5
  RSpec::Core::RakeTask.new(:unit) do |t|
64
6
  t.pattern = 'spec/unit/**/*_spec.rb'
@@ -86,5 +28,5 @@ namespace :spec do
86
28
  end
87
29
  end
88
30
 
89
- task spec: 'spec:unit'
90
- task default: 'spec:unit'
31
+ task(:spec) { RSpec::Core::RakeTask.new }
32
+ task default: :spec
data/TODO.md CHANGED
@@ -7,3 +7,13 @@
7
7
  * MajorObject#metadata
8
8
  * ColorTable color entries
9
9
  * Raster bands in a dataset
10
+ * Functions that take a GDALProgressFunc arg should no longer be a block; they
11
+ should be a Proc. _Then_ the other argument should also be accepted so that
12
+ the function can take advantage of the meta function (the one that can handle
13
+ many layers deep of functions & their progress).
14
+ * rubocop
15
+ * Make sure extensions are in their extension files.
16
+ * Extract non-core-GDAL/OGR things into another gem?
17
+ * Fix circular dependencies. Autoload things.
18
+ * Make Enumerators for classes that do iterating over child objects
19
+ * Tame down integration tests--don't need to test so many files now.
@@ -10,9 +10,9 @@ other_point_wkt = 'POINT (1 2)'
10
10
  other_point = OGR::Geometry.create_from_wkt(point_wkt)
11
11
 
12
12
  line_string_wkt = 'LINESTRING (1 2, 10 30, 40 40, 1 2)'
13
- line_string = OGR::Geometry.create_from_wkt(line_string_wkt)
13
+ line_string = OGR::Geometry.create_from_wkt(line_string_wkt)
14
14
  other_line_string_wkt = 'LINESTRING (10 10, 0 30, 40 10)'
15
- other_line_string = OGR::Geometry.create_from_wkt(other_line_string_wkt)
15
+ other_line_string = OGR::Geometry.create_from_wkt(other_line_string_wkt)
16
16
 
17
17
  polygon_wkt = 'POLYGON ((0 0,4 0,4 4,0 4,0 0), (1 1, 2 1, 2 2, 1 1))'
18
18
  polygon = OGR::Geometry.create_from_wkt(polygon_wkt)
@@ -20,10 +20,10 @@ other_polygon_wkt = 'POLYGON ((1 1,5 1,5 5,1 5,1 1), (10 10, 20 10, 20 20, 10 10
20
20
  other_polygon = OGR::Geometry.create_from_wkt(other_polygon_wkt)
21
21
 
22
22
  multi_point_wkt = 'MULTIPOINT ((10 40), (40 30), (20 20), (30 10))'
23
- multi_point = OGR::Geometry.create_from_wkt(multi_point_wkt)
23
+ multi_point = OGR::Geometry.create_from_wkt(multi_point_wkt)
24
24
 
25
25
  multi_line_string_wkt = 'MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))'
26
- multi_line_string = OGR::Geometry.create_from_wkt(multi_line_string_wkt)
26
+ multi_line_string = OGR::Geometry.create_from_wkt(multi_line_string_wkt)
27
27
 
28
28
  multi_polygon_wkt = 'MULTIPOLYGON (((-120.03296317083633 44.226828996384285, -120.03199741570855 44.230616638863914, -120.03305119285443 44.23322276021398, -120.03305439612939 44.23323503554639, -120.03305423080232 44.233247523039175, -120.03305070309673 44.23325975261691, -120.03304394580853 44.233271263913274, -120.03303421330706 44.233281623601044, -120.0330218719597 44.23329044170392, -120.03300738634044 44.23329738627662, -120.03299130174162 44.23330219590042, -120.03297422364709 44.23330468952384, -120.03295679493954 44.23330477327791, -120.0329396717 44.23330244400986, -120.03259652218235 44.23323046886841, -120.03259605091168 44.23323469214073, -120.03259130838445 44.233246748969734, -120.03258339633375 44.23325791928269, -120.03257261443646 44.233267779993575, -120.03255937106756 44.233275957618844, -120.03254416783288 44.23328214242357, -120.03252758057009 44.23328610015274, -120.03251023753826 44.2332876809039, -120.032492795622 44.23328682480475, -120.0324759154512 44.23328356428076, -120.03246023637918 44.23327802282714, -120.03244635226639 44.233270410331386, -120.03229057481504 44.233166296752856, -120.03144275436163 44.23298846700243, -120.03135705202111 44.23542539118272, -120.03135483571377 44.23543806847976, -120.0313491680669 44.2354501823413, -120.0313402724131 44.23546125542315, -120.03132849928409 44.23547085139311, -120.03131431259804 44.235478592124444, -120.03129827137883 44.235484172595754, -120.03128100772805 44.23548737291011, -120.03126320191683 44.23548806696012, -120.03124555558011 44.235486227396926, -120.03122876406881 44.235481926707976, -120.03121348904955 44.23547533436071, -120.03120033243181 44.23546671012462, -120.03118981264993 44.23545639383555, -120.02629194435607 44.229488174527326, -120.0262841759258 44.22947593881562, -120.0262801234077 44.229462813795166, -120.02627996353844 44.22944937186798, -120.0262837032901 44.22943619925734, -120.02629117956641 44.22942387044152, -120.02630206631528 44.22941292309999, -120.02631588874878 44.229403834664076, -120.02650834059244 44.22930162063937, -120.02596466290531 44.22893822933382, -120.02595288197551 44.22892861642798, -120.02594398682248 44.22891752390089, -120.02593832881524 44.2289053899198, -120.02593613145164 44.22889269379079, -120.02593748153026 44.22887993702566, -120.02594232572132 44.2288676235318, -120.02595047267361 44.22885623970722, -120.0259616005729 44.228846235226946, -120.02597526985406 44.22883800528063, -120.0259909405644 44.22883187496161, -120.02600799369236 44.22882808642537, -120.02602575561929 44.228826789324046, -120.02604352472815 44.22882803489487, -120.02606059911827 44.2288317739361, -120.02607630433104 44.22883785875077, -120.02675839864344 44.229168810839475, -120.02688733695234 44.22910032953997, -120.02611125484312 44.228061533840545, -120.02610457348571 44.22805003875662, -120.02610110582951 44.22803783693943, -120.02610098163969 44.228025384999874, -120.02610420556363 44.2280131489091, -120.02611065695699 44.22800158656121, -120.0261200943985 44.22799113063793, -120.02613216472427 44.22798217241707, -120.02614641624366 44.227975047130094, -120.0261623156424 44.22797002141719, -120.02617926794002 44.22796728334896, -120.0261966387548 44.227966935388565, -120.02621377804353 44.22796899055725, -120.02623004442708 44.22797337194719, -120.0262448291917 44.2279799155993, -120.02625757906833 44.22798837663918, -120.02626781693645 44.22799843844071, -120.02754662923428 44.229551257921585, -120.030836241635 44.23114734101261, -120.03136956622194 44.229959117652726, -120.03138391393463 44.22955111324294, -120.03138620312208 44.229538207384174, -120.0313920671636 44.22952589494864, -120.03140126651873 44.229514678887824, -120.03141342540293 44.229505017367465, -120.03142804713777 44.22949730505196, -120.03144453443974 44.229491856982676, -120.03146221381887 44.22948889570851, -120.03148036308987 44.22948854219496, -120.03149824087296 44.229490810882744, -120.03151511687828 44.22949560909792, -120.03153030173767 44.22950274083756, -120.03154317516459 44.22951191477631, -120.0315532112922 44.22952275616695, -120.03156000257852 44.22953482814357, -120.03278854263438 44.22679758476189, -120.03286127379035 44.226512326846944, -120.03286465252121 44.226503048718484, -120.03286991708133 44.22649423317623, -120.03301731535839 44.22629080564284, -120.03302703028369 44.22628013425537, -120.03303948802117 44.22627104306898, -120.03305420051213 44.22626388825138, -120.03307059136289 44.22625895010873, -120.0330880184265 44.22625642210408, -120.03310579896007 44.22625640327766, -120.03312323637284 44.226258894367135, -120.03313964751646 44.22626379777834, -120.03315438944897 44.22627092140904, -120.03316688462326 44.22627998617475, -120.03317664351395 44.22629063694302, -120.03318328379541 44.22630245644617, -120.03318654532022 44.226314981629145, -120.03318630031114 44.22632772179051, -120.0331825583669 44.22634017780693, -120.03296317083633 44.226828996384285)))'
29
29
  multi_polygon = OGR::Geometry.create_from_wkt(multi_polygon_wkt)
@@ -47,5 +47,3 @@ multi_polygon = OGR::Geometry.create_from_wkt(multi_polygon_wkt)
47
47
  geometry = geometry.clone
48
48
  ls = geometry.to_line_string
49
49
  mls = geometry.to_multi_line_string
50
-
51
- binding.pry
data/examples/gridding.rb CHANGED
@@ -1,106 +1,107 @@
1
1
  require 'bundler/setup'
2
- require 'pry'
3
2
  require 'ffi-gdal'
3
+ require 'gdal/gridder'
4
+ require 'ogr/data_source'
5
+ require 'ogr/spatial_reference'
4
6
 
5
7
  GDAL::Logger.logging_enabled = true
6
8
 
7
- test_points_file = File.expand_path('points.txt', __dir__)
8
- test_points = File.read(test_points_file).split.map { |point_group| point_group.split(',').map(&:to_f) }
9
-
10
- output_formatter = lambda do |d, _, _|
11
- print "#{Time.now}: #{(d * 100).round(2)}%\r"
12
- true
13
- end
14
-
15
- # IDW Test
16
- def idtap(test_points)
17
- grid = GDAL::Grid.new(:inverse_distance_to_a_power, data_type: :GDT_Float32)
18
- grid.points = NArray[*test_points]
19
-
20
- grid.options[:angle] = 10
21
- # grid.options[:max_points] = 5
22
- # grid.options[:min_points] = 1
23
- grid.options[:no_data_value] = -9999
24
- grid.options[:power] = 2
25
- grid.options[:radius1] = 20
26
- grid.options[:radius2] = 15
27
- grid.options[:smoothing] = 5
28
-
29
- [grid, 'gridded-idtap.tif']
30
- end
31
-
32
- def moving_average(test_points)
33
- grid = GDAL::Grid.new(:moving_average, data_type: :GDT_Float32)
34
- grid.points = NArray[*test_points]
35
-
36
- grid.options[:angle] = 20
37
- grid.options[:min_points] = 2
38
- grid.options[:no_data_value] = -9999
39
- grid.options[:radius1] = 20
40
- grid.options[:radius2] = 51
41
-
42
- [grid, 'gridded-ma.tif']
43
- end
44
-
45
- def nearest_neighbor(test_points)
46
- grid = GDAL::Grid.new(:nearest_neighbor, data_type: :GDT_Float32)
47
- grid.points = NArray[*test_points]
48
-
49
- grid.options[:angle] = 30
50
- grid.options[:no_data_value] = -9999
51
- grid.options[:radius1] = 20
52
- grid.options[:radius2] = 15
53
-
54
- [grid, 'gridded-nn.tif']
55
- end
56
-
57
- def metric_range(test_points)
58
- grid = GDAL::Grid.new(:metric_range, data_type: :GDT_Float32)
59
- grid.points = NArray[*test_points]
60
-
61
- grid.options[:angle] = 30
62
- # grid.options[:no_data_value] = -9999
63
- grid.options[:radius1] = 20
64
- grid.options[:radius2] = 15
65
- [grid, 'gridded-metric-range.tif']
66
- end
67
-
68
- def make_file(file_name, grid, data)
69
- driver = GDAL::Driver.by_name('GTiff')
70
- dataset = driver.create_dataset(
71
- file_name,
72
- grid.x_size.round.to_i,
73
- grid.y_size.round.to_i,
74
- data_type: grid.data_type
75
- )
76
-
77
- dataset.geo_transform = grid.geo_transform
78
- dataset.projection = OGR::SpatialReference.new_from_epsg(32_632).to_wkt
79
-
80
- dataset.raster_io('w', data, data_type: grid.data_type)
81
- if grid.options[:no_data_value]
82
- dataset.raster_band(1).no_data_value = grid.options[:no_data_value]
9
+ module Examples
10
+ module Gridding
11
+ class << self
12
+ # IDW Test
13
+ def make_idtap_options
14
+ gridder_options = GDAL::GridderOptions.new(:inverse_distance_to_a_power)
15
+
16
+ gridder_options.algorithm_options[:angle] = 10
17
+ gridder_options.algorithm_options[:max_points] = 5
18
+ gridder_options.algorithm_options[:min_points] = 1
19
+ gridder_options.algorithm_options[:no_data_value] = -9999
20
+ gridder_options.algorithm_options[:power] = 2
21
+ gridder_options.algorithm_options[:radius1] = 20
22
+ gridder_options.algorithm_options[:radius2] = 15
23
+ gridder_options.algorithm_options[:smoothing] = 5
24
+
25
+ [gridder_options, 'gridded-idtap.tif']
26
+ end
27
+
28
+ def make_moving_average_options
29
+ gridder_options = GDAL::GridderOptions.new(:moving_average)
30
+
31
+ gridder_options.algorithm_options[:angle] = 20
32
+ gridder_options.algorithm_options[:min_points] = 2
33
+ gridder_options.algorithm_options[:no_data_value] = -9999
34
+ gridder_options.algorithm_options[:radius1] = 20
35
+ gridder_options.algorithm_options[:radius2] = 51
36
+
37
+ [gridder_options, 'gridded-ma.tif']
38
+ end
39
+
40
+ def make_nearest_neighbor_options
41
+ gridder_options = GDAL::GridderOptions.new(:nearest_neighbor)
42
+
43
+ gridder_options.algorithm_options[:angle] = 30
44
+ gridder_options.algorithm_options[:no_data_value] = -9999
45
+ gridder_options.algorithm_options[:radius1] = 20
46
+ gridder_options.algorithm_options[:radius2] = 15
47
+
48
+ [gridder_options, 'gridded-nn.tif']
49
+ end
50
+
51
+ def make_metric_range_options
52
+ gridder_options = GDAL::GridderOptions.new(:metric_range)
53
+
54
+ gridder_options.algorithm_options[:angle] = 30
55
+ gridder_options.algorithm_options[:no_data_value] = -9999
56
+ gridder_options.algorithm_options[:radius1] = 20
57
+ gridder_options.algorithm_options[:radius2] = 15
58
+
59
+ [gridder_options, 'gridded-metric-range.tif']
60
+ end
61
+
62
+ def make_file(source_layer, file_name, gridder_options)
63
+ start = Time.now
64
+
65
+ output_formatter = lambda do |d, _, _|
66
+ print "Duration: #{(Time.now - start).to_i}s\t| #{(d * 100).round(2)}%\r"
67
+ true
68
+ end
69
+
70
+ gridder_options.input_field_name = 'STATE_FIPS'
71
+ gridder_options.progress_formatter = output_formatter
72
+ gridder_options.output_size = { width: 1600, height: 1480 }
73
+
74
+ gridder = GDAL::Gridder.new(source_layer, file_name, gridder_options)
75
+ gridder.grid!
76
+
77
+ puts ''
78
+ puts "Duration for #{file_name}: #{Time.now - start}"
79
+ end
80
+ end
83
81
  end
84
- dataset.close
85
- puts "\nDone writing #{file_name}"
86
82
  end
87
83
 
88
- grid, output_file_name = idtap(test_points)
89
- output = grid.create(&output_formatter)
90
- puts ''
91
- make_file(output_file_name, grid, output)
92
-
93
- grid, output_file_name = moving_average(test_points)
94
- output = grid.create(&output_formatter)
95
- puts ''
96
- make_file(output_file_name, grid, output)
97
-
98
- grid, output_file_name = nearest_neighbor(test_points)
99
- output = grid.create(&output_formatter)
100
- puts ''
101
- make_file(output_file_name, grid, output)
102
-
103
- grid, output_file_name = metric_range(test_points)
104
- output = grid.create(&output_formatter)
105
- puts ''
106
- make_file(output_file_name, grid, output)
84
+ if $PROGRAM_NAME == __FILE__
85
+ shp_path = './spec/support/shapefiles/states_21basic'
86
+ ds = OGR::DataSource.open(shp_path, 'r')
87
+
88
+ # Inverse Distance To A Power
89
+ gridder_options, output_file_name = Examples::Gridding.make_idtap_options
90
+ puts ''
91
+ Examples::Gridding.make_file(ds.layer(0), output_file_name, gridder_options)
92
+
93
+ # Moving Average
94
+ gridder_options, output_file_name = Examples::Gridding.make_moving_average_options
95
+ puts ''
96
+ Examples::Gridding.make_file(ds.layer(0), output_file_name, gridder_options)
97
+
98
+ # Nearest Neighbor
99
+ gridder_options, output_file_name = Examples::Gridding.make_nearest_neighbor_options
100
+ puts ''
101
+ Examples::Gridding.make_file(ds.layer(0), output_file_name, gridder_options)
102
+
103
+ # Metric Range
104
+ gridder_options, output_file_name = Examples::Gridding.make_metric_range_options
105
+ puts ''
106
+ Examples::Gridding.make_file(ds.layer(0), output_file_name, gridder_options)
107
+ end
@@ -31,5 +31,3 @@ ring.add_point(extent.x_min, extent.y_max)
31
31
  ring.add_point(extent.x_min, extent.y_min)
32
32
  poly = OGR::Geometry.create(:wkbPolygon)
33
33
  poly.add_geometry(ring)
34
-
35
- binding.pry
@@ -0,0 +1,47 @@
1
+ require 'bundler/setup'
2
+ require 'thor'
3
+ require 'fileutils'
4
+ require 'gdal/dataset'
5
+ require 'gdal/raster_band'
6
+
7
+ GDAL::Logger.logging_enabled = true
8
+
9
+ module Examples
10
+ class RasterErasing < ::Thor
11
+ desc 'erase SOURCE DEST', 'Erase (clip) pixels from the center of the first raster band in SOURCE to DEST'
12
+ def erase(source_path, dest_path)
13
+ FileUtils.cp(source_path, dest_path)
14
+ dest_dataset = GDAL::Dataset.open(dest_path, 'w')
15
+ geo_transform = dest_dataset.geo_transform
16
+
17
+ raster_band = dest_dataset.raster_band(1)
18
+ extent_polygon = dest_dataset.extent
19
+ buffer_size = if extent_polygon.area > 1
20
+ extent_polygon.area / -5000
21
+ else
22
+ extent_polygon.area / -0.5
23
+ end
24
+
25
+ extent_polygon = extent_polygon.buffer(buffer_size)
26
+
27
+ if extent_polygon.empty?
28
+ raise 'Poorly buffered extent--you should play with these values to get this demo to work.'
29
+ end
30
+
31
+ raster_point = OGR::Point.new
32
+ start = Time.now
33
+
34
+ raster_band.simple_erase! do |x, y|
35
+ coords = geo_transform.apply_geo_transform(x, y)
36
+ raster_point.set_point(0, coords[:x_geo], coords[:y_geo])
37
+ !raster_point.within? extent_polygon
38
+ end
39
+
40
+ dest_dataset.close
41
+
42
+ puts "Erased dataset in #{Time.now - start}s. Output at '#{dest_path}'"
43
+ end
44
+ end
45
+ end
46
+
47
+ Examples::RasterErasing.start(ARGV)