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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +62 -0
- data/Gemfile +1 -1
- data/History.md +53 -28
- data/README.md +6 -0
- data/Rakefile +23 -1
- data/examples/extract_and_colorize.rb +21 -22
- data/examples/geometries.rb +2 -2
- data/examples/gridding.rb +106 -0
- data/examples/ogr_layer_to_layer.rb +1 -1
- data/examples/points.txt +127 -0
- data/examples/testing_gdal.rb +3 -4
- data/ffi-gdal.gemspec +3 -2
- data/lib/ext/error_symbols.rb +2 -57
- data/lib/ext/ffi_library_function_checks.rb +26 -0
- data/lib/ext/float_ext.rb +2 -2
- data/lib/ext/narray_ext.rb +2 -0
- data/lib/ext/numeric_as_data_type.rb +19 -0
- data/lib/ext/to_bool.rb +4 -4
- data/lib/ffi/cpl/conv.rb +132 -0
- data/lib/ffi/cpl/error.rb +67 -0
- data/lib/ffi/cpl/hash_set.rb +39 -0
- data/lib/ffi/cpl/http.rb +25 -0
- data/lib/ffi/cpl/http_result.rb +18 -0
- data/lib/ffi/cpl/list.rb +38 -0
- data/lib/ffi/cpl/mime_part.rb +11 -0
- data/lib/ffi/cpl/minixml.rb +47 -0
- data/lib/ffi/cpl/port.rb +23 -0
- data/lib/ffi/cpl/quad_tree.rb +51 -0
- data/lib/ffi/{ogr/ogr_envelope.rb → cpl/rect_obj.rb} +3 -3
- data/lib/ffi/cpl/string.rb +95 -0
- data/lib/ffi/cpl/vsi.rb +115 -0
- data/lib/ffi/cpl/xml_node.rb +6 -6
- data/lib/ffi/gdal/alg.rb +385 -0
- data/lib/ffi/gdal/{gdal_color_entry.rb → color_entry.rb} +1 -2
- data/lib/ffi/gdal/exceptions.rb +6 -0
- data/lib/ffi/gdal/{gdal_gcp.rb → gcp.rb} +1 -3
- data/lib/ffi/gdal/{gdal_h.rb → gdal.rb} +253 -252
- data/lib/ffi/gdal/grid.rb +58 -0
- data/lib/ffi/gdal/{gdal_grid_data_metrics_options.rb → grid_data_metrics_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_inverse_distance_to_a_power_options.rb → grid_inverse_distance_to_a_power_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_moving_average_options.rb → grid_moving_average_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_nearest_neighbor_options.rb → grid_nearest_neighbor_options.rb} +1 -2
- data/lib/ffi/gdal/matching.rb +20 -0
- data/lib/ffi/gdal/{gdal_rpc_info.rb → rpc_info.rb} +1 -2
- data/lib/ffi/gdal/{gdal_transformer_info.rb → transformer_info.rb} +1 -2
- data/lib/ffi/gdal/version.rb +1 -1
- data/lib/ffi/gdal/vrt.rb +92 -0
- data/lib/ffi/gdal/{gdal_warp_options.rb → warp_options.rb} +8 -4
- data/lib/ffi/gdal/warper.rb +70 -0
- data/lib/ffi/gdal.rb +56 -69
- data/lib/ffi/ogr/api.rb +567 -0
- data/lib/ffi/ogr/{ogr_contour_writer_info.rb → contour_writer_info.rb} +2 -3
- data/lib/ffi/ogr/core.rb +181 -0
- data/lib/ffi/ogr/envelope.rb +12 -0
- data/lib/ffi/ogr/{ogr_envelope_3d.rb → envelope_3d.rb} +2 -2
- data/lib/ffi/ogr/featurestyle.rb +29 -0
- data/lib/ffi/ogr/field.rb +63 -0
- data/lib/ffi/ogr/geocoding.rb +30 -0
- data/lib/ffi/ogr/srs_api.rb +407 -0
- data/lib/ffi/ogr/style_param.rb +13 -0
- data/lib/ffi/ogr/{ogr_style_value.rb → style_value.rb} +4 -3
- data/lib/ffi/ogr.rb +7 -7
- data/lib/ffi-gdal.rb +7 -145
- data/lib/gdal/color_entry.rb +18 -14
- data/lib/gdal/color_entry_mixins/extensions.rb +32 -0
- data/lib/gdal/color_interpretation.rb +2 -2
- data/lib/gdal/color_table.rb +37 -32
- data/lib/gdal/color_table_mixins/extensions.rb +48 -0
- data/lib/gdal/cpl_error_handler.rb +119 -0
- data/lib/gdal/data_type.rb +7 -7
- data/lib/gdal/dataset.rb +131 -238
- data/lib/gdal/dataset_mixins/algorithm_methods.rb +182 -0
- data/lib/gdal/dataset_mixins/extensions.rb +542 -0
- data/lib/gdal/dataset_mixins/matching.rb +26 -0
- data/lib/gdal/driver.rb +68 -92
- data/lib/gdal/driver_mixins/extensions.rb +93 -0
- data/lib/gdal/exceptions.rb +32 -4
- data/lib/gdal/geo_transform.rb +63 -43
- data/lib/gdal/geo_transform_mixins/extensions.rb +57 -0
- data/lib/gdal/grid.rb +144 -0
- data/lib/gdal/grid_types/data_metrics_base.rb +14 -0
- data/lib/gdal/grid_types/inverse_distance_to_a_power.rb +19 -0
- data/lib/gdal/grid_types/metric_average_distance.rb +12 -0
- data/lib/gdal/grid_types/metric_average_distance_pts.rb +12 -0
- data/lib/gdal/grid_types/metric_count.rb +12 -0
- data/lib/gdal/grid_types/metric_maximum.rb +12 -0
- data/lib/gdal/grid_types/metric_minimum.rb +12 -0
- data/lib/gdal/grid_types/metric_range.rb +12 -0
- data/lib/gdal/grid_types/moving_average.rb +19 -0
- data/lib/gdal/grid_types/nearest_neighbor.rb +19 -0
- data/lib/gdal/grid_types.rb +22 -0
- data/lib/gdal/internal_helpers.rb +94 -0
- data/lib/gdal/major_object.rb +4 -7
- data/lib/gdal/options.rb +14 -7
- data/lib/gdal/raster_attribute_table.rb +38 -47
- data/lib/gdal/raster_attribute_table_mixins/extensions.rb +41 -0
- data/lib/gdal/raster_band.rb +193 -227
- data/lib/gdal/raster_band_classifier.rb +107 -0
- data/lib/gdal/raster_band_mixins/algorithm_methods.rb +292 -0
- data/lib/gdal/raster_band_mixins/extensions.rb +238 -0
- data/lib/gdal/rpc_info.rb +35 -0
- data/lib/gdal/transformer.rb +15 -0
- data/lib/gdal/transformers/approximate_transformer.rb +48 -0
- data/lib/gdal/transformers/base_general_image_projection_transformer.rb +45 -0
- data/lib/gdal/transformers/gcp_transformer.rb +55 -0
- data/lib/gdal/transformers/general_image_projection_transformer.rb +31 -0
- data/lib/gdal/transformers/general_image_projection_transformer2.rb +52 -0
- data/lib/gdal/transformers/general_image_projection_transformer3.rb +25 -0
- data/lib/gdal/transformers/geolocation_transformer.rb +42 -0
- data/lib/gdal/transformers/reprojection_transformer.rb +39 -0
- data/lib/gdal/transformers/rpc_transformer.rb +56 -0
- data/lib/gdal/transformers/tps_transformer.rb +40 -0
- data/lib/gdal/virtual_dataset.rb +96 -0
- data/lib/gdal/warp_operation.rb +20 -23
- data/lib/gdal.rb +17 -0
- data/lib/ogr/coordinate_transformation.rb +16 -41
- data/lib/ogr/data_source.rb +103 -58
- data/lib/ogr/data_source_extensions.rb +5 -6
- data/lib/ogr/data_source_mixins/capability_methods.rb +27 -0
- data/lib/ogr/driver.rb +61 -33
- data/lib/ogr/driver_mixins/capability_methods.rb +16 -0
- data/lib/ogr/envelope.rb +29 -18
- data/lib/ogr/envelope_extensions.rb +70 -49
- data/lib/ogr/error_handling.rb +46 -0
- data/lib/ogr/exceptions.rb +58 -12
- data/lib/ogr/feature.rb +334 -86
- data/lib/ogr/feature_definition.rb +94 -51
- data/lib/ogr/feature_definition_extensions.rb +36 -13
- data/lib/ogr/feature_extensions.rb +62 -11
- data/lib/ogr/field.rb +175 -54
- data/lib/ogr/field_definition.rb +110 -0
- data/lib/ogr/{field_extensions.rb → field_definition_extensions.rb} +4 -5
- data/lib/ogr/{geocoding_session.rb → geocoder.rb} +14 -13
- data/lib/ogr/geometries/geometry_collection.rb +13 -0
- data/lib/ogr/geometries/line_string.rb +35 -0
- data/lib/ogr/geometries/linear_ring.rb +11 -0
- data/lib/ogr/geometries/multi_line_string.rb +16 -0
- data/lib/ogr/geometries/multi_point.rb +14 -0
- data/lib/ogr/geometries/multi_polygon.rb +21 -0
- data/lib/ogr/geometries/none_geometry.rb +13 -0
- data/lib/ogr/geometries/point.rb +65 -0
- data/lib/ogr/geometries/point_extensions.rb +32 -0
- data/lib/ogr/geometries/polygon.rb +14 -0
- data/lib/ogr/geometries/unknown_geometry.rb +10 -0
- data/lib/ogr/geometry.rb +270 -242
- data/lib/ogr/geometry_extensions.rb +8 -9
- data/lib/ogr/geometry_field_definition.rb +99 -0
- data/lib/ogr/geometry_field_definition_extensions.rb +19 -0
- data/lib/ogr/geometry_types/container.rb +75 -0
- data/lib/ogr/geometry_types/curve.rb +25 -28
- data/lib/ogr/geometry_types/surface.rb +13 -4
- data/lib/ogr/internal_helpers.rb +57 -0
- data/lib/ogr/layer.rb +60 -181
- data/lib/ogr/layer_mixins/capability_methods.rb +102 -0
- data/lib/ogr/layer_mixins/extensions.rb +59 -0
- data/lib/ogr/layer_mixins/ogr_feature_methods.rb +127 -0
- data/lib/ogr/layer_mixins/ogr_field_methods.rb +143 -0
- data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +163 -0
- data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +89 -0
- data/lib/ogr/layer_mixins/ogr_sql_methods.rb +48 -0
- data/lib/ogr/spatial_reference.rb +108 -589
- data/lib/ogr/spatial_reference_extensions.rb +29 -3
- data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +494 -0
- data/lib/ogr/spatial_reference_mixins/exporters.rb +134 -0
- data/lib/ogr/spatial_reference_mixins/importers.rb +243 -0
- data/lib/ogr/spatial_reference_mixins/morphers.rb +25 -0
- data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +122 -0
- data/lib/ogr/spatial_reference_mixins/type_checks.rb +62 -0
- data/lib/ogr/style_table.rb +53 -5
- data/lib/ogr/style_table_extensions.rb +21 -5
- data/lib/ogr/style_tool.rb +118 -0
- data/lib/ogr.rb +8 -0
- data/spec/ffi-gdal_spec.rb +1 -2
- data/spec/integration/{color_table_info_spec.rb → gdal/color_table_info_spec.rb} +12 -12
- data/spec/integration/{dataset_info_spec.rb → gdal/dataset_info_spec.rb} +2 -6
- data/spec/integration/{driver_info_spec.rb → gdal/driver_info_spec.rb} +5 -5
- data/spec/integration/{geo_transform_info_spec.rb → gdal/geo_transform_info_spec.rb} +1 -14
- data/spec/integration/{raster_attribute_table_info_spec.rb → gdal/raster_attribute_table_info_spec.rb} +1 -2
- data/spec/integration/{raster_band_info_spec.rb → gdal/raster_band_info_spec.rb} +30 -42
- data/spec/integration/ogr/layer_spec.rb +97 -0
- data/spec/spec_helper.rb +94 -5
- data/spec/support/integration_help.rb +1 -0
- data/spec/support/shared_contexts.rb +26 -0
- data/spec/support/shared_examples/{major_object_examples.rb → gdal/major_object_examples.rb} +5 -5
- data/spec/support/shared_examples/ogr/a_25D_geometry.rb +7 -0
- data/spec/support/shared_examples/ogr/a_container_geometry.rb +47 -0
- data/spec/support/shared_examples/ogr/a_geometry.rb +404 -0
- data/spec/support/shared_examples/ogr/a_line_string.rb +16 -0
- data/spec/support/test_style_table.txt +3 -0
- data/spec/unit/ext/error_symbols_spec.rb +41 -53
- data/spec/unit/ext/numeric_as_data_type_spec.rb +113 -0
- data/spec/unit/ffi/gdal_spec.rb +70 -0
- data/spec/unit/gdal/color_entry_spec.rb +5 -0
- data/spec/unit/gdal/color_interpretation_spec.rb +5 -0
- data/spec/unit/gdal/{color_table_extensions_spec.rb → color_table_mixins/extensions_spec.rb} +3 -3
- data/spec/unit/gdal/color_table_spec.rb +14 -16
- data/spec/unit/gdal/data_type_spec.rb +10 -17
- data/spec/unit/gdal/dataset_spec.rb +4 -7
- data/spec/unit/gdal/driver_mixins/extensions_spec.rb +22 -0
- data/spec/unit/gdal/driver_spec.rb +49 -0
- data/spec/unit/gdal/environment_methods_spec.rb +6 -0
- data/spec/unit/gdal/geo_transform_spec.rb +276 -0
- data/spec/unit/gdal/grid_spec.rb +5 -0
- data/spec/unit/gdal/internal_helpers_spec.rb +112 -0
- data/spec/unit/gdal/major_object_spec.rb +6 -0
- data/spec/unit/gdal/options_spec.rb +5 -0
- data/spec/unit/gdal/raster_attribute_table_spec.rb +5 -0
- data/spec/unit/gdal/raster_band_classifier_spec.rb +134 -0
- data/spec/unit/gdal/raster_band_spec.rb +5 -0
- data/spec/unit/gdal/rpc_info_spec.rb +5 -0
- data/spec/unit/gdal/version_info_spec.rb +6 -0
- data/spec/unit/gdal/virtual_dataset_spec.rb +32 -0
- data/spec/unit/gdal/warp_operation_spec.rb +5 -0
- data/spec/unit/ogr/data_source_mixins/capability_methods_spec.rb +30 -0
- data/spec/unit/ogr/data_source_spec.rb +209 -0
- data/spec/unit/ogr/driver_mixins/capability_methods_spec.rb +18 -0
- data/spec/unit/ogr/driver_spec.rb +150 -0
- data/spec/unit/ogr/envelope_spec.rb +322 -0
- data/spec/unit/ogr/feature_definition_spec.rb +313 -0
- data/spec/unit/ogr/feature_spec.rb +379 -0
- data/spec/unit/ogr/field_definition_spec.rb +135 -0
- data/spec/unit/ogr/field_spec.rb +193 -0
- data/spec/unit/ogr/geometries/geometry_collection_spec.rb +186 -0
- data/spec/unit/ogr/geometries/line_string_spec.rb +105 -0
- data/spec/unit/ogr/{linear_ring_spec.rb → geometries/linear_ring_spec.rb} +10 -31
- data/spec/unit/ogr/geometries/multi_line_string_spec.rb +14 -0
- data/spec/unit/ogr/geometries/multi_point_spec.rb +14 -0
- data/spec/unit/ogr/geometries/multi_polygon_spec.rb +41 -0
- data/spec/unit/ogr/geometries/none_geometry_spec.rb +12 -0
- data/spec/unit/ogr/{point_spec.rb → geometries/point_spec.rb} +19 -25
- data/spec/unit/ogr/geometries/polygon_spec.rb +17 -0
- data/spec/unit/ogr/geometries/unknown_geometry_spec.rb +10 -0
- data/spec/unit/ogr/geometry_field_definition_spec.rb +87 -0
- data/spec/unit/ogr/geometry_spec.rb +542 -0
- data/spec/unit/ogr/internal_helpers_spec.rb +57 -0
- data/spec/unit/ogr/layer_mixins/capability_methods_spec.rb +88 -0
- data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +145 -0
- data/spec/unit/ogr/layer_mixins/ogr_field_methods_spec.rb +432 -0
- data/spec/unit/ogr/layer_mixins/ogr_layer_method_methods_spec.rb +20 -0
- data/spec/unit/ogr/layer_mixins/ogr_query_filter_methods_spec.rb +42 -0
- data/spec/unit/ogr/layer_mixins/ogr_sql_methods_spec.rb +12 -0
- data/spec/unit/ogr/layer_spec.rb +66 -67
- data/spec/unit/ogr/spatial_reference_mixins/coordinate_system_getter_setters_spec.rb +46 -0
- data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +139 -0
- data/spec/unit/ogr/spatial_reference_mixins/importers_spec.rb +38 -0
- data/spec/unit/ogr/spatial_reference_mixins/morphers_spec.rb +36 -0
- data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +102 -0
- data/spec/unit/ogr/spatial_reference_mixins/type_checks_spec.rb +157 -0
- data/spec/unit/ogr/spatial_reference_spec.rb +42 -0
- data/spec/unit/ogr/style_table_spec.rb +132 -0
- data/spec/unit/ogr/style_tool_spec.rb +157 -0
- data/spec/unit/version_info_spec.rb +1 -1
- metadata +285 -75
- data/lib/ffi/cpl/conv_h.rb +0 -143
- data/lib/ffi/cpl/error_h.rb +0 -63
- data/lib/ffi/cpl/minixml_h.rb +0 -14
- data/lib/ffi/cpl/string_h.rb +0 -81
- data/lib/ffi/cpl/vsi_h.rb +0 -112
- data/lib/ffi/gdal/alg_h.rb +0 -127
- data/lib/ffi/gdal/grid_h.rb +0 -51
- data/lib/ffi/gdal/warper_h.rb +0 -48
- data/lib/ffi/ogr/api_h.rb +0 -553
- data/lib/ffi/ogr/core_h.rb +0 -148
- data/lib/ffi/ogr/featurestyle_h.rb +0 -22
- data/lib/ffi/ogr/geocoding_h.rb +0 -21
- data/lib/ffi/ogr/ogr_field.rb +0 -50
- data/lib/ffi/ogr/ogr_style_param.rb +0 -12
- data/lib/ffi/ogr/srs_api_h.rb +0 -325
- data/lib/gdal/color_entry_extensions.rb +0 -30
- data/lib/gdal/color_table_extensions.rb +0 -47
- data/lib/gdal/dataset_extensions.rb +0 -496
- data/lib/gdal/driver_extensions.rb +0 -56
- data/lib/gdal/geo_transform_extensions.rb +0 -90
- data/lib/gdal/raster_attribute_table_extensions.rb +0 -40
- data/lib/gdal/raster_band_extensions.rb +0 -198
- data/lib/ogr/geometry_types/collection.rb +0 -45
- data/lib/ogr/layer_extensions.rb +0 -55
- data/lib/ogr/line_string.rb +0 -7
- data/lib/ogr/linear_ring.rb +0 -6
- data/lib/ogr/multi_line_string.rb +0 -9
- data/lib/ogr/multi_point.rb +0 -7
- data/lib/ogr/multi_polygon.rb +0 -14
- data/lib/ogr/point.rb +0 -89
- data/lib/ogr/polygon.rb +0 -9
data/lib/gdal/raster_band.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative '../ffi/gdal'
|
2
|
-
require_relative '../ffi/ogr/
|
3
|
-
require_relative '
|
2
|
+
require_relative '../ffi/ogr/api'
|
3
|
+
require_relative 'raster_band_mixins/algorithm_methods'
|
4
|
+
require_relative 'raster_band_mixins/extensions'
|
4
5
|
require_relative 'color_table'
|
5
6
|
require_relative 'major_object'
|
6
7
|
require_relative 'raster_attribute_table'
|
@@ -10,27 +11,25 @@ module GDAL
|
|
10
11
|
class RasterBand
|
11
12
|
include MajorObject
|
12
13
|
include GDAL::Logger
|
13
|
-
include
|
14
|
+
include RasterBandMixins::AlgorithmMethods
|
15
|
+
include RasterBandMixins::Extensions
|
14
16
|
|
15
17
|
ALL_VALID = 0x01
|
16
18
|
PER_DATASET = 0x02
|
17
19
|
ALPHA = 0x04
|
18
20
|
NODATA = 0x08
|
19
21
|
|
20
|
-
# @
|
21
|
-
|
22
|
-
@raster_band_pointer = GDAL._pointer(GDAL::RasterBand, raster_band)
|
23
|
-
end
|
22
|
+
# @return [FFI::Pointer] C pointer to the C raster band.
|
23
|
+
attr_reader :c_pointer
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
# @param raster_band [GDAL::RasterBand, FFI::Pointer]
|
26
|
+
def initialize(raster_band)
|
27
|
+
@c_pointer = GDAL._pointer(GDAL::RasterBand, raster_band)
|
27
28
|
end
|
28
29
|
|
29
30
|
# @return [Boolean]
|
30
31
|
def flush_cache
|
31
|
-
|
32
|
-
|
33
|
-
cpl_err.to_bool
|
32
|
+
!!FFI::GDAL.GDALFlushRasterCache(@c_pointer)
|
34
33
|
end
|
35
34
|
|
36
35
|
# The raster width in pixels.
|
@@ -39,7 +38,7 @@ module GDAL
|
|
39
38
|
def x_size
|
40
39
|
return nil if null?
|
41
40
|
|
42
|
-
FFI::GDAL.GDALGetRasterBandXSize(@
|
41
|
+
FFI::GDAL.GDALGetRasterBandXSize(@c_pointer)
|
43
42
|
end
|
44
43
|
|
45
44
|
# The raster height in pixels.
|
@@ -48,7 +47,7 @@ module GDAL
|
|
48
47
|
def y_size
|
49
48
|
return nil if null?
|
50
49
|
|
51
|
-
FFI::GDAL.GDALGetRasterBandYSize(@
|
50
|
+
FFI::GDAL.GDALGetRasterBandYSize(@c_pointer)
|
52
51
|
end
|
53
52
|
|
54
53
|
# The type of access to the raster band this object currently has.
|
@@ -57,7 +56,7 @@ module GDAL
|
|
57
56
|
def access_flag
|
58
57
|
return nil if null?
|
59
58
|
|
60
|
-
FFI::GDAL.GDALGetRasterAccess(@
|
59
|
+
FFI::GDAL.GDALGetRasterAccess(@c_pointer)
|
61
60
|
end
|
62
61
|
|
63
62
|
# The number of band within the associated dataset that this band
|
@@ -67,57 +66,50 @@ module GDAL
|
|
67
66
|
def number
|
68
67
|
return nil if null?
|
69
68
|
|
70
|
-
FFI::GDAL.GDALGetBandNumber(@
|
69
|
+
FFI::GDAL.GDALGetBandNumber(@c_pointer)
|
71
70
|
end
|
72
71
|
|
73
72
|
# @return [GDAL::Dataset, nil]
|
74
73
|
def dataset
|
75
74
|
return @dataset if @dataset
|
76
75
|
|
77
|
-
dataset_ptr = FFI::GDAL.GDALGetBandDataset(@
|
76
|
+
dataset_ptr = FFI::GDAL.GDALGetBandDataset(@c_pointer)
|
78
77
|
return nil if dataset_ptr.null?
|
79
78
|
|
80
79
|
@dataset = GDAL::Dataset.new(dataset_ptr)
|
81
80
|
end
|
82
81
|
|
83
|
-
# @return [Symbol] One of FFI::GDAL::
|
82
|
+
# @return [Symbol] One of FFI::GDAL::ColorInterp.
|
84
83
|
def color_interpretation
|
85
|
-
FFI::GDAL.GDALGetRasterColorInterpretation(@
|
84
|
+
FFI::GDAL.GDALGetRasterColorInterpretation(@c_pointer)
|
86
85
|
end
|
87
86
|
|
88
|
-
# @param new_color_interp [FFI::GDAL::
|
87
|
+
# @param new_color_interp [FFI::GDAL::ColorInterp]
|
89
88
|
# @return [Boolean]
|
90
89
|
def color_interpretation=(new_color_interp)
|
91
|
-
|
90
|
+
!!FFI::GDAL.GDALSetRasterColorInterpretation(@c_pointer,
|
92
91
|
new_color_interp)
|
93
|
-
|
94
|
-
cpl_err.to_bool
|
95
92
|
end
|
96
93
|
|
97
94
|
# @return [GDAL::ColorTable]
|
98
95
|
def color_table
|
99
|
-
|
100
|
-
|
101
|
-
gdal_color_table = FFI::GDAL.GDALGetRasterColorTable(@raster_band_pointer)
|
96
|
+
gdal_color_table = FFI::GDAL.GDALGetRasterColorTable(@c_pointer)
|
102
97
|
return nil if gdal_color_table.null?
|
103
98
|
|
104
|
-
|
99
|
+
ColorTable.new(gdal_color_table)
|
105
100
|
end
|
106
101
|
|
107
102
|
# @param new_color_table [GDAL::ColorTable]
|
108
103
|
def color_table=(new_color_table)
|
109
104
|
color_table_pointer = GDAL._pointer(GDAL::ColorTable, new_color_table)
|
110
|
-
|
111
|
-
@color_table = ColorTable.new(color_table_pointer)
|
112
|
-
|
113
|
-
cpl_err.to_bool
|
105
|
+
FFI::GDAL.GDALSetRasterColorTable(@c_pointer, color_table_pointer)
|
114
106
|
end
|
115
107
|
|
116
108
|
# The pixel data type for this band.
|
117
109
|
#
|
118
|
-
# @return [Symbol] One of FFI::GDAL::
|
110
|
+
# @return [Symbol] One of FFI::GDAL::DataType.
|
119
111
|
def data_type
|
120
|
-
FFI::GDAL.GDALGetRasterDataType(@
|
112
|
+
FFI::GDAL.GDALGetRasterDataType(@c_pointer)
|
121
113
|
end
|
122
114
|
|
123
115
|
# The natural block size is the block size that is most efficient for
|
@@ -128,36 +120,25 @@ module GDAL
|
|
128
120
|
def block_size
|
129
121
|
x_pointer = FFI::MemoryPointer.new(:int)
|
130
122
|
y_pointer = FFI::MemoryPointer.new(:int)
|
131
|
-
FFI::GDAL.GDALGetBlockSize(@
|
123
|
+
FFI::GDAL.GDALGetBlockSize(@c_pointer, x_pointer, y_pointer)
|
132
124
|
|
133
125
|
{ x: x_pointer.read_int, y: y_pointer.read_int }
|
134
126
|
end
|
135
127
|
|
136
128
|
# @return [Array<String>]
|
137
129
|
def category_names
|
138
|
-
names = FFI::GDAL.GDALGetRasterCategoryNames(@
|
130
|
+
names = FFI::GDAL.GDALGetRasterCategoryNames(@c_pointer)
|
139
131
|
return [] if names.null?
|
140
132
|
|
141
133
|
names.get_array_of_string(0)
|
142
134
|
end
|
143
135
|
|
144
136
|
# @param names [Array<String>]
|
145
|
-
# @return [
|
137
|
+
# @return [Boolean]
|
146
138
|
def category_names=(names)
|
147
|
-
|
148
|
-
FFI::MemoryPointer.from_string(name.to_s)
|
149
|
-
end
|
139
|
+
names_pointer = GDAL._string_array_to_pointer(names)
|
150
140
|
|
151
|
-
|
152
|
-
names_pointer = FFI::MemoryPointer.new(:pointer, str_pointers.length)
|
153
|
-
|
154
|
-
str_pointers.each_with_index do |ptr, i|
|
155
|
-
names_pointer[i].put_pointer(0, ptr)
|
156
|
-
end
|
157
|
-
|
158
|
-
cpl_err = FFI::GDAL.GDALSetRasterCategoryNames(@raster_band_pointer, names_pointer)
|
159
|
-
|
160
|
-
cpl_err.to_ruby(warning: [])
|
141
|
+
!!FFI::GDAL.GDALSetRasterCategoryNames(@c_pointer, names_pointer)
|
161
142
|
end
|
162
143
|
|
163
144
|
# The no data value for a band is generally a special marker value used to
|
@@ -167,7 +148,7 @@ module GDAL
|
|
167
148
|
# @return [Hash{value => Float, is_associated => Boolean}]
|
168
149
|
def no_data_value
|
169
150
|
associated = FFI::MemoryPointer.new(:bool)
|
170
|
-
value = FFI::GDAL.GDALGetRasterNoDataValue(@
|
151
|
+
value = FFI::GDAL.GDALGetRasterNoDataValue(@c_pointer, associated)
|
171
152
|
|
172
153
|
{ value: value, is_associated: associated.read_bytes(1).to_bool }
|
173
154
|
end
|
@@ -177,19 +158,17 @@ module GDAL
|
|
177
158
|
# @param value [Float]
|
178
159
|
# @return [Boolean]
|
179
160
|
def no_data_value=(value)
|
180
|
-
|
181
|
-
|
182
|
-
cpl_err.to_bool
|
161
|
+
!!FFI::GDAL.GDALSetRasterNoDataValue(@c_pointer, value)
|
183
162
|
end
|
184
163
|
|
185
164
|
# @return [Fixnum]
|
186
165
|
def overview_count
|
187
|
-
FFI::GDAL.GDALGetOverviewCount(@
|
166
|
+
FFI::GDAL.GDALGetOverviewCount(@c_pointer)
|
188
167
|
end
|
189
168
|
|
190
169
|
# @return [Boolean]
|
191
170
|
def arbitrary_overviews?
|
192
|
-
FFI::GDAL.GDALHasArbitraryOverviews(@
|
171
|
+
FFI::GDAL.GDALHasArbitraryOverviews(@c_pointer).zero? ? false : true
|
193
172
|
end
|
194
173
|
|
195
174
|
# @param index [Fixnum] Must be between 0 and (#overview_count - 1).
|
@@ -197,7 +176,7 @@ module GDAL
|
|
197
176
|
def overview(index)
|
198
177
|
return nil if overview_count.zero?
|
199
178
|
|
200
|
-
overview_pointer = FFI::GDAL.GDALGetOverview(@
|
179
|
+
overview_pointer = FFI::GDAL.GDALGetOverview(@c_pointer, index)
|
201
180
|
return nil if overview_pointer.null?
|
202
181
|
|
203
182
|
self.class.new(overview_pointer)
|
@@ -207,8 +186,8 @@ module GDAL
|
|
207
186
|
# many pixels.
|
208
187
|
# @return [GDAL::RasterBand] An optimal overview or the same raster band if
|
209
188
|
# the raster band has no overviews.
|
210
|
-
def raster_sample_overview(desired_samples=0)
|
211
|
-
band_pointer = FFI::GDAL.GDALGetRasterSampleOverview(@
|
189
|
+
def raster_sample_overview(desired_samples = 0)
|
190
|
+
band_pointer = FFI::GDAL.GDALGetRasterSampleOverview(@c_pointer, desired_samples)
|
212
191
|
return nil if band_pointer.null?
|
213
192
|
|
214
193
|
self.class.new(band_pointer)
|
@@ -216,7 +195,7 @@ module GDAL
|
|
216
195
|
|
217
196
|
# @return [GDAL::RasterBand]
|
218
197
|
def mask_band
|
219
|
-
band_pointer = FFI::GDAL.GDALGetMaskBand(@
|
198
|
+
band_pointer = FFI::GDAL.GDALGetMaskBand(@c_pointer)
|
220
199
|
return nil if band_pointer.null?
|
221
200
|
|
222
201
|
self.class.new(band_pointer)
|
@@ -224,7 +203,7 @@ module GDAL
|
|
224
203
|
|
225
204
|
# @return [Array<Symbol>]
|
226
205
|
def mask_flags
|
227
|
-
flag_list = FFI::GDAL.GDALGetMaskFlags(@
|
206
|
+
flag_list = FFI::GDAL.GDALGetMaskFlags(@c_pointer).to_s(2).scan(/\d/)
|
228
207
|
flags = []
|
229
208
|
|
230
209
|
flag_list.reverse.each_with_index do |flag, i|
|
@@ -244,9 +223,7 @@ module GDAL
|
|
244
223
|
|
245
224
|
# @return [Boolean]
|
246
225
|
def create_mask_band(flags)
|
247
|
-
|
248
|
-
|
249
|
-
cpl_err.to_bool
|
226
|
+
!!FFI::GDAL.GDALCreateMaskBand(@c_pointer, flags)
|
250
227
|
end
|
251
228
|
|
252
229
|
# Fill this band with constant value. Useful for clearing a band and
|
@@ -254,10 +231,8 @@ module GDAL
|
|
254
231
|
#
|
255
232
|
# @param real_value [Float]
|
256
233
|
# @param imaginary_value [Float]
|
257
|
-
def fill(real_value, imaginary_value=0)
|
258
|
-
|
259
|
-
|
260
|
-
cpl_err.to_bool
|
234
|
+
def fill(real_value, imaginary_value = 0)
|
235
|
+
!!FFI::GDAL.GDALFillRaster(@c_pointer, real_value, imaginary_value)
|
261
236
|
end
|
262
237
|
|
263
238
|
# Returns minimum, maximum, mean, and standard deviation of all pixel values
|
@@ -269,34 +244,63 @@ module GDAL
|
|
269
244
|
# calculating can be done without rescanning the image.
|
270
245
|
# @return [Hash{minimum: Float, maximum: Float, mean: Float,
|
271
246
|
# standard_deviation: Float}]
|
272
|
-
def statistics(approx_ok=true, force=true)
|
247
|
+
def statistics(approx_ok = true, force = true)
|
273
248
|
min = FFI::MemoryPointer.new(:double)
|
274
249
|
max = FFI::MemoryPointer.new(:double)
|
275
250
|
mean = FFI::MemoryPointer.new(:double)
|
276
251
|
standard_deviation = FFI::MemoryPointer.new(:double)
|
277
252
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
min,
|
282
|
-
max,
|
283
|
-
mean,
|
284
|
-
standard_deviation)
|
285
|
-
|
286
|
-
case cpl_err.to_ruby
|
287
|
-
when :none, :debug
|
253
|
+
handler = GDAL::CPLErrorHandler.new
|
254
|
+
handler.on_warning = proc { Hash.new }
|
255
|
+
handler.on_none = proc do
|
288
256
|
{
|
289
257
|
minimum: min.read_double,
|
290
258
|
maximum: max.read_double,
|
291
259
|
mean: mean.read_double,
|
292
260
|
standard_deviation: standard_deviation.read_double
|
293
261
|
}
|
294
|
-
|
295
|
-
|
296
|
-
|
262
|
+
end
|
263
|
+
|
264
|
+
handler.custom_handle do
|
265
|
+
FFI::GDAL.GDALGetRasterStatistics(@c_pointer,
|
266
|
+
approx_ok,
|
267
|
+
force,
|
268
|
+
min,
|
269
|
+
max,
|
270
|
+
mean,
|
271
|
+
standard_deviation)
|
297
272
|
end
|
298
273
|
end
|
299
274
|
|
275
|
+
# @param approx_ok [Boolean] If +true+, allows for some approximating,
|
276
|
+
# which may speed up calculations.
|
277
|
+
# @return [Hash{minimum => Float, maximum => Float, mean => Float,
|
278
|
+
# standard_deviation => Float}]
|
279
|
+
def compute_statistics(approx_ok: false, &progress_block)
|
280
|
+
min_ptr = FFI::MemoryPointer.new(:double)
|
281
|
+
max_ptr = FFI::MemoryPointer.new(:double)
|
282
|
+
mean_ptr = FFI::MemoryPointer.new(:double)
|
283
|
+
standard_deviation_ptr = FFI::MemoryPointer.new(:double)
|
284
|
+
|
285
|
+
FFI::GDAL::GDALComputeRasterStatistics(
|
286
|
+
@c_pointer, # hBand
|
287
|
+
approx_ok, # bApproxOK
|
288
|
+
min_ptr, # pdfMin
|
289
|
+
max_ptr, # pdfMax
|
290
|
+
mean_ptr, # pdfMean
|
291
|
+
standard_deviation_ptr, # pdfStdDev
|
292
|
+
progress_block, # pfnProgress
|
293
|
+
nil # pProgressData
|
294
|
+
)
|
295
|
+
|
296
|
+
{
|
297
|
+
minimum: min_ptr.read_double,
|
298
|
+
maximum: max_ptr.read_double,
|
299
|
+
mean: mean_ptr.read_double,
|
300
|
+
standard_deviation: standard_deviation_ptr.read_double
|
301
|
+
}
|
302
|
+
end
|
303
|
+
|
300
304
|
# The raster value scale. This value (in combination with the #offset
|
301
305
|
# value) is used to transform raw pixel values into the units returned by
|
302
306
|
# #units. For example this might be used to store elevations in GUInt16
|
@@ -310,7 +314,7 @@ module GDAL
|
|
310
314
|
# @return [Hash{value => Float, is_meaningful => Boolean}]
|
311
315
|
def scale
|
312
316
|
meaningful = FFI::MemoryPointer.new(:bool)
|
313
|
-
result = FFI::GDAL.GDALGetRasterScale(@
|
317
|
+
result = FFI::GDAL.GDALGetRasterScale(@c_pointer, meaningful)
|
314
318
|
|
315
319
|
{ value: result, is_meaningful: meaningful.read_bytes(1).to_bool }
|
316
320
|
end
|
@@ -318,12 +322,10 @@ module GDAL
|
|
318
322
|
# @param new_scale [Float]
|
319
323
|
# @return [Boolean]
|
320
324
|
def scale=(new_scale)
|
321
|
-
|
322
|
-
|
323
|
-
cpl_err.to_bool
|
325
|
+
!!FFI::GDAL.GDALSetRasterScale(@c_pointer, new_scale.to_f)
|
324
326
|
end
|
325
327
|
|
326
|
-
# This value (in combination with the
|
328
|
+
# This value (in combination with the #scale value) is used to
|
327
329
|
# transform raw pixel values into the units returned by #units. For example
|
328
330
|
# this might be used to store elevations in GUInt16 bands with a precision
|
329
331
|
# of 0.1, and starting from -100.
|
@@ -336,7 +338,7 @@ module GDAL
|
|
336
338
|
# @return [Hash{value => Float, is_meaningful => Boolean}]
|
337
339
|
def offset
|
338
340
|
meaningful = FFI::MemoryPointer.new(:bool)
|
339
|
-
result = FFI::GDAL.GDALGetRasterOffset(@
|
341
|
+
result = FFI::GDAL.GDALGetRasterOffset(@c_pointer, meaningful)
|
340
342
|
|
341
343
|
{ value: result, is_meaningful: meaningful.read_bytes(1).to_bool }
|
342
344
|
end
|
@@ -344,14 +346,12 @@ module GDAL
|
|
344
346
|
# @param new_offset [Float]
|
345
347
|
# @return [Boolean]
|
346
348
|
def offset=(new_offset)
|
347
|
-
|
348
|
-
|
349
|
-
cpl_err.to_bool
|
349
|
+
!!FFI::GDAL.GDALSetRasterOffset(@c_pointer, new_offset)
|
350
350
|
end
|
351
351
|
|
352
352
|
# @return [String]
|
353
353
|
def unit_type
|
354
|
-
FFI::GDAL.GDALGetRasterUnitType(@
|
354
|
+
FFI::GDAL.GDALGetRasterUnitType(@c_pointer)
|
355
355
|
end
|
356
356
|
|
357
357
|
# @param new_unit_type [String] "" indicates unknown, "m" is meters, "ft"
|
@@ -359,9 +359,7 @@ module GDAL
|
|
359
359
|
# @return [Boolean]
|
360
360
|
def unit_type=(new_unit_type)
|
361
361
|
if defined? FFI::GDAL::GDALSetRasterUnitType
|
362
|
-
|
363
|
-
|
364
|
-
cpl_err.to_bool
|
362
|
+
!!FFI::GDAL.GDALSetRasterUnitType(@c_pointer, new_unit_type)
|
365
363
|
else
|
366
364
|
warn "GDALSetRasterUnitType is not defined. Can't call RasterBand#unit_type="
|
367
365
|
end
|
@@ -369,28 +367,23 @@ module GDAL
|
|
369
367
|
|
370
368
|
# @return [GDAL::RasterAttributeTable]
|
371
369
|
def default_raster_attribute_table
|
372
|
-
|
373
|
-
|
374
|
-
rat_pointer = FFI::GDAL.GDALGetDefaultRAT(@raster_band_pointer)
|
370
|
+
rat_pointer = FFI::GDAL.GDALGetDefaultRAT(@c_pointer)
|
375
371
|
return nil if rat_pointer.null?
|
376
372
|
|
377
|
-
|
373
|
+
GDAL::RasterAttributeTable.new(rat_pointer)
|
378
374
|
end
|
379
375
|
|
380
376
|
# @return [GDAL::RasterAttributeTable]
|
381
377
|
def default_raster_attribute_table=(rat_table)
|
382
378
|
rat_table_ptr = GDAL._pointer(GDAL::RasterAttributeTable, rat_table)
|
383
|
-
|
384
|
-
@default_raster_attribute_table = GDAL::RasterAttributeTable.new(rat_table_pointer)
|
385
|
-
|
386
|
-
cpl_err.to_bool
|
379
|
+
FFI::GDAL.GDALSetDefaultRAT(@c_pointer, rat_table_ptr)
|
387
380
|
end
|
388
381
|
|
389
382
|
# Gets the default raster histogram. Results are returned as a Hash so some
|
390
383
|
# metadata about the histogram can be returned. Example:
|
391
384
|
#
|
392
385
|
# {
|
393
|
-
# :
|
386
|
+
# :minimum => -0.9,
|
394
387
|
# :maximum => 255.9,
|
395
388
|
# :buckets => 256,
|
396
389
|
# :totals => [
|
@@ -418,7 +411,7 @@ module GDAL
|
|
418
411
|
#
|
419
412
|
# @param force [Boolean] Forces the computation of the histogram. If
|
420
413
|
# +false+ and the default histogram isn't available, this returns nil.
|
421
|
-
# @param block [Proc] No required, but can be used to output
|
414
|
+
# @param block [Proc] No required, but can be used to output progress info
|
422
415
|
# during processing.
|
423
416
|
#
|
424
417
|
# @yieldparam completion [Float] The ration completed as a decimal.
|
@@ -427,35 +420,46 @@ module GDAL
|
|
427
420
|
# @return [Hash{minimum => Float, maximum => Float, buckets => Fixnum,
|
428
421
|
# totals => Array<Fixnum>}] Returns +nil+ if no default histogram is
|
429
422
|
# available.
|
430
|
-
def default_histogram(force=false, &block)
|
423
|
+
def default_histogram(force = false, &block)
|
431
424
|
min_pointer = FFI::MemoryPointer.new(:double)
|
432
425
|
max_pointer = FFI::MemoryPointer.new(:double)
|
433
426
|
buckets_pointer = FFI::MemoryPointer.new(:int)
|
434
427
|
histogram_pointer = FFI::MemoryPointer.new(:pointer)
|
435
428
|
progress_proc = block || nil
|
436
429
|
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
progress_proc,
|
444
|
-
nil
|
445
|
-
)
|
430
|
+
handler = GDAL::CPLErrorHandler.new
|
431
|
+
handler.on_warning = proc { nil }
|
432
|
+
handler.on_none = proc do
|
433
|
+
min = min_pointer.read_double
|
434
|
+
max = max_pointer.read_double
|
435
|
+
buckets = buckets_pointer.read_int
|
446
436
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
437
|
+
totals = if buckets.zero?
|
438
|
+
[]
|
439
|
+
else
|
440
|
+
histogram_pointer.get_pointer(0).read_array_of_int(buckets)
|
441
|
+
end
|
451
442
|
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
443
|
+
{
|
444
|
+
minimum: min,
|
445
|
+
maximum: max,
|
446
|
+
buckets: buckets,
|
447
|
+
totals: totals
|
448
|
+
}
|
456
449
|
end
|
457
450
|
|
458
|
-
|
451
|
+
handler.custom_handle do
|
452
|
+
FFI::GDAL.GDALGetDefaultHistogram(
|
453
|
+
@c_pointer,
|
454
|
+
min_pointer,
|
455
|
+
max_pointer,
|
456
|
+
buckets_pointer,
|
457
|
+
histogram_pointer,
|
458
|
+
force,
|
459
|
+
progress_proc,
|
460
|
+
nil
|
461
|
+
)
|
462
|
+
end
|
459
463
|
end
|
460
464
|
|
461
465
|
# Computes a histogram using the given inputs. If you just want the default
|
@@ -481,25 +485,34 @@ module GDAL
|
|
481
485
|
histogram_pointer = FFI::MemoryPointer.new(:pointer, buckets)
|
482
486
|
progress_proc = block || nil
|
483
487
|
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
buckets
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
'doing things')
|
488
|
+
handler = GDAL::CPLErrorHandler.new
|
489
|
+
handler.on_warning = proc { nil }
|
490
|
+
handler.on_none = proc do
|
491
|
+
totals = if buckets.zero?
|
492
|
+
[]
|
493
|
+
else
|
494
|
+
histogram_pointer.read_array_of_int(buckets)
|
495
|
+
end
|
493
496
|
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
497
|
+
{
|
498
|
+
minimum: min,
|
499
|
+
maximum: max,
|
500
|
+
buckets: buckets,
|
501
|
+
totals: totals
|
502
|
+
}
|
500
503
|
end
|
501
504
|
|
502
|
-
|
505
|
+
handler.custom_handle do
|
506
|
+
FFI::GDAL.GDALGetRasterHistogram(@c_pointer,
|
507
|
+
min.to_f,
|
508
|
+
max.to_f,
|
509
|
+
buckets,
|
510
|
+
histogram_pointer,
|
511
|
+
include_out_of_range,
|
512
|
+
approx_ok,
|
513
|
+
progress_proc,
|
514
|
+
nil)
|
515
|
+
end
|
503
516
|
end
|
504
517
|
|
505
518
|
# Copies the contents of one raster to another similarly configure band.
|
@@ -508,7 +521,7 @@ module GDAL
|
|
508
521
|
#
|
509
522
|
# Options:
|
510
523
|
# * :compressed
|
511
|
-
# * 'YES': forces alignment on the destination_band to
|
524
|
+
# * 'YES': forces alignment on the destination_band to achieve the best
|
512
525
|
# compression.
|
513
526
|
#
|
514
527
|
# @param destination_band [GDAL::RasterBand]
|
@@ -518,13 +531,12 @@ module GDAL
|
|
518
531
|
def copy_whole_raster(destination_band, **options, &progress)
|
519
532
|
destination_pointer = GDAL._pointer(GDAL::RasterBand, destination_band)
|
520
533
|
options_ptr = GDAL::Options.pointer(options)
|
521
|
-
|
534
|
+
|
535
|
+
!!FFI::GDAL.GDALRasterBandCopyWholeRaster(@c_pointer,
|
522
536
|
destination_pointer,
|
523
537
|
options_ptr,
|
524
538
|
progress,
|
525
539
|
nil)
|
526
|
-
|
527
|
-
cpl_err.to_bool
|
528
540
|
end
|
529
541
|
|
530
542
|
# Reads the raster line-by-line and returns as an NArray. Will yield each
|
@@ -533,6 +545,7 @@ module GDAL
|
|
533
545
|
# @yieldparam pixel_line [Array]
|
534
546
|
# @yieldparam line_number [Fixnum]
|
535
547
|
# @return [NArray]
|
548
|
+
# TODO: Extract RasterIO to separate function.
|
536
549
|
def readlines(data_type: :GDT_Byte)
|
537
550
|
x_offset = 0
|
538
551
|
line_size = 1
|
@@ -540,8 +553,9 @@ module GDAL
|
|
540
553
|
line_space = 0
|
541
554
|
scan_line = GDAL._pointer_from_data_type(data_type, x_size)
|
542
555
|
|
543
|
-
the_array =
|
544
|
-
FFI::GDAL.GDALRasterIO(
|
556
|
+
the_array = y_size.times.map do |y|
|
557
|
+
FFI::GDAL.GDALRasterIO(
|
558
|
+
@c_pointer,
|
545
559
|
:GF_Read,
|
546
560
|
x_offset,
|
547
561
|
y,
|
@@ -556,10 +570,10 @@ module GDAL
|
|
556
570
|
)
|
557
571
|
|
558
572
|
line_array = if data_type == :GDT_Byte
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
573
|
+
scan_line.read_array_of_uint8(x_size)
|
574
|
+
else
|
575
|
+
scan_line.read_array_of_float(x_size)
|
576
|
+
end
|
563
577
|
|
564
578
|
yield(line_array, y) if block_given?
|
565
579
|
|
@@ -569,16 +583,15 @@ module GDAL
|
|
569
583
|
NArray.to_na(the_array)
|
570
584
|
end
|
571
585
|
|
572
|
-
# @param pixel_array [NArray] The
|
586
|
+
# @param pixel_array [NArray] The list of pixels.
|
573
587
|
# @param x_offset [Fixnum] The left-most pixel to start writing.
|
574
588
|
# @param y_offset [Fixnum] The top-most pixel to start writing.
|
575
|
-
# @param data_type [FFI::GDAL::
|
589
|
+
# @param data_type [FFI::GDAL::DataType] The type of pixel contained in
|
576
590
|
# the +pixel_array+.
|
577
591
|
# @param line_space [Fixnum]
|
578
592
|
# @param pixel_space [Fixnum]
|
579
593
|
# TODO: Write using #buffer_size to write most efficiently.
|
580
|
-
|
581
|
-
def write_array(pixel_array, x_offset: 0, y_offset: 0, data_type: :GDT_Byte,
|
594
|
+
def write_array(pixel_array, x_offset: 0, y_offset: 0, data_type: self.data_type,
|
582
595
|
line_space: 0, pixel_space: 0)
|
583
596
|
line_size = 1
|
584
597
|
x_size = pixel_array.sizes.first
|
@@ -594,7 +607,8 @@ module GDAL
|
|
594
607
|
meth = "write_array_of_#{ffi_type}".to_sym
|
595
608
|
scan_line.send(meth, pixels.to_a)
|
596
609
|
|
597
|
-
FFI::GDAL.GDALRasterIO(
|
610
|
+
FFI::GDAL.GDALRasterIO(
|
611
|
+
@c_pointer,
|
598
612
|
:GF_Write,
|
599
613
|
x_offset, # nXOff
|
600
614
|
y,
|
@@ -619,97 +633,49 @@ module GDAL
|
|
619
633
|
# the left-most block, 1 the next block, etc.
|
620
634
|
# @param y_offset [Fixnum] The vertical block offset, with 0 indicating the
|
621
635
|
# top-most block, 1 the next block, etc.
|
622
|
-
|
636
|
+
# @return [FFI::MemoryPointer] The image buffer.
|
637
|
+
def read_block(x_offset, y_offset, image_buffer = nil)
|
623
638
|
image_buffer ||= FFI::MemoryPointer.new(:void)
|
624
|
-
result = FFI::GDAL.GDALReadBlock(@raster_band_pointer, x_offset, y_offset, image_buffer)
|
625
639
|
|
626
|
-
|
640
|
+
FFI::GDAL.GDALReadBlock(@c_pointer, x_offset, y_offset, image_buffer)
|
641
|
+
|
642
|
+
image_buffer
|
627
643
|
end
|
628
644
|
|
629
645
|
# The minimum and maximum values for this band.
|
630
646
|
#
|
631
|
-
# @return [
|
632
|
-
def min_max
|
633
|
-
|
634
|
-
|
635
|
-
min_max.put_array_of_double 0, [minimum_value[:value], maximum_value[:value]]
|
636
|
-
FFI::GDAL.GDALComputeRasterMinMax(@raster_band_pointer, 1, min_max)
|
647
|
+
# @return [Hash{min => Float, max => Float}]
|
648
|
+
def min_max(approx_ok: false)
|
649
|
+
min_max = FFI::MemoryPointer.new(:double, 2)
|
650
|
+
FFI::GDAL.GDALComputeRasterMinMax(@c_pointer, approx_ok, min_max)
|
637
651
|
|
638
|
-
|
639
|
-
else
|
640
|
-
[0.0, 0.0]
|
641
|
-
end
|
652
|
+
{ min: min_max[0].read_double, max: min_max[1].read_double }
|
642
653
|
end
|
643
654
|
|
644
|
-
#
|
655
|
+
# The minimum value in the band, not counting NODATA values. For file
|
656
|
+
# formats that don't know this intrinsically, the minimum supported value
|
657
|
+
# for the data type will generally be returned.
|
658
|
+
#
|
659
|
+
# @return [Hash{value => Float, is_tight => Boolean}] The +is_tight+ value
|
660
|
+
# tells whether the minimum is a tight minimum.
|
645
661
|
def minimum_value
|
646
662
|
is_tight = FFI::MemoryPointer.new(:bool)
|
647
|
-
value = FFI::GDAL.GDALGetRasterMinimum(@
|
663
|
+
value = FFI::GDAL.GDALGetRasterMinimum(@c_pointer, is_tight)
|
648
664
|
|
649
665
|
{ value: value, is_tight: is_tight.read_bytes(1).to_bool }
|
650
666
|
end
|
651
667
|
|
652
|
-
#
|
668
|
+
# The maximum value in the band, not counting NODATA values. For file
|
669
|
+
# formats that don't know this intrinsically, the maximum supported value
|
670
|
+
# for the data type will generally be returned.
|
671
|
+
#
|
672
|
+
# @return [Hash{value => Float, is_tight => Boolean}] The +is_tight+ value
|
673
|
+
# tells whether the maximum is a tight maximum.
|
653
674
|
def maximum_value
|
654
|
-
is_tight = FFI::MemoryPointer.new(:
|
655
|
-
value = FFI::GDAL.GDALGetRasterMaximum(@
|
675
|
+
is_tight = FFI::MemoryPointer.new(:bool)
|
676
|
+
value = FFI::GDAL.GDALGetRasterMaximum(@c_pointer, is_tight)
|
656
677
|
|
657
678
|
{ value: value, is_tight: is_tight.read_bytes(1).to_bool }
|
658
679
|
end
|
659
|
-
|
660
|
-
# Creates vector polygons for all connected regions of pixels in the raster
|
661
|
-
# that share a common pixel value.
|
662
|
-
#
|
663
|
-
# @param layer [OGR::Layer, FFI::Pointer] The layer to write the polygons
|
664
|
-
# to.
|
665
|
-
# @param mask_band [GDAL::RasterBand, FFI::Pointer] Optional band, where all
|
666
|
-
# pixels in the mask with a value other than zero will be considered
|
667
|
-
# suitable for collection as polygons.
|
668
|
-
# @param pixel_value_field [Fixnum] Index of the feature attribute into
|
669
|
-
# which the pixel value of the polygon should be written.
|
670
|
-
# @param options [Hash]
|
671
|
-
# @param progress [Proc]
|
672
|
-
# @return [OGR::Layer]
|
673
|
-
def polygonize(layer, mask_band: nil, pixel_value_field: -1, **options, &progress)
|
674
|
-
mask_band_ptr = GDAL._pointer(GDAL::RasterBand, mask_band, false)
|
675
|
-
|
676
|
-
layer_ptr = GDAL._pointer(OGR::Layer, layer)
|
677
|
-
raise "Invalid layer: #{layer.inspect}" if layer_ptr.null?
|
678
|
-
|
679
|
-
options_ptr = GDAL::Options.pointer(options)
|
680
|
-
|
681
|
-
cpl_err = FFI::GDAL.GDALFPolygonize(@raster_band_pointer, # hSrcBand
|
682
|
-
mask_band_ptr, # hMaskBand
|
683
|
-
layer_ptr, # hOutLayer
|
684
|
-
pixel_value_field, # iPixValField
|
685
|
-
options_ptr, # papszOptions
|
686
|
-
progress, # pfnProgress
|
687
|
-
nil # pProgressArg
|
688
|
-
)
|
689
|
-
cpl_err.to_ruby
|
690
|
-
|
691
|
-
OGR::Layer.new(layer_ptr)
|
692
|
-
end
|
693
|
-
|
694
|
-
#---------------------------------------------------------------------------
|
695
|
-
# Privates
|
696
|
-
#---------------------------------------------------------------------------
|
697
|
-
|
698
|
-
private
|
699
|
-
|
700
|
-
def formatted_buckets(cpl_err, min, max, buckets, totals)
|
701
|
-
case cpl_err.to_ruby
|
702
|
-
when :none
|
703
|
-
{
|
704
|
-
minimum: min,
|
705
|
-
maximum: max,
|
706
|
-
buckets: buckets,
|
707
|
-
totals: totals
|
708
|
-
}
|
709
|
-
when :warning then return nil
|
710
|
-
when :failure then raise CPLError
|
711
|
-
else raise CPLError
|
712
|
-
end
|
713
|
-
end
|
714
680
|
end
|
715
681
|
end
|