ffi-gdal 1.0.0.beta13 → 1.0.0.beta16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a7da9b47c629fe9a1b116f1c12175858e4c259d01b1f1b87027e3060656a06b
4
- data.tar.gz: 13275d69e24bda923196ac121ddc55ea61fa61351c7ea5245b91991a2266d5a3
3
+ metadata.gz: 001e1f9a99984fee7d2578b7afdb7c04508d113895d2892b457685a03290efed
4
+ data.tar.gz: 896c51e4d85abdce2f743de84b0fcd199f7ac48339fefb99dea0220812073296
5
5
  SHA512:
6
- metadata.gz: a46c6f0b1c318ff9ce7c0cb44d6f863cd8903194271bf9e5b93c0581b2dbd5129235829d97e64f725a561741933eadeb959d421fff09f562508097311afe0379
7
- data.tar.gz: a3efb551a19524168ffc9540854e3d99860018a062ed026621de787875576a1f6df74f3ca5f3eb0f34c31571be21b087a1262d16fbcd2e7b692da34671eefb2a
6
+ metadata.gz: 2e5d07dfc1ced24a5a6491d57cc32ab177de432f54477be7cda2d051633c124f07a83bec92f17551d2ca88ce113bf6589a187b3cf2dad0db70eb761a23643063
7
+ data.tar.gz: d3e425012f6ad7d119e8a3d307ece8f5b168c850037974264e01c50939105677d161ea1b430ad923ae1e85955f7d2d461ea46e0635b658535aaf3b84cf6374e5
data/History.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  Format for this file derived from [http://keepachangelog.com](http://keepachangelog.com).
4
4
 
5
+ ## 1.0.0.beta16 / 2022-06-09
6
+
7
+ ### Bug Fixes
8
+
9
+ * [DEV-34269] Ensure `GDAL::RasterBandClassifier#equal_count_ranges` returns a range when only one is requested.
10
+
11
+ ## 1.0.0.beta15 / 2022-05-12
12
+
13
+ ### Improvements
14
+
15
+ * [DEV-20059] Ensure `GDAL::RasterBandClassifier#equal_count_ranges` has a minimum spacing between breakpoints.
16
+
17
+ ## 1.0.0.beta14 / 2022-05-06
18
+
19
+ ### Bug Fixes
20
+
21
+ * [DEV-34133] Don't URI.parse path in `GDAL::Dataset#initialize` and `OGR::DataSource#initialize`.
22
+
5
23
  ## 1.0.0.beta13 / 2022-04-20
6
24
 
7
25
  ### Bug Fixes
@@ -2,6 +2,6 @@
2
2
 
3
3
  module FFI
4
4
  module GDAL
5
- VERSION = '1.0.0.beta13'
5
+ VERSION = '1.0.0.beta16'
6
6
  end
7
7
  end
data/lib/gdal/dataset.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'uri'
4
3
  require_relative '../gdal'
5
4
  require_relative '../ogr'
6
5
  require_relative 'major_object'
@@ -60,17 +59,10 @@ module GDAL
60
59
  def initialize(path_or_pointer, access_flag, shared_open = true)
61
60
  @c_pointer =
62
61
  if path_or_pointer.is_a? String
63
- file_path = begin
64
- uri = URI.parse(path_or_pointer)
65
- uri.scheme.nil? ? ::File.expand_path(path_or_pointer) : path_or_pointer
66
- rescue URI::InvalidURIError
67
- path_or_pointer
68
- end
69
-
70
62
  if shared_open
71
- FFI::GDAL::GDAL.GDALOpenShared(file_path, ACCESS_FLAGS[access_flag])
63
+ FFI::GDAL::GDAL.GDALOpenShared(path_or_pointer, ACCESS_FLAGS[access_flag])
72
64
  else
73
- FFI::GDAL::GDAL.GDALOpen(file_path, ACCESS_FLAGS[access_flag])
65
+ FFI::GDAL::GDAL.GDALOpen(path_or_pointer, ACCESS_FLAGS[access_flag])
74
66
  end
75
67
  else
76
68
  path_or_pointer
@@ -19,6 +19,8 @@ module GDAL
19
19
  #
20
20
  # @param ranges [Array<Hash{range => Range, map_to => Number}>]
21
21
  class RasterBandClassifier
22
+ MIN_GAP_PERCENTAGE = 0.005
23
+
22
24
  include GDAL::Logger
23
25
 
24
26
  attr_reader :ranges
@@ -64,14 +66,16 @@ module GDAL
64
66
  log "Max pixel value: #{sorted_and_masked_pixels.max}"
65
67
  log "Range size: #{range_size}"
66
68
 
67
- break_values = Array.new(range_count) { |i| sorted_and_masked_pixels[range_size * i] }.uniq
69
+ break_values = [*Array.new(range_count) { |i| sorted_and_masked_pixels[range_size * i] }.uniq,
70
+ sorted_and_masked_pixels.max]
71
+ ensure_min_gap(break_values)
68
72
  log "Break values: #{break_values}"
69
73
 
70
- return if break_values.uniq.size != range_count
74
+ return if range_count != 1 && break_values.uniq.size - 1 != range_count
71
75
 
72
76
  breakpoint_calculator = lambda do |range_number|
73
77
  min = break_values[range_number]
74
- max = break_values[range_number + 1] || sorted_and_masked_pixels.max
78
+ max = break_values[range_number + 1]
75
79
 
76
80
  range_for_type(min, max)
77
81
  end
@@ -131,6 +135,23 @@ module GDAL
131
135
  end
132
136
  end
133
137
 
138
+ # @param break_values [Array<Numeric>]
139
+ def ensure_min_gap(break_values)
140
+ min_gap = (break_values.last - break_values.first) * MIN_GAP_PERCENTAGE
141
+
142
+ (1...break_values.size).each do |index|
143
+ left, right = break_values[index - 1, 2]
144
+ diff = right - left
145
+ adjustment = (min_gap / 2) - (diff / 2)
146
+
147
+ next unless diff < min_gap
148
+
149
+ log "Index #{index} diff #{diff} smaller than min_gap #{min_gap}, adjusting by #{adjustment}"
150
+ break_values.fill(0...index) { |x| break_values[x] - adjustment }
151
+ break_values.fill(index..) { |x| break_values[x] + adjustment }
152
+ end
153
+ end
154
+
134
155
  def range_for_type(min, max)
135
156
  min.to_data_type(@raster_band.data_type)..max.to_data_type(@raster_band.data_type)
136
157
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'uri'
4
3
  require 'json'
5
4
  require_relative '../gdal'
6
5
  require_relative '../ogr'
@@ -41,14 +40,12 @@ module OGR
41
40
  def initialize(path_or_pointer, access_flag)
42
41
  @c_pointer =
43
42
  if path_or_pointer.is_a?(String)
44
- uri = URI.parse(path_or_pointer)
45
- file_path = uri.scheme.nil? ? ::File.expand_path(path_or_pointer) : path_or_pointer
46
- FFI::OGR::API.OGROpen(file_path, OGR._boolean_access_flag(access_flag), nil)
43
+ FFI::OGR::API.OGROpen(path_or_pointer, OGR._boolean_access_flag(access_flag), nil)
47
44
  else
48
45
  path_or_pointer
49
46
  end
50
47
 
51
- raise OGR::OpenFailure, file_path if @c_pointer.null?
48
+ raise OGR::OpenFailure, path_or_pointer if @c_pointer.null?
52
49
 
53
50
  @layers = []
54
51
  end
@@ -97,6 +97,15 @@ RSpec.describe GDAL::RasterBandClassifier do
97
97
  it { is_expected.to be_nil }
98
98
  end
99
99
 
100
+ context 'all same value' do
101
+ let(:band_narray) { Numo::Int8.new(3, 5).fill(1) }
102
+ before { allow(raster_band).to receive(:to_nna).and_return(band_narray) }
103
+
104
+ it 'returns a single range when 1 is requested' do
105
+ expect(subject.equal_count_ranges(1)).to eq [{ range: 1..1, map_to: 1 }]
106
+ end
107
+ end
108
+
100
109
  context 'all nodata pixels' do
101
110
  let(:band_narray) { Numo::Int8.new(3, 5).fill(0) }
102
111
  before { allow(raster_band).to receive(:to_nna).and_return(band_narray) }
@@ -107,6 +116,22 @@ RSpec.describe GDAL::RasterBandClassifier do
107
116
  end
108
117
  end
109
118
 
119
+ describe '#ensure_min_gap' do
120
+ let(:break_values) do
121
+ [29_491.177616329518, 34_999.999999999985, 34_999.99999999999, 35_000.0, 35_000.01582852495, 36_499.9508667737]
122
+ end
123
+
124
+ let(:expected_values) do
125
+ [29_438.61973121367, 34_947.44211488414, 34_982.48598113636, 35_017.52984738857, 35_052.57371364079,
126
+ 36_552.508751889545]
127
+ end
128
+
129
+ it 'ensures breakpoints have a gap between them of 0.5% of the total range' do
130
+ subject.send(:ensure_min_gap, break_values)
131
+ expect(break_values).to eq expected_values
132
+ end
133
+ end
134
+
110
135
  describe '#classify!' do
111
136
  before do
112
137
  ranges = subject.equal_count_ranges(10)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-gdal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta13
4
+ version: 1.0.0.beta16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Loveless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-25 00:00:00.000000000 Z
11
+ date: 2022-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -543,7 +543,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
543
543
  - !ruby/object:Gem::Version
544
544
  version: 1.3.1
545
545
  requirements: []
546
- rubygems_version: 3.0.9
546
+ rubygems_version: 3.3.7
547
547
  signing_key:
548
548
  specification_version: 4
549
549
  summary: FFI wrapper for GDAL/OGR.