ffi-gdal 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +9 -0
- data/.devcontainer/devcontainer.json +98 -0
- data/.github/CODEOWNERS +1 -0
- data/.github/workflows/codacy.yml +3 -3
- data/.github/workflows/codeql.yml +4 -4
- data/.github/workflows/continuous-integration.yml +30 -19
- data/.github/workflows/dependency-review.yml +2 -2
- data/.github/workflows/specs-in-docker.yml +12 -6
- data/.gitignore +4 -1
- data/Changelog.md +45 -4
- data/Gemfile +4 -2
- data/README.md +35 -0
- data/bin/rake +1 -1
- data/bin/rspec +1 -1
- data/bin/rubocop +1 -1
- data/lib/ext/numeric_as_data_type.rb +1 -1
- data/lib/ffi/cpl/vsi.rb +10 -0
- data/lib/ffi/gdal/gdal.rb +9 -2
- data/lib/ffi/gdal/grid_data_metrics_options.rb +27 -5
- data/lib/ffi/gdal/grid_inverse_distance_to_a_power_options.rb +30 -10
- data/lib/ffi/gdal/grid_moving_average_options.rb +30 -5
- data/lib/ffi/gdal/grid_nearest_neighbor_options.rb +24 -4
- data/lib/ffi/gdal/internal_helpers/gdal_version.rb +15 -0
- data/lib/ffi/gdal/internal_helpers/layout_version.rb +9 -0
- data/lib/ffi/gdal/internal_helpers/layout_version_resolver.rb +24 -0
- data/lib/ffi/gdal/internal_helpers.rb +11 -0
- data/lib/ffi/gdal/utils.rb +984 -0
- data/lib/ffi/gdal/version.rb +1 -1
- data/lib/ffi/gdal.rb +3 -1
- data/lib/ffi/ogr/core.rb +1 -1
- data/lib/ffi/ogr/srs_api.rb +17 -0
- data/lib/gdal/cpl_error_handler.rb +30 -15
- data/lib/gdal/exceptions.rb +35 -16
- data/lib/gdal/extensions/color_table/extensions.rb +1 -1
- data/lib/gdal/extensions/gridder.rb +4 -0
- data/lib/gdal/geo_transform.rb +13 -0
- data/lib/gdal/grid_algorithms/algorithm_base.rb +35 -0
- data/lib/gdal/grid_algorithms/inverse_distance_to_a_power.rb +3 -7
- data/lib/gdal/grid_algorithms/metric_average_distance.rb +5 -4
- data/lib/gdal/grid_algorithms/metric_average_distance_pts.rb +5 -4
- data/lib/gdal/grid_algorithms/metric_count.rb +5 -4
- data/lib/gdal/grid_algorithms/metric_maximum.rb +5 -4
- data/lib/gdal/grid_algorithms/metric_minimum.rb +5 -4
- data/lib/gdal/grid_algorithms/metric_range.rb +5 -4
- data/lib/gdal/grid_algorithms/moving_average.rb +3 -7
- data/lib/gdal/grid_algorithms/nearest_neighbor.rb +3 -7
- data/lib/gdal/grid_algorithms.rb +2 -0
- data/lib/gdal/internal_helpers.rb +8 -5
- data/lib/gdal/major_object.rb +6 -0
- data/lib/gdal/raster_band.rb +16 -12
- data/lib/gdal/utils/dem/options.rb +52 -0
- data/lib/gdal/utils/dem.rb +108 -0
- data/lib/gdal/utils/grid/options.rb +52 -0
- data/lib/gdal/utils/grid.rb +72 -0
- data/lib/gdal/utils/helpers/dataset_list.rb +43 -0
- data/lib/gdal/utils/helpers/string_list.rb +47 -0
- data/lib/gdal/utils/helpers.rb +11 -0
- data/lib/gdal/utils/info/options.rb +52 -0
- data/lib/gdal/utils/info.rb +40 -0
- data/lib/gdal/utils/nearblack/options.rb +52 -0
- data/lib/gdal/utils/nearblack.rb +119 -0
- data/lib/gdal/utils/rasterize/options.rb +52 -0
- data/lib/gdal/utils/rasterize.rb +108 -0
- data/lib/gdal/utils/translate/options.rb +52 -0
- data/lib/gdal/utils/translate.rb +72 -0
- data/lib/gdal/utils/vector_translate/options.rb +52 -0
- data/lib/gdal/utils/vector_translate.rb +132 -0
- data/lib/gdal/utils/warp/options.rb +52 -0
- data/lib/gdal/utils/warp.rb +118 -0
- data/lib/gdal/utils.rb +22 -0
- data/lib/gdal/warp_options.rb +11 -2
- data/lib/gdal.rb +1 -0
- data/lib/ogr/extensions/geometry/extensions.rb +0 -8
- data/lib/ogr/extensions/layer/extensions.rb +1 -1
- data/lib/ogr/extensions/spatial_reference/extensions.rb +4 -4
- data/lib/ogr/geometry.rb +9 -6
- data/lib/ogr/layer.rb +1 -1
- data/lib/ogr/spatial_reference.rb +27 -2
- metadata +32 -5
- data/.ruby-version +0 -1
- data/lib/gdal/grid_algorithms/data_metrics_base.rb +0 -14
data/lib/ffi/gdal/version.rb
CHANGED
data/lib/ffi/gdal.rb
CHANGED
@@ -19,9 +19,11 @@ module FFI
|
|
19
19
|
File.expand_path("gdal/grid_inverse_distance_to_a_power_options.rb", __dir__)
|
20
20
|
autoload :GridMovingAverageOptions, File.expand_path("gdal/grid_moving_average_options.rb", __dir__)
|
21
21
|
autoload :GridNearestNeighborOptions, File.expand_path("gdal/grid_nearest_neighbor_options.rb", __dir__)
|
22
|
+
autoload :InternalHelpers, File.expand_path("gdal/internal_helpers.rb", __dir__)
|
22
23
|
autoload :Matching, File.expand_path("gdal/matching.rb", __dir__)
|
23
24
|
autoload :RPCInfo, File.expand_path("gdal/rpc_info.rb", __dir__)
|
24
25
|
autoload :TransformerInfo, File.expand_path("gdal/transformer_info.rb", __dir__)
|
26
|
+
autoload :Utils, File.expand_path("gdal/utils.rb", __dir__)
|
25
27
|
autoload :VRT, File.expand_path("gdal/vrt.rb", __dir__)
|
26
28
|
autoload :Warper, File.expand_path("gdal/warper.rb", __dir__)
|
27
29
|
autoload :WarpOptions, File.expand_path("gdal/warp_options.rb", __dir__)
|
@@ -39,7 +41,7 @@ module FFI
|
|
39
41
|
ogr_core.h ogr_srs_api.h
|
40
42
|
]
|
41
43
|
|
42
|
-
header_search_paths = %w[/usr/local/include /usr/include /usr/include/gdal]
|
44
|
+
header_search_paths = %w[/usr/local/include /usr/include /usr/include/gdal /opt/homebrew/include/]
|
43
45
|
|
44
46
|
header_files.map do |file|
|
45
47
|
dir = header_search_paths.find do |d|
|
data/lib/ffi/ogr/core.rb
CHANGED
data/lib/ffi/ogr/srs_api.rb
CHANGED
@@ -38,6 +38,13 @@ module FFI
|
|
38
38
|
:ODT_LD_Min, 10_000,
|
39
39
|
:ODT_LD_Max, 32_767
|
40
40
|
|
41
|
+
# https://gdal.org/api/ogr_srs_api.html#_CPPv422OSRAxisMappingStrategy
|
42
|
+
OSRAxisMappingStrategy = enum(
|
43
|
+
:OAMS_TRADITIONAL_GIS_ORDER, 0,
|
44
|
+
:OAMS_AUTHORITY_COMPLIANT, 1,
|
45
|
+
:OAMS_CUSTOM, 2
|
46
|
+
)
|
47
|
+
|
41
48
|
# -----------------------------------------------------------------------
|
42
49
|
# Constants
|
43
50
|
# -----------------------------------------------------------------------
|
@@ -125,6 +132,10 @@ module FFI
|
|
125
132
|
# ~~~~~~~~~~~~~
|
126
133
|
# SpatialReference
|
127
134
|
# ~~~~~~~~~~~~~
|
135
|
+
|
136
|
+
# https://gdal.org/api/ogr_srs_api.html#_CPPv417OSRGetPROJVersionPiPiPi
|
137
|
+
attach_function :OSRGetPROJVersion, %i[pointer pointer pointer], :void
|
138
|
+
|
128
139
|
attach_function :OSRNewSpatialReference, %i[string], :OGRSpatialReferenceH
|
129
140
|
attach_function :OSRCloneGeogCS, %i[OGRSpatialReferenceH], :OGRSpatialReferenceH
|
130
141
|
attach_function :OSRClone, %i[OGRSpatialReferenceH], :OGRSpatialReferenceH
|
@@ -215,6 +226,12 @@ module FFI
|
|
215
226
|
%i[OGRSpatialReferenceH string int pointer],
|
216
227
|
:string
|
217
228
|
|
229
|
+
# https://gdal.org/api/ogr_srs_api.html#_CPPv425OSRGetAxisMappingStrategy20OGRSpatialReferenceH
|
230
|
+
attach_function :OSRGetAxisMappingStrategy, %i[OGRSpatialReferenceH], OSRAxisMappingStrategy
|
231
|
+
|
232
|
+
# https://gdal.org/api/ogr_srs_api.html#_CPPv425OSRGetAxisMappingStrategy20OGRSpatialReferenceH
|
233
|
+
attach_function :OSRSetAxisMappingStrategy, [:OGRSpatialReferenceH, OSRAxisMappingStrategy], :void
|
234
|
+
|
218
235
|
attach_function :OSRSetACEA,
|
219
236
|
%i[OGRSpatialReferenceH double double double double double double],
|
220
237
|
FFI::OGR::Core::Err
|
@@ -9,19 +9,27 @@ module GDAL
|
|
9
9
|
class CPLErrorHandler
|
10
10
|
include GDAL::Logger
|
11
11
|
|
12
|
+
# NOTE: Error codes are defined in https://gdal.org/doxygen/cpl__error_8h_source.html
|
12
13
|
CPLE_MAP = [
|
13
|
-
{ cple: :CPLE_None,
|
14
|
-
{ cple: :CPLE_AppDefined,
|
15
|
-
{ cple: :CPLE_OutOfMemory,
|
16
|
-
{ cple: :CPLE_FileIO,
|
17
|
-
{ cple: :CPLE_OpenFailed,
|
18
|
-
{ cple: :CPLE_IllegalArg,
|
19
|
-
{ cple: :CPLE_NotSupported,
|
20
|
-
{ cple: :CPLE_AssertionFailed,
|
21
|
-
{ cple: :CPLE_NoWriteAccess,
|
22
|
-
{ cple: :CPLE_UserInterrupt,
|
23
|
-
{ cple: :CPLE_ObjectNull,
|
14
|
+
{ cple: :CPLE_None, exception: nil }.freeze,
|
15
|
+
{ cple: :CPLE_AppDefined, exception: GDAL::Error }.freeze,
|
16
|
+
{ cple: :CPLE_OutOfMemory, exception: ::NoMemoryError }.freeze,
|
17
|
+
{ cple: :CPLE_FileIO, exception: ::IOError }.freeze,
|
18
|
+
{ cple: :CPLE_OpenFailed, exception: GDAL::OpenFailure }.freeze,
|
19
|
+
{ cple: :CPLE_IllegalArg, exception: ::ArgumentError }.freeze,
|
20
|
+
{ cple: :CPLE_NotSupported, exception: GDAL::UnsupportedOperation }.freeze,
|
21
|
+
{ cple: :CPLE_AssertionFailed, exception: ::RuntimeError }.freeze,
|
22
|
+
{ cple: :CPLE_NoWriteAccess, exception: GDAL::NoWriteAccess }.freeze,
|
23
|
+
{ cple: :CPLE_UserInterrupt, exception: ::Interrupt }.freeze,
|
24
|
+
{ cple: :CPLE_ObjectNull, exception: GDAL::NullObject }.freeze,
|
25
|
+
{ cple: :CPLE_HttpResponse, exception: GDAL::HttpResponse }.freeze,
|
26
|
+
{ cple: :CPLE_AWSBucketNotFound, exception: GDAL::AWSBucketNotFound }.freeze,
|
27
|
+
{ cple: :CPLE_AWSObjectNotFound, exception: GDAL::AWSObjectNotFound }.freeze,
|
28
|
+
{ cple: :CPLE_AWSAccessDenied, exception: GDAL::AWSAccessDenied }.freeze,
|
29
|
+
{ cple: :CPLE_AWSInvalidCredentials, exception: GDAL::AWSInvalidCredentials }.freeze,
|
30
|
+
{ cple: :CPLE_AWSSignatureDoesNotMatch, exception: GDAL::AWSSignatureDoesNotMatch }.freeze
|
24
31
|
].freeze
|
32
|
+
FALLBACK_CPLE_EXCEPTION = { exception: GDAL::Error }.freeze
|
25
33
|
|
26
34
|
FAIL_PROC = lambda do |exception, message|
|
27
35
|
ex = exception ? exception.new(message) : GDAL::Error.new(message)
|
@@ -65,11 +73,15 @@ module GDAL
|
|
65
73
|
|
66
74
|
def initialize
|
67
75
|
@on_none = SUCCESS_PROC
|
68
|
-
|
76
|
+
|
77
|
+
@on_debug = lambda do |_, message|
|
78
|
+
logger.debug(message)
|
79
|
+
true
|
80
|
+
end
|
69
81
|
|
70
82
|
@on_warning = lambda do |_, message|
|
71
|
-
warn(message)
|
72
|
-
|
83
|
+
logger.warn(message)
|
84
|
+
true
|
73
85
|
end
|
74
86
|
|
75
87
|
@on_failure = FAIL_PROC
|
@@ -123,7 +135,10 @@ module GDAL
|
|
123
135
|
|
124
136
|
# @return Whatever the Proc evaluates.
|
125
137
|
def result(error_class, error_number, message)
|
126
|
-
error_class_map(error_class).call(
|
138
|
+
error_class_map(error_class).call(
|
139
|
+
CPLE_MAP.fetch(error_number, FALLBACK_CPLE_EXCEPTION).fetch(:exception),
|
140
|
+
message
|
141
|
+
)
|
127
142
|
end
|
128
143
|
|
129
144
|
def error_class_map(error_class)
|
data/lib/gdal/exceptions.rb
CHANGED
@@ -1,22 +1,50 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module GDAL
|
4
|
-
class BufferTooSmall < StandardError
|
5
|
-
end
|
6
|
-
|
7
|
-
class CreateFail < StandardError
|
8
|
-
end
|
9
|
-
|
10
4
|
class Error < ::RuntimeError
|
11
5
|
end
|
12
6
|
|
13
|
-
|
7
|
+
# CPLE_OpenFailed
|
8
|
+
class OpenFailure < ::StandardError
|
14
9
|
def initialize(file, msg = nil)
|
15
10
|
message = msg || "Unable to open file '#{file}'. Perhaps an unsupported file format?"
|
16
11
|
super(message)
|
17
12
|
end
|
18
13
|
end
|
19
14
|
|
15
|
+
# CPLE_NotSupported
|
16
|
+
class UnsupportedOperation < ::StandardError; end
|
17
|
+
|
18
|
+
# CPLE_NoWriteAccess
|
19
|
+
class NoWriteAccess < ::RuntimeError; end
|
20
|
+
|
21
|
+
# CPLE_ObjectNull
|
22
|
+
class NullObject < ::TypeError; end
|
23
|
+
|
24
|
+
# CPLE_HttpResponse
|
25
|
+
class HttpResponse < ::RuntimeError; end
|
26
|
+
|
27
|
+
# CPLE_AWSBucketNotFound
|
28
|
+
class AWSBucketNotFound < ::RuntimeError; end
|
29
|
+
|
30
|
+
# CPLE_AWSObjectNotFound
|
31
|
+
class AWSObjectNotFound < ::RuntimeError; end
|
32
|
+
|
33
|
+
# CPLE_AWSAccessDenied
|
34
|
+
class AWSAccessDenied < ::RuntimeError; end
|
35
|
+
|
36
|
+
# CPLE_AWSInvalidCredentials
|
37
|
+
class AWSInvalidCredentials < ::RuntimeError; end
|
38
|
+
|
39
|
+
# CPLE_AWSSignatureDoesNotMatch
|
40
|
+
class AWSSignatureDoesNotMatch < ::RuntimeError; end
|
41
|
+
|
42
|
+
class BufferTooSmall < StandardError
|
43
|
+
end
|
44
|
+
|
45
|
+
class CreateFail < StandardError
|
46
|
+
end
|
47
|
+
|
20
48
|
class InvalidAccessFlag < RuntimeError
|
21
49
|
end
|
22
50
|
|
@@ -51,12 +79,6 @@ module GDAL
|
|
51
79
|
class NoValuesToGrid < RuntimeError
|
52
80
|
end
|
53
81
|
|
54
|
-
class NoWriteAccess < RuntimeError
|
55
|
-
end
|
56
|
-
|
57
|
-
class NullObject < TypeError
|
58
|
-
end
|
59
|
-
|
60
82
|
class RequiredBandNotFound < StandardError
|
61
83
|
end
|
62
84
|
|
@@ -69,7 +91,4 @@ module GDAL
|
|
69
91
|
|
70
92
|
class UnknownRasterAttributeTableType < StandardError
|
71
93
|
end
|
72
|
-
|
73
|
-
class UnsupportedOperation < StandardError
|
74
|
-
end
|
75
94
|
end
|
@@ -10,7 +10,7 @@ module GDAL
|
|
10
10
|
raise "Invalid ColorEntry number 'color#{color_number}'" unless (1..4).to_a.include? color_number
|
11
11
|
|
12
12
|
Array.new(color_entry_count) do |i|
|
13
|
-
color_entry(i).send("color#{color_number}"
|
13
|
+
color_entry(i).send(:"color#{color_number}")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -4,6 +4,10 @@ require "narray"
|
|
4
4
|
require "gdal"
|
5
5
|
require "gdal/options"
|
6
6
|
require "ogr"
|
7
|
+
require "ogr/extensions/envelope/extensions"
|
8
|
+
require "ogr/extensions/layer/extensions"
|
9
|
+
require "gdal/extensions/geo_transform/extensions"
|
10
|
+
|
7
11
|
require_relative "gridder_options"
|
8
12
|
require_relative "gridder/point_extracting"
|
9
13
|
|
data/lib/gdal/geo_transform.rb
CHANGED
@@ -40,6 +40,19 @@ module GDAL
|
|
40
40
|
self.y_rotation ||= 0.0
|
41
41
|
end
|
42
42
|
|
43
|
+
# @param other [GDAL::GeoTransform]
|
44
|
+
# @return [Boolean]
|
45
|
+
def ==(other)
|
46
|
+
return false unless other.is_a?(GDAL::GeoTransform)
|
47
|
+
|
48
|
+
x_origin == other.x_origin &&
|
49
|
+
pixel_width == other.pixel_width &&
|
50
|
+
x_rotation == other.x_rotation &&
|
51
|
+
y_origin == other.y_origin &&
|
52
|
+
y_rotation == other.y_rotation &&
|
53
|
+
pixel_height == other.pixel_height
|
54
|
+
end
|
55
|
+
|
43
56
|
def null?
|
44
57
|
@c_pointer.null?
|
45
58
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GDAL
|
4
|
+
module GridAlgorithms
|
5
|
+
# Base abstract class for all grid algorithms.
|
6
|
+
class AlgorithmBase
|
7
|
+
# @return Options object.
|
8
|
+
attr_reader :options
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@options = options_class.new
|
12
|
+
assign_size_of_structure
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Class] Options class.
|
16
|
+
def options_class
|
17
|
+
# This method must be overridden in subclasses.
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Symbol] C identifier for the algorithm.
|
21
|
+
def c_identifier
|
22
|
+
# This method must be overridden in subclasses.
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def assign_size_of_structure
|
28
|
+
# Starting GDAL 3.6.0 we must assign nSizeOfStructure to the size of the structure.
|
29
|
+
return unless @options.members.include?(:n_size_of_structure)
|
30
|
+
|
31
|
+
@options[:n_size_of_structure] = @options.size
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -2,15 +2,11 @@
|
|
2
2
|
|
3
3
|
module GDAL
|
4
4
|
module GridAlgorithms
|
5
|
-
class InverseDistanceToAPower
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@options = FFI::GDAL::GridInverseDistanceToAPowerOptions.new
|
5
|
+
class InverseDistanceToAPower < AlgorithmBase
|
6
|
+
def options_class
|
7
|
+
::FFI::GDAL::GridInverseDistanceToAPowerOptions
|
11
8
|
end
|
12
9
|
|
13
|
-
# @return [Symbol]
|
14
10
|
def c_identifier
|
15
11
|
:GGA_InverseDistanceToAPower
|
16
12
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "data_metrics_base"
|
4
|
-
|
5
3
|
module GDAL
|
6
4
|
module GridAlgorithms
|
7
|
-
class MetricAverageDistance <
|
8
|
-
|
5
|
+
class MetricAverageDistance < AlgorithmBase
|
6
|
+
def options_class
|
7
|
+
::FFI::GDAL::GridDataMetricsOptions
|
8
|
+
end
|
9
|
+
|
9
10
|
def c_identifier
|
10
11
|
:GGA_MetricAverageDistance
|
11
12
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "data_metrics_base"
|
4
|
-
|
5
3
|
module GDAL
|
6
4
|
module GridAlgorithms
|
7
|
-
class MetricAverageDistancePts <
|
8
|
-
|
5
|
+
class MetricAverageDistancePts < AlgorithmBase
|
6
|
+
def options_class
|
7
|
+
::FFI::GDAL::GridDataMetricsOptions
|
8
|
+
end
|
9
|
+
|
9
10
|
def c_identifier
|
10
11
|
:GGA_MetricAverageDistancePts
|
11
12
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "data_metrics_base"
|
4
|
-
|
5
3
|
module GDAL
|
6
4
|
module GridAlgorithms
|
7
|
-
class MetricCount <
|
8
|
-
|
5
|
+
class MetricCount < AlgorithmBase
|
6
|
+
def options_class
|
7
|
+
::FFI::GDAL::GridDataMetricsOptions
|
8
|
+
end
|
9
|
+
|
9
10
|
def c_identifier
|
10
11
|
:GGA_MetricCount
|
11
12
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "data_metrics_base"
|
4
|
-
|
5
3
|
module GDAL
|
6
4
|
module GridAlgorithms
|
7
|
-
class MetricMaximum <
|
8
|
-
|
5
|
+
class MetricMaximum < AlgorithmBase
|
6
|
+
def options_class
|
7
|
+
::FFI::GDAL::GridDataMetricsOptions
|
8
|
+
end
|
9
|
+
|
9
10
|
def c_identifier
|
10
11
|
:GGA_MetricMaximum
|
11
12
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "data_metrics_base"
|
4
|
-
|
5
3
|
module GDAL
|
6
4
|
module GridAlgorithms
|
7
|
-
class MetricMinimum <
|
8
|
-
|
5
|
+
class MetricMinimum < AlgorithmBase
|
6
|
+
def options_class
|
7
|
+
::FFI::GDAL::GridDataMetricsOptions
|
8
|
+
end
|
9
|
+
|
9
10
|
def c_identifier
|
10
11
|
:GGA_MetricMinimum
|
11
12
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "data_metrics_base"
|
4
|
-
|
5
3
|
module GDAL
|
6
4
|
module GridAlgorithms
|
7
|
-
class MetricRange <
|
8
|
-
|
5
|
+
class MetricRange < AlgorithmBase
|
6
|
+
def options_class
|
7
|
+
::FFI::GDAL::GridDataMetricsOptions
|
8
|
+
end
|
9
|
+
|
9
10
|
def c_identifier
|
10
11
|
:GGA_MetricRange
|
11
12
|
end
|
@@ -2,15 +2,11 @@
|
|
2
2
|
|
3
3
|
module GDAL
|
4
4
|
module GridAlgorithms
|
5
|
-
class MovingAverage
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@options = FFI::GDAL::GridMovingAverageOptions.new
|
5
|
+
class MovingAverage < AlgorithmBase
|
6
|
+
def options_class
|
7
|
+
::FFI::GDAL::GridMovingAverageOptions
|
11
8
|
end
|
12
9
|
|
13
|
-
# @return [Symbol]
|
14
10
|
def c_identifier
|
15
11
|
:GGA_MovingAverage
|
16
12
|
end
|
@@ -2,15 +2,11 @@
|
|
2
2
|
|
3
3
|
module GDAL
|
4
4
|
module GridAlgorithms
|
5
|
-
class NearestNeighbor
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@options = FFI::GDAL::GridNearestNeighborOptions.new
|
5
|
+
class NearestNeighbor < AlgorithmBase
|
6
|
+
def options_class
|
7
|
+
::FFI::GDAL::GridNearestNeighborOptions
|
11
8
|
end
|
12
9
|
|
13
|
-
# @return [Symbol]
|
14
10
|
def c_identifier
|
15
11
|
:GGA_NearestNeighbor
|
16
12
|
end
|
data/lib/gdal/grid_algorithms.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module GDAL
|
4
4
|
module GridAlgorithms
|
5
|
+
autoload :AlgorithmBase,
|
6
|
+
File.expand_path("grid_algorithms/algorithm_base", __dir__)
|
5
7
|
autoload :InverseDistanceToAPower,
|
6
8
|
File.expand_path("grid_algorithms/inverse_distance_to_a_power", __dir__)
|
7
9
|
autoload :MetricAverageDistance,
|
@@ -106,7 +106,7 @@ module GDAL
|
|
106
106
|
def _read_pointer_pointer_safely(pointer_ptr, type)
|
107
107
|
return if pointer_ptr.read_pointer.null?
|
108
108
|
|
109
|
-
pointer_ptr.read_pointer.send("read_#{type}"
|
109
|
+
pointer_ptr.read_pointer.send(:"read_#{type}")
|
110
110
|
end
|
111
111
|
|
112
112
|
# Convenience function for allocating a pointer to a string (**char),
|
@@ -141,10 +141,13 @@ module GDAL
|
|
141
141
|
def _gdal_data_type_to_ffi(data_type)
|
142
142
|
case data_type
|
143
143
|
when :GDT_Byte then :uchar
|
144
|
+
when :GDT_Int8 then :int8
|
144
145
|
when :GDT_UInt16 then :uint16
|
145
146
|
when :GDT_Int16, :GDT_CInt16 then :int16
|
146
147
|
when :GDT_UInt32 then :uint32
|
147
148
|
when :GDT_Int32, :GDT_CInt32 then :int32
|
149
|
+
when :GDT_UInt64 then :uint64
|
150
|
+
when :GDT_Int64 then :int64
|
148
151
|
when :GDT_Float32, :GDT_CFloat32 then :float
|
149
152
|
when :GDT_Float64, :GDT_CFloat64 then :double
|
150
153
|
else
|
@@ -201,9 +204,9 @@ module GDAL
|
|
201
204
|
# @return [Number, Array<Number>]
|
202
205
|
def _read_pointer(pointer, data_type, length = 1)
|
203
206
|
if length == 1
|
204
|
-
pointer.send("read_#{_gdal_data_type_to_ffi(data_type)}")
|
207
|
+
pointer.send(:"read_#{_gdal_data_type_to_ffi(data_type)}")
|
205
208
|
else
|
206
|
-
pointer.send("read_array_of_#{_gdal_data_type_to_ffi(data_type)}", length)
|
209
|
+
pointer.send(:"read_array_of_#{_gdal_data_type_to_ffi(data_type)}", length)
|
207
210
|
end
|
208
211
|
end
|
209
212
|
|
@@ -217,10 +220,10 @@ module GDAL
|
|
217
220
|
# with size > 1, the "write_array_of_" method will be called.
|
218
221
|
def _write_pointer(pointer, data_type, data)
|
219
222
|
if data.is_a?(Array) && data.size > 1
|
220
|
-
pointer.send("write_array_of_#{_gdal_data_type_to_ffi(data_type)}", data)
|
223
|
+
pointer.send(:"write_array_of_#{_gdal_data_type_to_ffi(data_type)}", data)
|
221
224
|
else
|
222
225
|
data = data.first if data.is_a?(Array)
|
223
|
-
pointer.send("write_#{_gdal_data_type_to_ffi(data_type)}", data)
|
226
|
+
pointer.send(:"write_#{_gdal_data_type_to_ffi(data_type)}", data)
|
224
227
|
end
|
225
228
|
end
|
226
229
|
|
data/lib/gdal/major_object.rb
CHANGED
data/lib/gdal/raster_band.rb
CHANGED
@@ -347,14 +347,16 @@ module GDAL
|
|
347
347
|
# returned.
|
348
348
|
#
|
349
349
|
# @return Float
|
350
|
-
# @raise GDAL::Error if the underlying call fails.
|
351
350
|
def scale
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
raise GDAL::Error, "GDALGetRasterScale failed" unless success.read_bytes(1).to_bool
|
351
|
+
FFI::GDAL::GDAL.GDALGetRasterScale(@c_pointer, nil)
|
352
|
+
end
|
356
353
|
|
357
|
-
|
354
|
+
# Check if the scale is set.
|
355
|
+
# @return [Boolean]
|
356
|
+
def scale?
|
357
|
+
success = FFI::MemoryPointer.new(:bool)
|
358
|
+
FFI::GDAL::GDAL.GDALGetRasterScale(@c_pointer, success)
|
359
|
+
success.read_bytes(1).to_bool
|
358
360
|
end
|
359
361
|
|
360
362
|
# @param new_scale [Float]
|
@@ -376,14 +378,16 @@ module GDAL
|
|
376
378
|
# returned.
|
377
379
|
#
|
378
380
|
# @return Float
|
379
|
-
# @raise GDAL::Error if the underlying call fails.
|
380
381
|
def offset
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
raise GDAL::Error, "GDALGetRasterOffset failed" unless success.read_bytes(1).to_bool
|
382
|
+
FFI::GDAL::GDAL.GDALGetRasterOffset(@c_pointer, nil)
|
383
|
+
end
|
385
384
|
|
386
|
-
|
385
|
+
# Check if the offset is set.
|
386
|
+
# @return [Boolean]
|
387
|
+
def offset?
|
388
|
+
success = FFI::MemoryPointer.new(:bool)
|
389
|
+
FFI::GDAL::GDAL.GDALGetRasterOffset(@c_pointer, success)
|
390
|
+
success.read_bytes(1).to_bool
|
387
391
|
end
|
388
392
|
|
389
393
|
# Sets the scaling offset. Very few formats support this method.
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GDAL
|
4
|
+
module Utils
|
5
|
+
class DEM
|
6
|
+
# Ruby wrapper for GDALDEMProcessingOptions C API (options for gdaldem utility).
|
7
|
+
#
|
8
|
+
# @see GDAL::Utils::DEM
|
9
|
+
# @see https://gdal.org/programs/gdaldem.html gdaldem utility documentation.
|
10
|
+
class Options
|
11
|
+
# @private
|
12
|
+
class AutoPointer < ::FFI::AutoPointer
|
13
|
+
# @param pointer [FFI::Pointer]
|
14
|
+
def self.release(pointer)
|
15
|
+
return unless pointer && !pointer.null?
|
16
|
+
|
17
|
+
::FFI::GDAL::Utils.GDALDEMProcessingOptionsFree(pointer)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [AutoPointer] C pointer to the GDALDEMProcessingOptions.
|
22
|
+
attr_reader :c_pointer
|
23
|
+
|
24
|
+
# @return [Array<String>] The options.
|
25
|
+
attr_reader :options
|
26
|
+
|
27
|
+
# Create a new instance.
|
28
|
+
#
|
29
|
+
# @see https://gdal.org/programs/gdaldem.html
|
30
|
+
# List of available options could be found in gdaldem utility documentation.
|
31
|
+
#
|
32
|
+
# @example Create a new instance.
|
33
|
+
# options = GDAL::Utils::DEM::Options.new(options: ["-of", "GTiff", "-co", "COMPRESS=DEFLATE"])
|
34
|
+
#
|
35
|
+
# @param options [Array<String>] The options list.
|
36
|
+
def initialize(options: [])
|
37
|
+
@options = options
|
38
|
+
@string_list = ::GDAL::Utils::Helpers::StringList.new(strings: options)
|
39
|
+
@c_pointer = AutoPointer.new(options_pointer)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
attr_reader :string_list
|
45
|
+
|
46
|
+
def options_pointer
|
47
|
+
::FFI::GDAL::Utils.GDALDEMProcessingOptionsNew(string_list.c_pointer, nil)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|