ffi-gdal 1.0.0.beta14 → 1.0.0.beta15

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: 3afcc101b07f1be65e2cce03ed7d925ae1d94a2fb8f36e6b32c9738f97002619
4
- data.tar.gz: caeedcff346cadb107ed4a91970b61a93f61959d6e0f0e69cc96dafc290a8851
3
+ metadata.gz: 27ce3bb913f0b8635ea76cbf5c4630815f1ac669b96d8d4b9106d51e724b88e7
4
+ data.tar.gz: 82959d4f4e6c2ebe35aaed9d37ec87c4520b17a96afd4a4ce7fa0ca72542915e
5
5
  SHA512:
6
- metadata.gz: 55f9c4e293410626d9fda5e624589f24fede9aeb8faff2378ab72c2fe2cd9d7f412eebfa3dddb313719710d950167e894b4a6abe4833997d27483046cf4f65c5
7
- data.tar.gz: b315fe3b339d8d7c1479fd609660cb38e2872e5007500bb896175cd47fbd9322f8ac19f584cd9a8cf55163c5121574670ace63d5d6c6a33e300190a35ad46a04
6
+ metadata.gz: 305f98803b8e7568a43ac5e5a108283b5a3c16d9c87c440207a48227f1d3c833961ecc278994ab70830f976ac3d3f94d80e79059e9c3335964010ada30a02603
7
+ data.tar.gz: eb5b7863342eb29246bf892387ad591364fe98b3bc654dc63854d995a75d22ad4143dddebcacdb880ee6c22d8d0bcb1d8db2f6a230a9f4266b013ab4db8d2581
data/History.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Format for this file derived from [http://keepachangelog.com](http://keepachangelog.com).
4
4
 
5
+ ## 1.0.0.beta15 / 2022-05-12
6
+
7
+ ### Improvements
8
+
9
+ * [DEV-20059] Ensure `GDAL::RasterBandClassifier#equal_count_ranges` has a minimum spacing between breakpoints.
10
+
5
11
  ## 1.0.0.beta14 / 2022-05-06
6
12
 
7
13
  ### Bug Fixes
@@ -2,6 +2,6 @@
2
2
 
3
3
  module FFI
4
4
  module GDAL
5
- VERSION = '1.0.0.beta14'
5
+ VERSION = '1.0.0.beta15'
6
6
  end
7
7
  end
@@ -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 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
@@ -107,6 +107,22 @@ RSpec.describe GDAL::RasterBandClassifier do
107
107
  end
108
108
  end
109
109
 
110
+ describe '#ensure_min_gap' do
111
+ let(:break_values) do
112
+ [29_491.177616329518, 34_999.999999999985, 34_999.99999999999, 35_000.0, 35_000.01582852495, 36_499.9508667737]
113
+ end
114
+
115
+ let(:expected_values) do
116
+ [29_438.61973121367, 34_947.44211488414, 34_982.48598113636, 35_017.52984738857, 35_052.57371364079,
117
+ 36_552.508751889545]
118
+ end
119
+
120
+ it 'ensures breakpoints have a gap between them of 0.5% of the total range' do
121
+ subject.send(:ensure_min_gap, break_values)
122
+ expect(break_values).to eq expected_values
123
+ end
124
+ end
125
+
110
126
  describe '#classify!' do
111
127
  before do
112
128
  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.beta14
4
+ version: 1.0.0.beta15
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-05-09 00:00:00.000000000 Z
11
+ date: 2022-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi