ffi-gdal 1.0.0.beta1 → 1.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ module FFI
8
8
  old_attach_function(*args)
9
9
  rescue FFI::NotFoundError
10
10
  @unsupported_gdal_functions ||= []
11
- warn "Function '#{args.first}' is not available in this build of GDAL/OGR v#{FFI::GDAL.GDALVersionInfo('RELEASE_NAME')}"
11
+ warn "ffi-gdal warning: function '#{args.first}' is not available in this build of GDAL/OGR (v#{FFI::GDAL.GDALVersionInfo('RELEASE_NAME')})"
12
12
  @unsupported_gdal_functions << args.first
13
13
  end
14
14
 
@@ -14,9 +14,9 @@ module FFI
14
14
  attach_function :GDALGridInverseDistanceToAPower,
15
15
  %i[pointer GUInt32 pointer pointer pointer double double pointer pointer],
16
16
  CPLErr
17
- # attach_function :GDALGridInverseDistanceToAPointerNoSearch,
18
- # %i[pointer GUInt32 pointer pointer pointer double double pointer pointer],
19
- # CPLErr
17
+ attach_function :GDALGridInverseDistanceToAPointerNoSearch,
18
+ %i[pointer GUInt32 pointer pointer pointer double double pointer pointer],
19
+ CPLErr
20
20
 
21
21
  attach_function :GDALGridMovingAverage,
22
22
  %i[pointer GUInt32 pointer pointer pointer double double pointer pointer],
@@ -1,5 +1,5 @@
1
1
  module FFI
2
2
  module GDAL
3
- VERSION = '1.0.0.beta1'
3
+ VERSION = '1.0.0.beta3'
4
4
  end
5
5
  end
@@ -267,9 +267,9 @@ module FFI
267
267
  attach_function :OGR_FD_DeleteFieldDefn,
268
268
  %i[OGRFeatureDefnH int],
269
269
  OGRErr
270
- # attach_function :OGR_FD_ReorderFieldDefns,
271
- # %i[OGRFeatureDefnH pointer],
272
- # OGRErr
270
+ attach_function :OGR_FD_ReorderFieldDefns,
271
+ %i[OGRFeatureDefnH pointer],
272
+ OGRErr
273
273
  attach_function :OGR_FD_GetGeomType, %i[OGRFeatureDefnH], OGRwkbGeometryType
274
274
  attach_function :OGR_FD_SetGeomType,
275
275
  [:OGRFeatureDefnH, OGRwkbGeometryType],
@@ -71,7 +71,7 @@ module GDAL
71
71
 
72
72
  flag = FFI::GDAL.GDALGetAccess(@dataset_pointer)
73
73
 
74
- FFI::GDAL.GDALAccess[flag]
74
+ FFI::GDAL::GDALAccess[flag]
75
75
  end
76
76
 
77
77
  # @return [GDAL::Driver] The driver to be used for working with this
@@ -148,11 +148,12 @@ module GDAL
148
148
  raster_band(raster_count)
149
149
  end
150
150
 
151
- # Adds a mask band to the dataset
151
+ # Adds a mask band to the dataset.
152
152
  #
153
+ # @param flags [Fixnum] Any of of the GDAL::RasterBand flags.
153
154
  # @return [Boolean]
154
- def create_mask_band
155
- cpl_err = FFI::GDAL.GDALCreateDatasetMaskBand(@dataset_pointer, 0)
155
+ def create_mask_band(flags)
156
+ cpl_err = FFI::GDAL.GDALCreateDatasetMaskBand(@dataset_pointer, flags)
156
157
 
157
158
  cpl_err.to_bool
158
159
  end
@@ -472,13 +472,13 @@ module GDAL
472
472
  # @param ndvi [NArray]
473
473
  # @return [NArray]
474
474
  def calculate_ndvi_byte(ndvi)
475
- (ndvi + 1) * (127.5)
475
+ (ndvi + 1) * (255.0 / 2)
476
476
  end
477
477
 
478
478
  # @param ndvi [NArray]
479
479
  # @return [NArray]
480
480
  def calculate_ndvi_uint16(ndvi)
481
- (ndvi + 1) * (2**15 - 1)
481
+ (ndvi + 1) * (65535.0 / 2)
482
482
  end
483
483
 
484
484
  # Sets any negative values in the NArray to 0.
@@ -85,6 +85,7 @@ module GDAL
85
85
  FFI::GDAL.GDALGetRasterColorInterpretation(@raster_band_pointer)
86
86
  end
87
87
 
88
+ # @param new_color_interp [FFI::GDAL::GDALColorInterp]
88
89
  # @return [Boolean]
89
90
  def color_interpretation=(new_color_interp)
90
91
  cpl_err = FFI::GDAL.GDALSetRasterColorInterpretation(@raster_band_pointer,
@@ -110,17 +110,17 @@ module GDAL
110
110
  raise "Can't colorize a #{data_type} band--must be :GDT_Byte or :GDT_UInt16"
111
111
  end
112
112
 
113
- self.color_interpretation = :GCI_PaletteIndex
113
+ self.color_interpretation ||= :GCI_PaletteIndex
114
114
  table.add_color_entry(0, 0, 0, 0, 255)
115
- bin_count = (color_entry_index_count / colors.size).to_f
115
+ bin_count = color_entry_index_count / colors.size.to_f
116
116
 
117
117
  1.upto(color_entry_index_count - 1) do |color_entry_index|
118
- color_number = (color_entry_index / bin_count.to_f).to_i
118
+ color_number = (color_entry_index / bin_count).to_i
119
119
 
120
120
  color = colors[color_number]
121
- color_array = hex_to_rgb(color) unless color.is_a?(Array)
121
+ rgb_array = hex_to_rgb(color) unless color.is_a?(Array)
122
122
  table.add_color_entry(color_entry_index,
123
- color_array[0], color_array[1], color_array[2], 255)
123
+ rgb_array[0], rgb_array[1], rgb_array[2], 255)
124
124
  end
125
125
 
126
126
  self.color_table = table
@@ -22,6 +22,7 @@ module OGR
22
22
  else
23
23
  new(geometry)
24
24
  end
25
+
25
26
  case geometry.name
26
27
  when 'POINT' then OGR::Point.new(geometry.c_pointer)
27
28
  when 'LINESTRING' then OGR::LineString.new(geometry.c_pointer)
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe GDAL::ColorTable do
5
+ subject do
6
+ described_class.create(:GPI_RGB)
7
+ end
8
+
9
+ describe '#color_entries_for' do
10
+ context 'no colors' do
11
+ it 'returns an empty array' do
12
+ expect(subject.color_entries_for(1)).to be_empty
13
+ end
14
+ end
15
+
16
+ context 'colors' do
17
+ it 'returns all of the color values ColorEntrys for the color number' do
18
+ subject.add_color_entry(0, 1, 2, 3, 4)
19
+ subject.add_color_entry(1, 10, 20, 30, 40)
20
+ expect(subject.color_entries_for(1)).to eq([1, 10])
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '#color_entries' do
26
+ context 'no colors' do
27
+ it 'returns an empty array' do
28
+ expect(subject.color_entries).to be_empty
29
+ end
30
+ end
31
+
32
+ context 'colors' do
33
+ it 'returns an array of the ColorEntrys' do
34
+ subject.add_color_entry(0, 1, 2, 3, 4)
35
+ subject.add_color_entry(1, 10, 20, 30, 40)
36
+
37
+ expect(subject.color_entries.size).to eq 2
38
+ expect(subject.color_entries.first).to be_a GDAL::ColorEntry
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '#color_entries_as_rgb' do
44
+ context 'no colors' do
45
+ it 'returns an empty array' do
46
+ expect(subject.color_entries_as_rgb).to be_empty
47
+ end
48
+ end
49
+
50
+ context 'colors' do
51
+ it 'returns an array of the ColorEntrys' do
52
+ subject.add_color_entry(0, 1, 2, 3, 4)
53
+ subject.add_color_entry(1, 10, 20, 30, 40)
54
+
55
+ expect(subject.color_entries_as_rgb.size).to eq 2
56
+ expect(subject.color_entries_as_rgb.first).to be_a GDAL::ColorEntry
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe GDAL::DataType do
4
+ describe '.size' do
5
+ context 'with valid data type' do
6
+ it 'returns the size' do
7
+ expect(described_class.size(:GDT_Byte)).to eq 8
8
+ end
9
+ end
10
+
11
+ context 'with invalid data type' do
12
+ it 'raises an ArgumentError' do
13
+ expect {
14
+ described_class.size(:Bob)
15
+ }.to raise_exception(ArgumentError)
16
+ end
17
+ end
18
+ end
19
+
20
+ describe '.complex?' do
21
+ context 'with valid, complex data type' do
22
+ it 'returns true' do
23
+ expect(described_class.complex?(:GDT_CFloat64)).to eq true
24
+ end
25
+ end
26
+
27
+ context 'with valid, simple data type' do
28
+ it 'returns true' do
29
+ expect(described_class.complex?(:GDT_Float64)).to eq false
30
+ end
31
+ end
32
+
33
+ context 'with invalid data type' do
34
+ it 'raises an ArgumentError' do
35
+ expect {
36
+ described_class.complex?(:Bob)
37
+ }.to raise_exception(ArgumentError)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '.name' do
43
+ context 'with valid data type' do
44
+ it 'returns the name' do
45
+ expect(described_class.name(:GDT_Byte)).to eq 'Byte'
46
+ end
47
+ end
48
+
49
+ context 'with invalid data type' do
50
+ it 'raises an ArgumentError' do
51
+ skip 'Figure out why this causes a segfault'
52
+
53
+ expect {
54
+ described_class.name(:Bob)
55
+ }.to raise_exception(ArgumentError)
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '.by_name' do
61
+ context 'with valid data type name' do
62
+ it 'returns the data type' do
63
+ skip 'Figure out why this causes a segfault'
64
+
65
+ expect(described_class.by_name('Byte')).to eq :GDT_Byte
66
+ end
67
+ end
68
+
69
+ context 'with invalid data type name' do
70
+ it 'raises an ArgumentError' do
71
+ skip 'Figure out why this causes a segfault'
72
+
73
+ expect {
74
+ described_class.by_name('Bob')
75
+ }.to raise_exception(ArgumentError)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe GDAL::Dataset do
4
+ let(:file_path) do
5
+ File.expand_path('../../support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif', __dir__)
6
+ end
7
+
8
+ subject do
9
+ described_class.open(file_path, 'r')
10
+ end
11
+
12
+ describe '#access_flag' do
13
+ it 'returns the flag that was used to open the dataset' do
14
+ expect(subject.access_flag).to eq :GA_ReadOnly
15
+ end
16
+ end
17
+
18
+ describe '#driver' do
19
+ it 'returns the driver that was used to open the dataset' do
20
+ expect(subject.driver).to be_a GDAL::Driver
21
+ end
22
+ end
23
+
24
+ describe '#file_list' do
25
+ it 'returns an array that includes the file that represents the dataset' do
26
+ expect(subject.file_list).to be_an Array
27
+ expect(subject.file_list).to include(file_path)
28
+ end
29
+ end
30
+
31
+ describe '#flush_cache' do
32
+ it 'returns nil' do
33
+ expect(subject.flush_cache).to be_nil
34
+ end
35
+ end
36
+
37
+ describe '#raster_x_size' do
38
+ it 'returns a Fixnum' do
39
+ expect(subject.raster_x_size).to eq 101
40
+ end
41
+ end
42
+
43
+ describe '#raster_y_size' do
44
+ it 'returns a Fixnum' do
45
+ expect(subject.raster_y_size).to eq 101
46
+ end
47
+ end
48
+
49
+ describe '#raster_count' do
50
+ it 'returns a Fixnum' do
51
+ expect(subject.raster_count).to eq 1
52
+ end
53
+ end
54
+
55
+ describe '#raster_band' do
56
+ it 'returns a GDAL::RasterBand' do
57
+ expect(subject.raster_band(1)).to be_a GDAL::RasterBand
58
+ end
59
+ end
60
+
61
+ describe '#add_band' do
62
+ it 'raises a GDAL::CPLErrFailure' do
63
+ skip 'Figure out why this causes a segfault'
64
+
65
+ expect {
66
+ subject.add_band(:GDT_Byte)
67
+ }.to raise_exception(GDAL::CPLErrFailure)
68
+ end
69
+ end
70
+
71
+ describe '#create_mask_band' do
72
+ context 'no flags given' do
73
+ it 'returns true' do
74
+ expect(subject.create_mask_band(0)).to eq true
75
+ end
76
+ end
77
+ end
78
+
79
+ describe '#projection' do
80
+ it 'returns the projection string' do
81
+ expect(subject.projection).to eq %(GEOGCS[\"unknown\",DATUM[\"unknown\",SPHEROID[\"Bessel 1841\",6377397.155,299.1528128000008,AUTHORITY[\"EPSG\",\"7004\"]],TOWGS84[598.1,73.7,418.2,0.202,0.045,-2.455,6.7]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]])
82
+ end
83
+ end
84
+
85
+ describe '#projection=' do
86
+ it 'returns the new projection' do
87
+ proj = subject.projection
88
+ expect(subject.projection = proj).to eq proj
89
+ expect(subject.projection).to eq proj
90
+ end
91
+ end
92
+
93
+ describe '#geo_transform' do
94
+ it 'returns a GDAL::GeoTransform' do
95
+ expect(subject.geo_transform).to be_a GDAL::GeoTransform
96
+ end
97
+ end
98
+ end
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.beta1
4
+ version: 1.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Loveless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2014-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -137,6 +137,10 @@ files:
137
137
  - README.md
138
138
  - Rakefile
139
139
  - TODO.md
140
+ - examples/extract_and_colorize.rb
141
+ - examples/geometries.rb
142
+ - examples/ogr_layer_to_layer.rb
143
+ - examples/testing_gdal.rb
140
144
  - ffi-gdal.gemspec
141
145
  - lib/ext/error_symbols.rb
142
146
  - lib/ext/float_ext.rb
@@ -235,8 +239,6 @@ files:
235
239
  - lib/ogr/spatial_reference_extensions.rb
236
240
  - lib/ogr/style_table.rb
237
241
  - lib/ogr/style_table_extensions.rb
238
- - linkies.rb
239
- - readie.rb
240
242
  - spec/ffi-gdal_spec.rb
241
243
  - spec/integration/color_table_info_spec.rb
242
244
  - spec/integration/dataset_info_spec.rb
@@ -259,18 +261,14 @@ files:
259
261
  - spec/support/worldfiles/SR_50M/SR_50M.tfw
260
262
  - spec/support/worldfiles/SR_50M/SR_50M.tif
261
263
  - spec/unit/ext/error_symbols_spec.rb
264
+ - spec/unit/gdal/color_table_extensions_spec.rb
262
265
  - spec/unit/gdal/color_table_spec.rb
266
+ - spec/unit/gdal/data_type_spec.rb
267
+ - spec/unit/gdal/dataset_spec.rb
263
268
  - spec/unit/ogr/layer_spec.rb
264
269
  - spec/unit/ogr/linear_ring_spec.rb
265
270
  - spec/unit/ogr/point_spec.rb
266
271
  - spec/unit/version_info_spec.rb
267
- - testing_gdal.rb
268
- - testing_gdalwarp.rb
269
- - testing_layer_to_layer.rb
270
- - testing_ndvi.rb
271
- - testing_nir.rb
272
- - testing_ogr.rb
273
- - things.rb
274
272
  homepage: https://github.com/turboladen/ffi-gdal
275
273
  licenses:
276
274
  - MIT
@@ -318,7 +316,10 @@ test_files:
318
316
  - spec/support/worldfiles/SR_50M/SR_50M.tfw
319
317
  - spec/support/worldfiles/SR_50M/SR_50M.tif
320
318
  - spec/unit/ext/error_symbols_spec.rb
319
+ - spec/unit/gdal/color_table_extensions_spec.rb
321
320
  - spec/unit/gdal/color_table_spec.rb
321
+ - spec/unit/gdal/data_type_spec.rb
322
+ - spec/unit/gdal/dataset_spec.rb
322
323
  - spec/unit/ogr/layer_spec.rb
323
324
  - spec/unit/ogr/linear_ring_spec.rb
324
325
  - spec/unit/ogr/point_spec.rb
data/linkies.rb DELETED
@@ -1,35 +0,0 @@
1
- require 'nokogiri'
2
- require 'open-uri'
3
-
4
- abort("Usage: extract_links URL DEST_DIR") if ARGV.size != 2
5
-
6
- args = ARGV.dup
7
- url = args[0]
8
- dest_dir = args[1]
9
-
10
- doc = Nokogiri::HTML(open(url))
11
-
12
- hrefs = doc.css("a").map do |link|
13
- if (href = link.attr("href")) && !href.empty?
14
- URI::join(url, href)
15
- end
16
- end.compact.uniq
17
-
18
- Dir.mkdir(dest_dir) unless File.exist?(dest_dir)
19
- Dir.chdir(dest_dir)
20
-
21
- hrefs.each_with_index do |href, i|
22
- filename = href.path.split('/').last
23
- print "Downloading (#{i + 1}/#{hrefs.size}) #{filename}...\r"
24
-
25
- begin
26
- File.write(filename, open(href).read)
27
- rescue OpenURI::HTTPError => ex
28
- puts "Sonofa!"
29
- raise
30
- end
31
- end
32
-
33
- puts "\nAll done!"
34
-
35
- # puts(hrefs.join("\n"))