ffi-gdal 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 647e3eeffef3a444a35f32abcc8918172685030f
4
- data.tar.gz: 0b30d6ff25a55d01d8859ea2f679a78ecf04cb5b
3
+ metadata.gz: 5be516e43cc426c9f1fe2f0f0b701b971597d8e6
4
+ data.tar.gz: 53d5d44e1450f3e3f4de809eb025723f1e2945d8
5
5
  SHA512:
6
- metadata.gz: 6f59779cfb110c9e8eae87a8731df55a78437df2d2e495c138cffaa5054231c22ea69373afae68cc6bdb4814261fcd767da3b964300d4f6db152246351642405
7
- data.tar.gz: 62d6225c376ced220a3270f0ca31f3c3b54a4761ed3df3cc5cde46e36c3295493ac7c0da9293975db2f0e5d78357599785e96beb1874670ba3bb08f6c0a40bef
6
+ metadata.gz: 434c97cb29adc90a5f3daee4e5ac47a9560b7cb4959301b342988deb9976d4f579b0bc3a117d596f522e31725ecc2aa5f1519cf2d3bfb338677bee2fe8b447fc
7
+ data.tar.gz: 186963aecb3376291c75694f2628393a36b3c31603bd79897610a0796c7dabcbbb1f5f2e6332bd269c4f5b143200e405ae3a5453f1cb558f0c7a8b1e1d0723e7
data/History.md CHANGED
@@ -1,3 +1,16 @@
1
+ ### 0.0.3 / 2014-09-26
2
+
3
+ * Improvements
4
+ * The `approx_ok` param for `RasterBand#histogram` should default to
5
+ `false` (prefering data exactness over performance).
6
+ * Bug fixes
7
+ * Fixed URL silliness introduced in 0.0.2.
8
+ * `Dataset#*_band` methods should return `nil` if the band with that color
9
+ isn't found.
10
+ * `RasterBand#default_histogram` died if the band didn't have any values.
11
+ * `RasterBand#histogram` wasn't returning totals.
12
+
13
+
1
14
  ### 0.0.2 / 2014-09-26
2
15
 
3
16
  * New things
@@ -27,7 +27,7 @@ module GDAL
27
27
  # @param access_flag [String] 'r' or 'w'.
28
28
  def self.open(path, access_flag)
29
29
  uri = URI.parse(path)
30
- file_path = u.scheme.nil? ? ::File.expand_path(path) : path
30
+ file_path = uri.scheme.nil? ? ::File.expand_path(path) : path
31
31
 
32
32
  pointer = FFI::GDAL.GDALOpen(file_path, ACCESS_FLAGS[access_flag])
33
33
  raise OpenFailure.new(file_path) if pointer.null?
@@ -53,7 +53,7 @@ module GDAL
53
53
  fail RequiredBandNotFound, 'Near-infrared'
54
54
  end
55
55
 
56
- the_array = original.calculate_ndvi(red.to_a, nir.to_a)
56
+ the_array = calculate_ndvi(red.to_a, nir.to_a)
57
57
 
58
58
  ndvi_band = ndvi_dataset.raster_band(1)
59
59
  ndvi_band.write_array(the_array)
@@ -71,7 +71,7 @@ module GDAL
71
71
  fail RequiredBandNotFound, 'Near-infrared'
72
72
  end
73
73
 
74
- the_array = original.calculate_ndvi(green.to_a, nir.to_a)
74
+ the_array = calculate_ndvi(green.to_a, nir.to_a)
75
75
 
76
76
  gndvi_band = gndvi_dataset.raster_band(1)
77
77
  gndvi_band.write_array(the_array)
@@ -114,6 +114,13 @@ module GDAL
114
114
  end
115
115
  end
116
116
 
117
+ # @param red_band_array [NArray]
118
+ # @param nir_band_array [NArray]
119
+ # @return [NArray]
120
+ def self.calculate_ndvi(red_band_array, nir_band_array)
121
+ (nir_band_array - red_band_array) / (nir_band_array + red_band_array)
122
+ end
123
+
117
124
  def self.extract_8bit(source, destination, driver_name)
118
125
  dataset = open(source, 'r')
119
126
  geo_transform = dataset.geo_transform
@@ -313,39 +320,40 @@ module GDAL
313
320
  end
314
321
  end
315
322
 
316
- # @param red_band_array [NArray]
317
- # @param nir_band_array [NArray]
318
- # @return [NArray]
319
- def calculate_ndvi(red_band_array, nir_band_array)
320
- (nir_band_array - red_band_array) / (nir_band_array + red_band_array)
321
- end
322
-
323
323
  # @return [GDAL::RasterBand]
324
324
  def red_band
325
- find_band do |band|
325
+ band = find_band do |band|
326
326
  band.color_interpretation == :GCI_RedBand
327
327
  end
328
+
329
+ band.is_a?(GDAL::RasterBand) ? band : nil
328
330
  end
329
331
 
330
332
  # @return [GDAL::RasterBand]
331
333
  def green_band
332
- find_band do |band|
334
+ band = find_band do |band|
333
335
  band.color_interpretation == :GCI_GreenBand
334
336
  end
337
+
338
+ band.is_a?(GDAL::RasterBand) ? band : nil
335
339
  end
336
340
 
337
341
  # @return [GDAL::RasterBand]
338
342
  def blue_band
339
- find_band do |band|
343
+ band = find_band do |band|
340
344
  band.color_interpretation == :GCI_BlueBand
341
345
  end
346
+
347
+ band.is_a?(GDAL::RasterBand) ? band : nil
342
348
  end
343
349
 
344
350
  # @return [GDAL::RasterBand]
345
351
  def undefined_band
346
- find_band do |band|
352
+ band = find_band do |band|
347
353
  band.color_interpretation == :GCI_Undefined
348
354
  end
355
+
356
+ band.is_a?(GDAL::RasterBand) ? band : nil
349
357
  end
350
358
  end
351
359
  end
@@ -16,10 +16,10 @@ module GDAL
16
16
  # @param raster_band_pointer [FFI::Pointer] Requried if not passing in
17
17
  # +band_id+.
18
18
  def initialize(dataset, band_id: nil, raster_band_pointer: nil)
19
- if dataset.is_a? GDAL::Dataset
20
- @dataset = dataset.c_pointer
19
+ @dataset = if dataset.is_a? GDAL::Dataset
20
+ dataset.c_pointer
21
21
  else
22
- @dataset = dataset
22
+ dataset
23
23
  end
24
24
 
25
25
  @gdal_raster_band = if raster_band_pointer
@@ -303,6 +303,15 @@ module GDAL
303
303
  GDALSetRasterUnitType(@gdal_raster_band, new_unit_type)
304
304
  end
305
305
 
306
+ # @return [GDAL::RasterAttributeTable]
307
+ def default_raster_attribute_table
308
+ rat_pointer = GDALGetDefaultRAT(c_pointer)
309
+ return nil if rat_pointer.null?
310
+
311
+ GDAL::RasterAttributeTable.new(c_pointer,
312
+ raster_attribute_table_pointer: rat_pointer)
313
+ end
314
+
306
315
  # Gets the default raster histogram. Results are returned as a Hash so some
307
316
  # metadata about the histogram can be returned. Example:
308
317
  #
@@ -330,25 +339,26 @@ module GDAL
330
339
  # ]
331
340
  # }
332
341
  #
342
+ # Also, you can pass a block to get status on the processing. Conforms to
343
+ # FFI::GDAL::GDALProgressFunc.
344
+ #
333
345
  # @param force [Boolean] Forces the computation of the histogram. If
334
346
  # +false+ and the default histogram isn't available, this returns nil.
335
347
  # @param block [Proc] No required, but can be used to output progess info
336
348
  # during processing.
349
+ #
337
350
  # @yieldparam completion [Float] The ration completed as a decimal.
338
351
  # @yieldparam message [String] Message string to display.
352
+ #
339
353
  # @return [Hash{minimum => Float, maximum => Float, buckets => Fixnum,
340
- # totals => Array<Fixnum>}]
354
+ # totals => Array<Fixnum>}] Returns +nil+ if no default histogram is
355
+ # available.
341
356
  def default_histogram(force=false, &block)
342
357
  min_pointer = FFI::MemoryPointer.new(:double)
343
358
  max_pointer = FFI::MemoryPointer.new(:double)
344
359
  buckets_pointer = FFI::MemoryPointer.new(:int)
345
360
  histogram_pointer = FFI::MemoryPointer.new(:pointer)
346
-
347
- progress_proc = block || Proc.new do |completion, message, progress_arg|
348
- puts "completion: #{completion * 100}"
349
- puts "message: #{message}"
350
- true
351
- end
361
+ progress_proc = block || nil
352
362
 
353
363
  cpl_err = GDALGetDefaultHistogram(@gdal_raster_band,
354
364
  min_pointer,
@@ -363,28 +373,14 @@ module GDAL
363
373
  min = min_pointer.read_double
364
374
  max = max_pointer.read_double
365
375
  buckets = buckets_pointer.read_int
366
- totals = histogram_pointer.get_pointer(0).read_array_of_int(buckets)
367
376
 
368
- case cpl_err.to_ruby
369
- when :none, :debug
370
- {
371
- minimum: min,
372
- maximum: max,
373
- buckets: buckets,
374
- totals: totals
375
- }
376
- when :warning then return nil
377
- when :failure, :fatal then raise CPLError
377
+ totals = if buckets.zero?
378
+ []
379
+ else
380
+ histogram_pointer.get_pointer(0).read_array_of_int(buckets)
378
381
  end
379
- end
380
382
 
381
- # @return [GDAL::RasterAttributeTable]
382
- def default_raster_attribute_table
383
- rat_pointer = GDALGetDefaultRAT(c_pointer)
384
- return nil if rat_pointer.null?
385
-
386
- GDAL::RasterAttributeTable.new(c_pointer,
387
- raster_attribute_table_pointer: rat_pointer)
383
+ formated_buckets(cpl_err, min, max, buckets, totals)
388
384
  end
389
385
 
390
386
  # Computes a histogram using the given inputs. If you just want the default
@@ -397,18 +393,18 @@ module GDAL
397
393
  # @param approx_ok [Boolean]
398
394
  # @param block [Proc] No required, but can be used to output progess info
399
395
  # during processing.
396
+ #
400
397
  # @yieldparam completion [Float] The ration completed as a decimal.
401
398
  # @yieldparam message [String] Message string to display.
399
+ #
402
400
  # @return [Hash{minimum => Float, maximum => Float, buckets => Fixnum,
403
401
  # totals => Array<Fixnum>}]
402
+ #
403
+ # @see #default_histogram for more info.
404
404
  def histogram(min, max, buckets, include_out_of_range: false,
405
- approx_ok: true, &block)
406
- histogram_pointer = FFI::MemoryPointer.new(:int, buckets)
407
-
408
- progress_proc = block || Proc.new do |completion, message, progress_arg|
409
- puts "progress: #{completion * 100}"
410
- true
411
- end
405
+ approx_ok: false, &block)
406
+ histogram_pointer = FFI::MemoryPointer.new(:pointer, buckets)
407
+ progress_proc = block || nil
412
408
 
413
409
  cpl_err = GDALGetRasterHistogram(@gdal_raster_band,
414
410
  min.to_f,
@@ -418,21 +414,15 @@ module GDAL
418
414
  include_out_of_range,
419
415
  approx_ok,
420
416
  progress_proc,
421
- 'doing things'
422
- )
423
- totals = histogram_pointer.read_array_of_int(0)
417
+ 'doing things')
424
418
 
425
- case cpl_err.to_ruby
426
- when :none
427
- {
428
- minimum: min,
429
- maximum: max,
430
- buckets: buckets,
431
- totals: totals
432
- }
433
- when :warning then return nil
434
- when :failure then raise CPLError
419
+ totals = if buckets.zero?
420
+ []
421
+ else
422
+ histogram_pointer.read_array_of_int(buckets)
435
423
  end
424
+
425
+ formated_buckets(cpl_err, min, max, buckets, totals)
436
426
  end
437
427
 
438
428
  # TODO: Something about the pointer allocation smells here...
@@ -567,5 +557,26 @@ module GDAL
567
557
 
568
558
  NArray.to_na(lines)
569
559
  end
560
+
561
+ #---------------------------------------------------------------------------
562
+ # Privates
563
+ #---------------------------------------------------------------------------
564
+
565
+ private
566
+
567
+ def formated_buckets(cpl_err, min, max, buckets, totals)
568
+ case cpl_err.to_ruby
569
+ when :none
570
+ {
571
+ minimum: min,
572
+ maximum: max,
573
+ buckets: buckets,
574
+ totals: totals
575
+ }
576
+ when :warning then return nil
577
+ when :failure then raise CPLError
578
+ end
579
+ end
580
+
570
581
  end
571
582
  end
@@ -1,5 +1,5 @@
1
1
  module FFI
2
2
  module GDAL
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -4,329 +4,335 @@ require 'ffi-gdal'
4
4
 
5
5
 
6
6
  TIF_FILES.each do |file|
7
- dataset = GDAL::Dataset.open(file, 'r')
7
+ dataset = GDAL::Dataset.open(file, 'r')
8
+ dataset.each_band do |band_under_test|
8
9
 
9
- describe 'Raster Band Info' do
10
- after :all do
11
- dataset.close
12
- end
10
+ describe "Raster Band Info" do
11
+ after :suite do
12
+ dataset.close
13
+ end
13
14
 
14
- # TODO: Test against each raster band
15
- subject do
16
- GDAL::RasterBand.new(dataset.c_pointer, band_id: 1)
17
- end
15
+ # TODO: Test against each raster band
16
+ subject do
17
+ GDAL::RasterBand.new(dataset.c_pointer, raster_band_pointer: band_under_test.c_pointer)
18
+ end
18
19
 
19
- it_behaves_like 'a major object'
20
+ it_behaves_like 'a major object'
20
21
 
21
- describe '#x_size' do
22
- it 'is a non-zero Integer' do
23
- expect(subject.x_size).to be_a Fixnum
24
- expect(subject.x_size).to be > 0
22
+ describe '#x_size' do
23
+ it 'is a non-zero Integer' do
24
+ expect(subject.x_size).to be_a Fixnum
25
+ expect(subject.x_size).to be > 0
26
+ end
25
27
  end
26
- end
27
28
 
28
- describe '#y_size' do
29
- it 'is a non-zero Integer' do
30
- expect(subject.y_size).to be_a Fixnum
31
- expect(subject.y_size).to be > 0
29
+ describe '#y_size' do
30
+ it 'is a non-zero Integer' do
31
+ expect(subject.y_size).to be_a Fixnum
32
+ expect(subject.y_size).to be > 0
33
+ end
32
34
  end
33
- end
34
35
 
35
- describe '#access_flag' do
36
- specify { expect(subject.access_flag).to eq :GA_ReadOnly }
37
- end
36
+ describe '#access_flag' do
37
+ specify { expect(subject.access_flag).to eq :GA_ReadOnly }
38
+ end
38
39
 
39
- describe '#band_number' do
40
- it 'is a non-zero Integer' do
41
- expect(subject.band_number).to be_a Fixnum
42
- expect(subject.band_number).to be > 0
40
+ describe '#band_number' do
41
+ it 'is a non-zero Integer' do
42
+ expect(subject.band_number).to be_a Fixnum
43
+ expect(subject.band_number).to be > 0
44
+ end
43
45
  end
44
- end
45
46
 
46
- describe '#color_interpretation' do
47
- it 'is a Symbol; one of FFI::GDAL::GDALColorInterp' do
48
- expect(subject.color_interpretation).to be_a Symbol
49
- expect(FFI::GDAL::GDALColorInterp.symbols).to include subject.color_interpretation
47
+ describe '#color_interpretation' do
48
+ it 'is a Symbol; one of FFI::GDAL::GDALColorInterp' do
49
+ expect(subject.color_interpretation).to be_a Symbol
50
+ expect(FFI::GDAL::GDALColorInterp.symbols).to include subject.color_interpretation
51
+ end
50
52
  end
51
- end
52
53
 
53
- describe '#color_table' do
54
- it 'is a GDAL::ColorTable' do
55
- if subject.color_table
56
- expect(subject.color_table).to be_a GDAL::ColorTable
54
+ describe '#color_table' do
55
+ it 'is a GDAL::ColorTable' do
56
+ if subject.color_table
57
+ expect(subject.color_table).to be_a GDAL::ColorTable
58
+ end
57
59
  end
58
60
  end
59
- end
60
61
 
61
- describe '#data_type' do
62
- it 'is a Symbol; one of FFI::GDAL::GDALDataType' do
63
- expect(subject.data_type).to be_a Symbol
64
- expect(FFI::GDAL::GDALDataType.symbols).to include subject.data_type
62
+ describe '#data_type' do
63
+ it 'is a Symbol; one of FFI::GDAL::GDALDataType' do
64
+ expect(subject.data_type).to be_a Symbol
65
+ expect(FFI::GDAL::GDALDataType.symbols).to include subject.data_type
66
+ end
65
67
  end
66
- end
67
68
 
68
- describe '#block_size' do
69
- it 'is a Hash with x and y keys that are >= 1' do
70
- expect(subject.block_size).to be_a Hash
71
- expect(subject.block_size[:x]).to be >= 1
72
- expect(subject.block_size[:y]).to be >= 1
69
+ describe '#block_size' do
70
+ it 'is a Hash with x and y keys that are >= 1' do
71
+ expect(subject.block_size).to be_a Hash
72
+ expect(subject.block_size[:x]).to be >= 1
73
+ expect(subject.block_size[:y]).to be >= 1
74
+ end
73
75
  end
74
- end
75
76
 
76
- describe '#category_names' do
77
- it 'is an Array of Strings' do
78
- expect(subject.category_names).to be_an Array
77
+ describe '#category_names' do
78
+ it 'is an Array of Strings' do
79
+ expect(subject.category_names).to be_an Array
79
80
 
80
- subject.category_names.each do |category_name|
81
- expect(category_name).to be_a String
82
- expect(category_name).to_not be_empty
81
+ subject.category_names.each do |category_name|
82
+ expect(category_name).to be_a String
83
+ expect(category_name).to_not be_empty
84
+ end
83
85
  end
84
86
  end
85
- end
86
87
 
87
- describe '#category_names=' do
88
- around do |example|
89
- category_names = subject.category_names
90
- example.run
91
- subject.category_names = category_names
92
- end
88
+ describe '#category_names=' do
89
+ around do |example|
90
+ category_names = subject.category_names
91
+ example.run
92
+ subject.category_names = category_names
93
+ end
93
94
 
94
- it 'sets the category names' do
95
- expect(subject.category_names).to be_empty
95
+ it 'sets the category names' do
96
+ expect(subject.category_names).to be_empty
96
97
 
97
- subject.category_names = %w[one two three]
98
+ subject.category_names = %w[one two three]
98
99
 
99
- expect(subject.category_names).to eq %w[one two three]
100
+ expect(subject.category_names).to eq %w[one two three]
101
+ end
100
102
  end
101
- end
102
103
 
103
- describe '#no_data_value' do
104
- it 'is a Hash with :value and :is_associated keys' do
105
- expect(subject.no_data_value).to be_an Hash
104
+ describe '#no_data_value' do
105
+ it 'is a Hash with :value and :is_associated keys' do
106
+ expect(subject.no_data_value).to be_an Hash
106
107
 
107
- expect(subject.no_data_value[:value]).to be_a Float
108
- expect(subject.no_data_value[:is_associated]).to_not be_nil
108
+ expect(subject.no_data_value[:value]).to be_a Float
109
+ expect(subject.no_data_value[:is_associated]).to_not be_nil
110
+ end
109
111
  end
110
- end
111
112
 
112
- describe '#overview_count' do
113
- it 'is a Fixnum' do
114
- expect(subject.overview_count).to be_a Fixnum
113
+ describe '#overview_count' do
114
+ it 'is a Fixnum' do
115
+ expect(subject.overview_count).to be_a Fixnum
116
+ end
115
117
  end
116
- end
117
118
 
118
- describe '#arbitrary_overviews?' do
119
- it 'is true or false' do
120
- expect([true, false]).to include subject.arbitrary_overviews?
119
+ describe '#arbitrary_overviews?' do
120
+ it 'is true or false' do
121
+ expect([true, false]).to include subject.arbitrary_overviews?
122
+ end
121
123
  end
122
- end
123
124
 
124
- describe '#overview' do
125
- it 'returns a GDAL::RasterBand if the overview exists' do
126
- overview = subject.overview(0)
127
- expect(overview).to be_a GDAL::RasterBand if overview
125
+ describe '#overview' do
126
+ it 'returns a GDAL::RasterBand if the overview exists' do
127
+ overview = subject.overview(0)
128
+ expect(overview).to be_a GDAL::RasterBand if overview
129
+ end
128
130
  end
129
- end
130
131
 
131
- describe '#raster_sample_overview' do
132
- it 'returns a GDAL::RasterBand if the overview exists' do
133
- overview = subject.raster_sample_overview
134
- expect(overview).to be_a GDAL::RasterBand
132
+ describe '#raster_sample_overview' do
133
+ it 'returns a GDAL::RasterBand if the overview exists' do
134
+ overview = subject.raster_sample_overview
135
+ expect(overview).to be_a GDAL::RasterBand
136
+ end
135
137
  end
136
- end
137
138
 
138
- describe '#mask_band' do
139
- it 'returns a GDAL::RasterBand if the mask_band exists' do
140
- overview = subject.mask_band
141
- expect(overview).to be_a GDAL::RasterBand
139
+ describe '#mask_band' do
140
+ it 'returns a GDAL::RasterBand if the mask_band exists' do
141
+ overview = subject.mask_band
142
+ expect(overview).to be_a GDAL::RasterBand
143
+ end
142
144
  end
143
- end
144
145
 
145
- describe '#mask_flags' do
146
- it 'returns an Array of Symbols' do
147
- expect(subject.mask_flags).to eq [:GMF_ALL_VALID]
146
+ describe '#mask_flags' do
147
+ it 'returns an Array of Symbols' do
148
+ expect(subject.mask_flags).to eq [:GMF_ALL_VALID]
149
+ end
148
150
  end
149
- end
150
151
 
151
- describe '#statistics' do
152
- it 'returns a Hash with populated values' do
153
- expect(subject.statistics).to be_a Hash
154
- expect(%i[minimum maximum mean standard_deviation]).
155
- to eq subject.statistics.keys
156
- end
152
+ describe '#statistics' do
153
+ it 'returns a Hash with populated values' do
154
+ expect(subject.statistics).to be_a Hash
155
+ expect(%i[minimum maximum mean standard_deviation]).
156
+ to eq subject.statistics.keys
157
+ end
157
158
 
158
- it 'has a :minimum that ranges between 0.0/-32768.0 and 255.0' do
159
- min = subject.statistics[:minimum]
160
- unless min == -32768.0
161
- expect(subject.statistics[:minimum]).to((be >= 0.0) || (eq -32768.0))
162
- expect(subject.statistics[:minimum]).to be <= 255.0
159
+ it 'has a :minimum that ranges between 0.0/-32768.0 and 255.0' do
160
+ min = subject.statistics[:minimum]
161
+ unless min == -32768.0
162
+ expect(subject.statistics[:minimum]).to((be >= 0.0) || (eq -32768.0))
163
+ expect(subject.statistics[:minimum]).to be <= 255.0
164
+ end
163
165
  end
164
166
  end
165
- end
166
167
 
167
- describe '#scale' do
168
- it 'returns a Hash with populated values' do
169
- expect(subject.statistics).to be_a Hash
170
- expect(%i[value is_meaningful]).to eq subject.scale.keys
171
- end
168
+ describe '#scale' do
169
+ it 'returns a Hash with populated values' do
170
+ expect(subject.statistics).to be_a Hash
171
+ expect(%i[value is_meaningful]).to eq subject.scale.keys
172
+ end
172
173
 
173
- it 'has a :value that is a Float' do
174
- expect(subject.scale[:value]).to be_a Float
175
- end
174
+ it 'has a :value that is a Float' do
175
+ expect(subject.scale[:value]).to be_a Float
176
+ end
176
177
 
177
- it 'has a :is_meaningful that is false (since the examples are geotiffs)' do
178
- expect(subject.scale[:is_meaningful]).to eq false
178
+ it 'has a :is_meaningful that is false (since the examples are geotiffs)' do
179
+ expect(subject.scale[:is_meaningful]).to eq false
180
+ end
179
181
  end
180
- end
181
182
 
182
- describe '#scale=' do
183
- around do |example|
184
- scale = subject.scale[:value]
185
- example.run
186
- subject.scale = scale
187
- end
183
+ describe '#scale=' do
184
+ around do |example|
185
+ scale = subject.scale[:value]
186
+ example.run
187
+ subject.scale = scale
188
+ end
188
189
 
189
- it 'does nothing (because the file formats dont support it)' do
190
- subject.scale = 0.1
191
- expect(subject.scale[:value]).to eq 0.1
190
+ it 'does nothing (because the file formats dont support it)' do
191
+ subject.scale = 0.1
192
+ expect(subject.scale[:value]).to eq 0.1
193
+ end
192
194
  end
193
- end
194
195
 
195
- describe '#offset' do
196
- it 'returns a Hash with populated values' do
197
- expect(subject.offset).to be_a Hash
198
- expect(%i[value is_meaningful]).to eq subject.offset.keys
199
- end
196
+ describe '#offset' do
197
+ it 'returns a Hash with populated values' do
198
+ expect(subject.offset).to be_a Hash
199
+ expect(%i[value is_meaningful]).to eq subject.offset.keys
200
+ end
200
201
 
201
- it 'has a :value that is a Float' do
202
- expect(subject.offset[:value]).to be_a Float
203
- end
202
+ it 'has a :value that is a Float' do
203
+ expect(subject.offset[:value]).to be_a Float
204
+ end
204
205
 
205
- it 'has a :is_meaningful that is false (since the examples are geotiffs)' do
206
- expect(subject.offset[:is_meaningful]).to eq false
206
+ it 'has a :is_meaningful that is false (since the examples are geotiffs)' do
207
+ expect(subject.offset[:is_meaningful]).to eq false
208
+ end
207
209
  end
208
- end
209
210
 
210
- describe '#offset=' do
211
- around do |example|
212
- offset = subject.offset[:value]
213
- example.run
214
- subject.offset = offset
215
- end
211
+ describe '#offset=' do
212
+ around do |example|
213
+ offset = subject.offset[:value]
214
+ example.run
215
+ subject.offset = offset
216
+ end
216
217
 
217
- it 'does nothing (because the file formats dont support it)' do
218
- subject.offset = 0.1
219
- expect(subject.offset[:value]).to eq 0.1
218
+ it 'does nothing (because the file formats dont support it)' do
219
+ subject.offset = 0.1
220
+ expect(subject.offset[:value]).to eq 0.1
221
+ end
220
222
  end
221
- end
222
223
 
223
- describe '#unit_type' do
224
- it 'returns a String' do
225
- expect(subject.unit_type).to be_a String
224
+ describe '#unit_type' do
225
+ it 'returns a String' do
226
+ expect(subject.unit_type).to be_a String
227
+ end
226
228
  end
227
- end
228
229
 
229
- describe '#unit_type=' do
230
- around do |example|
231
- unit_type = subject.unit_type
232
- example.run
233
- subject.unit_type = unit_type
234
- end
230
+ describe '#unit_type=' do
231
+ around do |example|
232
+ unit_type = subject.unit_type
233
+ example.run
234
+ subject.unit_type = unit_type
235
+ end
235
236
 
236
- it 'does nothing (because the file formats dont support it)' do
237
- subject.unit_type = 'ft'
238
- expect(subject.unit_type).to eq 'ft'
237
+ it 'does nothing (because the file formats dont support it)' do
238
+ subject.unit_type = 'ft'
239
+ expect(subject.unit_type).to eq 'ft'
240
+ end
239
241
  end
240
- end
241
242
 
242
- describe '#default_histogram' do
243
- let!(:histogram) { subject.default_histogram }
243
+ describe '#default_histogram' do
244
+ let!(:histogram) { subject.default_histogram }
244
245
 
245
- it 'returns a Hash with :mininum, :maximum, :buckets, and :totals' do
246
- expect(histogram).to be_a Hash
247
- expect(histogram.keys).to eq %i[minimum maximum buckets totals]
248
- end
246
+ it 'returns a Hash with :mininum, :maximum, :buckets, and :totals' do
247
+ if histogram
248
+ expect(histogram).to be_a Hash
249
+ expect(histogram.keys).to eq %i[minimum maximum buckets totals]
250
+ end
251
+ end
249
252
 
250
- it 'has :mimimum as a Float' do
251
- expect(histogram[:minimum]).to be_a Float
252
- end
253
+ it 'has :mimimum as a Float' do
254
+ expect(histogram[:minimum]).to be_a Float if histogram
255
+ end
253
256
 
254
- it 'has :maximum as a Float' do
255
- expect(histogram[:maximum]).to be_a Float
256
- end
257
+ it 'has :maximum as a Float' do
258
+ expect(histogram[:maximum]).to be_a Float if histogram
259
+ end
257
260
 
258
- it 'has :buckets as a Fixnum' do
259
- expect(histogram[:buckets]).to be_a Fixnum
260
- end
261
+ it 'has :buckets as a Fixnum' do
262
+ expect(histogram[:buckets]).to be_a Fixnum if histogram
263
+ end
261
264
 
262
- it 'has :totals as an Array of 256 Fixnums' do
263
- expect(histogram[:totals]).to be_an Array
264
- expect(histogram[:totals].size).to eq 256
265
- expect(histogram[:totals].all? { |t| t.class == Fixnum}).to eq true
265
+ it 'has :totals as an Array of 256 Fixnums' do
266
+ if histogram
267
+ expect(histogram[:totals]).to be_an Array
268
+ expect(histogram[:totals].size).to eq 256
269
+ expect(histogram[:totals].all? { |t| t.class == Fixnum}).to eq true
270
+ end
271
+ end
266
272
  end
267
- end
268
273
 
269
- describe '#default_raster_attribute_table' do
270
- it 'returns a GDAL::RasterAttributeTable' do
271
- rat = subject.default_raster_attribute_table
274
+ describe '#default_raster_attribute_table' do
275
+ it 'returns a GDAL::RasterAttributeTable' do
276
+ rat = subject.default_raster_attribute_table
272
277
 
273
- if rat
274
- expect(rat).to be_a GDAL::RasterAttributeTable
278
+ if rat
279
+ expect(rat).to be_a GDAL::RasterAttributeTable
280
+ end
275
281
  end
276
282
  end
277
- end
278
283
 
279
- describe '#compute_min_max' do
280
- it 'returns a 2-element Array of Floats' do
281
- expect(subject.compute_min_max).to be_a Array
282
- expect(subject.compute_min_max.size).to eq 2
283
- expect(subject.compute_min_max.first).to be_a Float
284
- expect(subject.compute_min_max.last).to be_a Float
285
- end
284
+ describe '#compute_min_max' do
285
+ it 'returns a 2-element Array of Floats' do
286
+ expect(subject.compute_min_max).to be_a Array
287
+ expect(subject.compute_min_max.size).to eq 2
288
+ expect(subject.compute_min_max.first).to be_a Float
289
+ expect(subject.compute_min_max.last).to be_a Float
290
+ end
286
291
 
287
- it 'has a min that is < its max' do
288
- min, max = subject.compute_min_max
289
- expect(min).to be < max
290
- end
292
+ it 'has a min that is < its max' do
293
+ min, max = subject.compute_min_max
294
+ expect(min).to be < max
295
+ end
291
296
 
292
- it 'has a min that == statistics[:minimum]' do
293
- min, _ = subject.compute_min_max
294
- expect(min).to eq subject.statistics[:minimum]
295
- end
297
+ it 'has a min that == statistics[:minimum]' do
298
+ min, _ = subject.compute_min_max
299
+ expect(min).to eq subject.statistics[:minimum]
300
+ end
296
301
 
297
- it 'has a min that == minimum_value[:value]' do
298
- min, _ = subject.compute_min_max
299
- expect(min).to eq subject.minimum_value[:value]
302
+ it 'has a min that == minimum_value[:value]' do
303
+ min, _ = subject.compute_min_max
304
+ expect(min).to eq subject.minimum_value[:value]
305
+ end
300
306
  end
301
- end
302
307
 
303
- describe '#minimum_value' do
304
- it 'returns a Hash with populated values' do
305
- expect(subject.minimum_value).to be_a Hash
306
- expect(%i[value is_tight]).to eq subject.minimum_value.keys
307
- end
308
+ describe '#minimum_value' do
309
+ it 'returns a Hash with populated values' do
310
+ expect(subject.minimum_value).to be_a Hash
311
+ expect(%i[value is_tight]).to eq subject.minimum_value.keys
312
+ end
308
313
 
309
- it 'has a :value that is a Float' do
310
- expect(subject.minimum_value[:value]).to be_a Float
311
- end
314
+ it 'has a :value that is a Float' do
315
+ expect(subject.minimum_value[:value]).to be_a Float
316
+ end
312
317
 
313
- it 'has a :is_tight that is nil (since the examples are geotiffs)' do
314
- #expect(subject.minimum_value[:is_tight]).to eq nil
318
+ it 'has a :is_tight that is nil (since the examples are geotiffs)' do
319
+ #expect(subject.minimum_value[:is_tight]).to eq nil
320
+ end
315
321
  end
316
- end
317
322
 
318
- describe '#maximum_value' do
319
- it 'returns a Hash with populated values' do
320
- expect(subject.maximum_value).to be_a Hash
321
- expect(%i[value is_tight]).to eq subject.maximum_value.keys
322
- end
323
+ describe '#maximum_value' do
324
+ it 'returns a Hash with populated values' do
325
+ expect(subject.maximum_value).to be_a Hash
326
+ expect(%i[value is_tight]).to eq subject.maximum_value.keys
327
+ end
323
328
 
324
- it 'has a :value that is a Float' do
325
- expect(subject.maximum_value[:value]).to be_a Float
326
- end
329
+ it 'has a :value that is a Float' do
330
+ expect(subject.maximum_value[:value]).to be_a Float
331
+ end
327
332
 
328
- it 'has a :is_tight that is nil (since the examples are geotiffs)' do
329
- #expect(subject.maximum_value[:is_tight]).to eq nil
333
+ it 'has a :is_tight that is nil (since the examples are geotiffs)' do
334
+ #expect(subject.maximum_value[:is_tight]).to eq nil
335
+ end
330
336
  end
331
337
  end
332
338
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-gdal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Loveless