ffi-gdal 0.0.1

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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +60 -0
  7. data/Rakefile +57 -0
  8. data/ffi-gdal.gemspec +28 -0
  9. data/lib/ext/cpl_error_symbols.rb +37 -0
  10. data/lib/ext/to_bool.rb +13 -0
  11. data/lib/ffi/gdal/cpl_conv.rb +151 -0
  12. data/lib/ffi/gdal/cpl_error.rb +91 -0
  13. data/lib/ffi/gdal/cpl_string.rb +113 -0
  14. data/lib/ffi/gdal/cpl_vsi.rb +119 -0
  15. data/lib/ffi/gdal/gdal_color_entry.rb +13 -0
  16. data/lib/ffi/gdal/gdal_gcp.rb +18 -0
  17. data/lib/ffi/gdal/ogr_api.rb +28 -0
  18. data/lib/ffi/gdal/ogr_core.rb +199 -0
  19. data/lib/ffi/gdal/ogr_srs_api.rb +48 -0
  20. data/lib/ffi/gdal/version.rb +5 -0
  21. data/lib/ffi/gdal.rb +607 -0
  22. data/lib/ffi-gdal/color_table.rb +59 -0
  23. data/lib/ffi-gdal/dataset.rb +347 -0
  24. data/lib/ffi-gdal/driver.rb +151 -0
  25. data/lib/ffi-gdal/exceptions.rb +17 -0
  26. data/lib/ffi-gdal/geo_transform.rb +137 -0
  27. data/lib/ffi-gdal/major_object.rb +71 -0
  28. data/lib/ffi-gdal/raster_attribute_table.rb +78 -0
  29. data/lib/ffi-gdal/raster_band.rb +571 -0
  30. data/lib/ffi-gdal/version_info.rb +48 -0
  31. data/lib/ffi-gdal.rb +12 -0
  32. data/linkies.rb +35 -0
  33. data/meow.rb +144 -0
  34. data/readie.rb +90 -0
  35. data/rubby.rb +224 -0
  36. data/spec/ext/cpl_error_symbols_spec.rb +79 -0
  37. data/spec/ffi-gdal/integration/color_table_info_spec.rb +60 -0
  38. data/spec/ffi-gdal/integration/dataset_info_spec.rb +95 -0
  39. data/spec/ffi-gdal/integration/driver_info_spec.rb +60 -0
  40. data/spec/ffi-gdal/integration/geo_transform_info_spec.rb +66 -0
  41. data/spec/ffi-gdal/integration/raster_attribute_table_info_spec.rb +23 -0
  42. data/spec/ffi-gdal/integration/raster_band_info_spec.rb +333 -0
  43. data/spec/ffi-gdal/unit/version_info_spec.rb +48 -0
  44. data/spec/ffi-gdal_spec.rb +6 -0
  45. data/spec/spec_helper.rb +13 -0
  46. data/spec/support/integration_help.rb +1 -0
  47. data/spec/support/shared_examples/major_object_examples.rb +68 -0
  48. data/things.rb +84 -0
  49. metadata +216 -0
data/linkies.rb ADDED
@@ -0,0 +1,35 @@
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"))
data/meow.rb ADDED
@@ -0,0 +1,144 @@
1
+ # http://www.gdal.org/gdal_tutorial.html
2
+
3
+
4
+ require './lib/ffi/gdal'
5
+ require 'ruby-progressbar'
6
+ include FFI::GDAL
7
+
8
+ progressbar = ProgressBar.create
9
+ #name = 'empty_red_image.tif'
10
+ #name = 'empty_black_image.tif'
11
+ name = 'NDVI20000201032.tif'
12
+
13
+ #dir = '../../agrian/gis_engine/test/test_files'
14
+ dir = '~/Desktop/geotiffs'
15
+
16
+ psz_src_filename = File.expand_path(name, dir)
17
+ progressbar.log "file name: #{psz_src_filename}"
18
+
19
+ FFI::GDAL.GDALAllRegister
20
+ dataset = GDALOpen(psz_src_filename, :GA_ReadOnly)
21
+
22
+ abort 'file was not compatible' if dataset.null?
23
+ progressbar.log "dataset: #{dataset}"
24
+
25
+ #-------------------
26
+ # Getting dataset information
27
+ #-------------------
28
+
29
+ dataset_driver = GDALGetDatasetDriver(dataset)
30
+ progressbar.log "driver: #{dataset_driver}"
31
+ progressbar.log "driver short name: #{GDALGetDriverShortName(dataset_driver)}"
32
+ progressbar.log "driver long name: #{GDALGetDriverLongName(dataset_driver)}"
33
+
34
+ progressbar.log "size, x: #{GDALGetRasterXSize(dataset)}"
35
+ progressbar.log "size, y: #{GDALGetRasterYSize(dataset)}"
36
+ progressbar.log "size, count: #{GDALGetRasterCount(dataset)}"
37
+
38
+ progressbar.log "Projection is #{GDALGetProjectionRef(dataset)}"
39
+
40
+ geo_transform = FFI::MemoryPointer.new(:double, 6)
41
+
42
+ GDALGetGeoTransform(dataset, geo_transform)
43
+ progressbar.log "origin: #{geo_transform[0].read_double}, #{geo_transform[3].read_double}"
44
+ progressbar.log "pixel size: #{geo_transform[1].read_double}, #{geo_transform[5].read_double}"
45
+
46
+
47
+ #-------------------
48
+ # Fetching a raster band
49
+ #-------------------
50
+ block_x_size = FFI::MemoryPointer.new(:int)
51
+ block_y_size = FFI::MemoryPointer.new(:int)
52
+ raster_band = GDALGetRasterBand(dataset, 1)
53
+ GDALGetBlockSize(raster_band, block_x_size, block_y_size)
54
+
55
+ progressbar.log "Block: #{block_x_size.read_int}x#{block_y_size.read_int}"
56
+ progressbar.log "Type: #{GDALGetDataTypeName(GDALGetRasterDataType(raster_band))}"
57
+ progressbar.log "ColorInterp: #{GDALGetColorInterpretationName(GDALGetRasterColorInterpretation(raster_band))}"
58
+
59
+ b_got_min = FFI::MemoryPointer.new(:double)
60
+ b_got_max = FFI::MemoryPointer.new(:double)
61
+
62
+ adf_min_max = FFI::MemoryPointer.new(:double, 2)
63
+ adf_min_max.put_array_of_double(0, [
64
+ GDALGetRasterMinimum(raster_band, b_got_min),
65
+ GDALGetRasterMaximum(raster_band, b_got_max)
66
+ ])
67
+
68
+ unless b_got_max && b_got_min
69
+ GDALComputeRasterMinMax(raster_band, true, adf_min_max)
70
+ end
71
+
72
+ progressbar.log "Min: #{adf_min_max[0].read_double}"
73
+ progressbar.log "Max: #{adf_min_max[1].read_double}"
74
+
75
+ overview_count = GDALGetOverviewCount(raster_band)
76
+ progressbar.log "Band has #{overview_count} overviews."
77
+
78
+ raster_color_table = GDALGetRasterColorTable(raster_band)
79
+ unless raster_color_table.null?
80
+ progressbar.log "Band has a color table with #{raster_color_table} entries."
81
+ end
82
+
83
+
84
+ #-------------------
85
+ # Reading Raster Data
86
+ #-------------------
87
+ x_size = GDALGetRasterBandXSize(raster_band)
88
+ paf_scanline = FFI::MemoryPointer.new(:float, x_size)
89
+ GDALRasterIO(raster_band,
90
+ :GF_Read,
91
+ 0,
92
+ 0,
93
+ x_size,
94
+ 1,
95
+ paf_scanline,
96
+ x_size,
97
+ 1,
98
+ :GDT_Float32,
99
+ 0,
100
+ 0)
101
+
102
+ progressbar.log "scanline: #{paf_scanline.read_float}"
103
+
104
+ #-------------------
105
+ # Techniques for creating files
106
+ #-------------------
107
+ psz_format = 'GTiff'
108
+ geotiff_driver = GDALGetDriverByName(psz_format)
109
+ abort "No such driver #{psz_format}" if geotiff_driver.null?
110
+ papsz_metadata = GDALGetMetadata(geotiff_driver, nil)
111
+
112
+ if CSLFetchBoolean(papsz_metadata, GDAL_DCAP_CREATE, 0)
113
+ progressbar.log "Driver #{psz_format} supports Create() method."
114
+ end
115
+
116
+ if CSLFetchBoolean(papsz_metadata, GDAL_DCAP_CREATECOPY, 0)
117
+ progressbar.log "Driver #{psz_format} supports CreateCopy() method."
118
+ end
119
+
120
+ psz_dst_filename = File.expand_path('gdal_createcopy_test.tif', dir)
121
+ src_dataset = GDALOpen(psz_src_filename, :GA_ReadOnly)
122
+ dest_dataset = GDALCreateCopy(geotiff_driver, psz_dst_filename, src_dataset, 0, nil, nil, nil)
123
+ GDALClose(dest_dataset) unless dest_dataset.null?
124
+
125
+ # Don't close this yet--we use it later.
126
+ # GDALClose(src_dataset)
127
+
128
+
129
+ papsz_options = CSLSetNameValue(FFI::MemoryPointer.new(:pointer, 2), 'TILED', 'YES')
130
+ papsz_options = CSLSetNameValue(papsz_options, 'COMPRESS', 'PACKBITS')
131
+ progressbar.log "First option key/value pair: #{papsz_options.read_array_of_pointer(2).first.read_string}"
132
+ progressbar.log "Second option key/value pair: #{papsz_options.read_array_of_pointer(2).last.read_string}"
133
+
134
+
135
+ callback = Proc.new do |double, _, _|
136
+ progress = double * 100
137
+ progressbar.progress = progress unless progressbar.progress == 100
138
+ end
139
+ dest_dataset2 = GDALCreateCopy(geotiff_driver, psz_dst_filename, src_dataset, 0, papsz_options, callback, nil)
140
+
141
+ GDALClose(dest_dataset2) unless dest_dataset2.null?
142
+ CSLDestroy(papsz_options)
143
+ GDALClose(src_dataset)
144
+
data/readie.rb ADDED
@@ -0,0 +1,90 @@
1
+ require './lib/ffi-gdal'
2
+ require 'narray'
3
+
4
+
5
+ #dir = '../../agrian/gis_engine/test/test_files'
6
+ #name = 'empty_red_image.tif'
7
+ #name = 'empty_black_image.tif'
8
+
9
+ #dir = '~/Desktop/geotiffs'
10
+ #name = 'NDVI20000201032.tif'
11
+ #name = 'NDVI20000701183.tif'
12
+ #name = 'NDVI20000701183.zip'
13
+ #name = 'NDVI20000401092.tif'
14
+
15
+ #dir = './spec/support'
16
+ #name = 'google_earth_test.jpg'
17
+ #name = 'compassdata_gcparchive_google_earth.kmz'
18
+
19
+ #dir = './spec/support/aaron/Floyd'
20
+ #name = 'Floyd_1058_20140612_NRGB.tif'
21
+ #name = 'Floyd_1058_20140612_RGBNRGB.bmp'
22
+ #name = 'Floyd_1058_20140612_RGBNRGB.jpg'
23
+
24
+ dir = './spec/support/images/Harper'
25
+ name = 'Harper_1058_20140612_NRGB.tif'
26
+
27
+ #dir = './spec/support/osgeo'
28
+ #name = 'c41078a1.tif'
29
+
30
+ filename = File.expand_path(name, dir)
31
+ dataset = GDAL::Dataset.open(filename, 'r')
32
+
33
+ abort('No raster bands') if dataset.raster_count == 0
34
+ GDAL.log "raster count: #{dataset.raster_count}"
35
+
36
+ def raster_stuff(band)
37
+ GDAL.log "x size: #{band.x_size}"
38
+ GDAL.log "y size: #{band.y_size}"
39
+ GDAL.log "min: #{band.minimum_value}"
40
+ GDAL.log "max: #{band.maximum_value}"
41
+ GDAL.log "block size: #{band.block_size}"
42
+ GDAL.log "color interp: #{band.color_interpretation}"
43
+ lines = []
44
+
45
+ band.readlines do |line|
46
+ lines << line
47
+ end
48
+
49
+ GDAL.log "line height: #{lines.size}"
50
+ lines
51
+ end
52
+
53
+ bands = []
54
+
55
+
56
+ 1.upto(dataset.raster_count) do |i|
57
+ GDAL.log "Checking band #{i}"
58
+ band = dataset.raster_band(i)
59
+ GDAL.log "* color interp: #{band.color_interpretation}"
60
+
61
+ if %i[GCI_RedBand GCI_Undefined].include? band.color_interpretation
62
+ bands << {
63
+ band: band,
64
+ array: NArray.to_na(raster_stuff(dataset.raster_band(i)))
65
+ }
66
+ end
67
+ end
68
+
69
+ red = bands.find { |hash| hash[:band].color_interpretation == :GCI_RedBand }
70
+ nir = bands.find { |hash| hash[:band].color_interpretation == :GCI_Undefined }
71
+
72
+ if nir.nil?
73
+ abort 'No near-infrared band found!'
74
+ end
75
+ ndvi = (nir[:array] - red[:array]) / (nir[:array] + red[:array])
76
+
77
+ GDAL.log "NDVI array created"
78
+
79
+ GDAL.log dataset.driver.long_name
80
+ GDAL.log dataset.driver.all_metadata[:DEFAULT]["DCAP_CREATE"]
81
+
82
+ dataset.driver.create_dataset('testie.tif', ndvi.sizes.first, ndvi.sizes.last) do |out_dataset|
83
+ GDAL.log "raster count: #{out_dataset.raster_count}"
84
+ out_band = out_dataset.raster_band(1)
85
+ out_band.write_array(ndvi)
86
+
87
+ # need to add metadata and raster data
88
+ # http://www.gdal.org/gdal_tutorial.html
89
+ end
90
+
data/rubby.rb ADDED
@@ -0,0 +1,224 @@
1
+ require './lib/ffi-gdal'
2
+ require 'pp'
3
+ require 'pathname'
4
+
5
+ #dir = '../../agrian/gis_engine/test/test_files'
6
+ #name = 'empty_red_image.tif'
7
+ #name = 'empty_black_image.tif'
8
+
9
+ #dir = '~/Desktop/geotiffs'
10
+ #name = 'NDVI20000201032.tif'
11
+ #name = 'NDVI20000701183.tif'
12
+ #name = 'NDVI20000701183.zip'
13
+ #name = 'NDVI20000401092.tif'
14
+
15
+ #dir = './spec/support'
16
+ #name = 'google_earth_test.jpg'
17
+ #name = 'compassdata_gcparchive_google_earth.kmz'
18
+
19
+ #dir = './spec/support/aaron/Floyd'
20
+ #name = 'Floyd_1058_20140612_NRGB.tif'
21
+
22
+ dir = './spec/support/images/Harper'
23
+ name = 'Harper_1058_20140612_NRGB.tif'
24
+
25
+ #dir = './spec/support/osgeo'
26
+ #name = 'c41078a1.tif'
27
+
28
+ #dir = './spec/support/ShapeDailyCurrent'
29
+ #name = '851449507.dbf'
30
+ #name = '851449507.prj'
31
+
32
+ filename = File.expand_path(name, dir)
33
+ dataset = GDAL::Dataset.open(filename, 'r')
34
+
35
+ current_directory = Pathname.new(Dir.pwd)
36
+
37
+ puts '#------------------------------------------------------------------------'
38
+ puts '#'
39
+ puts "# #{GDAL.long_version}"
40
+ puts '#'
41
+ puts '# Build info:'
42
+ GDAL.build_info.each do |k, v|
43
+ puts "# - #{k} -> #{v}"
44
+ end
45
+ puts '#'
46
+ puts '#------------------------------------------------------------------------'
47
+ puts '#------------------------------------------------------------------------'
48
+ puts '# Dataset Info'
49
+ puts '#------------------------------------------------------------------------'
50
+ puts "* Description:\t\t\t#{dataset.description}"
51
+ puts "* Raster size (x, y):\t\t#{dataset.raster_x_size}, #{dataset.raster_y_size}"
52
+ puts "* Raster count:\t\t\t#{dataset.raster_count}"
53
+ puts "* Access flag:\t\t\t#{dataset.access_flag}"
54
+ puts "* Projection:\t#{dataset.projection}"
55
+ puts '* File list:'
56
+ dataset.file_list.each do |path|
57
+ p = Pathname.new(path)
58
+ puts "\t\t\t\t- #{p.relative_path_from(current_directory)}"
59
+ end
60
+
61
+ puts '* Metadata'
62
+ dataset.all_metadata.each do |domain, data|
63
+ puts "\t\t\t\t+ Domain: #{domain}"
64
+ if data.empty?
65
+ puts "\t\t\t\t\t- No values"
66
+ else
67
+ data.each do |k, v|
68
+ print "\t\t\t\t\t- #{k} => "
69
+ pp v
70
+ end
71
+ end
72
+ end
73
+
74
+
75
+
76
+ puts '#------------------------------------------------------------------------'
77
+ puts '# Driver Info'
78
+ puts '#------------------------------------------------------------------------'
79
+ puts "* Description:\t\t#{dataset.driver.description}"
80
+ puts "* Short name:\t\t#{dataset.driver.short_name}"
81
+ puts "* Long name:\t\t#{dataset.driver.long_name}"
82
+ puts "* Help topic:\t\t#{dataset.driver.help_topic}"
83
+ puts '* Metadata:'
84
+ dataset.driver.all_metadata.each do |domain, data|
85
+ puts "\t\t\t+ Domain: #{domain}"
86
+ if data.empty?
87
+ puts "\t\t\t\t- No values"
88
+ else
89
+ data.each do |k, v|
90
+ print "\t\t\t\t- #{k} => "
91
+ pp v
92
+ end
93
+ end
94
+ end
95
+
96
+ puts '* Creation option list:'
97
+ dataset.driver.creation_option_list.each do |option|
98
+ puts "\t\t\t- #{option}" unless option.empty?
99
+ end
100
+ puts
101
+
102
+
103
+ if dataset.raster_count > 0
104
+ puts '#------------------------------------------------------------------------'
105
+ puts '# Raster Band Info'
106
+ puts '#------------------------------------------------------------------------'
107
+ (1..dataset.raster_count).each do |i|
108
+ band = dataset.raster_band(i)
109
+ puts "* Band #{i}/#{dataset.raster_count}"
110
+ puts " - description:\t\t\t#{band.description}"
111
+ puts " - size (x,y):\t\t\t#{band.x_size},#{band.y_size}"
112
+ puts " - no-data value:\t\t#{band.no_data_value}"
113
+ puts " - access flag:\t\t#{band.access_flag}"
114
+ puts " - number:\t\t\t#{band.number}"
115
+ puts " - color interp:\t\t#{band.color_interpretation}"
116
+ puts " - type:\t\t\t#{band.data_type}"
117
+ puts " - block size:\t\t\t#{band.block_size}"
118
+ puts " - category names:\t\t#{band.category_names}"
119
+ band.category_names = 'meow'
120
+ puts " - category names:\t\t#{band.category_names}"
121
+ puts " - value range:\t\t#{band.minimum_value}..#{band.maximum_value}"
122
+ #puts " + read:\t\t\t#{band.read}"
123
+ puts " - unit type:\t\t\t#{band.unit_type}"
124
+ puts " - statistics:\t\t\t#{band.statistics}"
125
+ puts " - scale:\t\t\t#{band.scale}"
126
+ puts " - offset:\t\t\t#{band.offset}"
127
+ puts " - mask flags:\t\t\t#{band.mask_flags}"
128
+ #puts " + default histogram:\t\t\t#{band.default_histogram}"
129
+ #puts " + histogram:\t\t\t#{band.histogram(-0.5, 255.5, 256)}"
130
+
131
+ if band.mask_band
132
+ puts ' + Mask band:'
133
+ puts " - number:\t\t\t\t#{band.mask_band.number}"
134
+ puts " - size (x,y):\t\t\t#{band.mask_band.x_size},#{band.mask_band.y_size}"
135
+ puts " - color interp:\t\t\t#{band.mask_band.color_interpretation}"
136
+ puts " - type:\t\t\t\t#{band.mask_band.data_type}"
137
+ puts " - block size:\t\t\t#{band.mask_band.block_size}"
138
+ puts " - value range:\t\t\t#{band.mask_band.minimum_value}..#{band.mask_band.maximum_value}"
139
+ end
140
+ puts " - has arbitrary overviews?\t#{band.arbitrary_overviews?}"
141
+ puts " - raster sample overview:\t#{band.raster_sample_overview}"
142
+ puts " - overview count:\t\t#{band.overview_count}"
143
+ if band.overview_count > 0
144
+ (0...band.overview_count).each do |j|
145
+ overview = band.overview(j)
146
+ puts " # Overview #{j} Info:"
147
+ puts " - size (x, y):\t\t#{overview.x_size}, #{overview.y_size}"
148
+ puts " - color interp:\t\t#{overview.color_interpretation}"
149
+ puts " - type:\t\t\t#{overview.data_type}"
150
+ puts " - block size:\t\t#{overview.block_size}"
151
+ puts " - value range:\t\t#{overview.minimum_value}..#{overview.maximum_value}"
152
+ puts " - overview count:\t\t#{overview.overview_count}"
153
+ end
154
+ end
155
+ puts ' + Metadata:'
156
+ band.all_metadata.each do |domain, data|
157
+ puts "\t\t\t\t+ Domain: #{domain}"
158
+ if data.empty?
159
+ puts "\t\t\t\t\t- No values"
160
+ else
161
+ data.each do |k, v|
162
+ print "\t\t\t\t\t- #{k} => "
163
+ pp v
164
+ end
165
+ end
166
+ end
167
+ if band.color_table
168
+ puts ' + Color Table Info'
169
+ puts " - palette interp:\t\t#{band.color_table.palette_interpretation}"
170
+ puts " - color entry count:\t#{band.color_table.color_entry_count}"
171
+ if band.color_table.color_entry_count > 0
172
+ puts " - #{band.color_table.color_entry_count} color entries:"
173
+
174
+ (0...band.color_table.color_entry_count).each do |j|
175
+ ce = band.color_table.color_entry(j)
176
+ ce_string = "(#{ce[:c1]},#{ce[:c2]},#{ce[:c3]},#{ce[:c4]})"
177
+
178
+ rgb = band.color_table.color_entry_as_rgb(j)
179
+ rgb_string = "(#{rgb[:c1]},#{rgb[:c2]},#{rgb[:c3]},#{rgb[:c4]})"
180
+
181
+ if band.color_table.palette_interpretation == :GPI_RGB
182
+ puts "\t\t\t\t~ #{j}:\t#{ce_string}"
183
+ else
184
+ puts "\t\t\t\t~ #{j}:\t#{ce_string}, RGB: #{rgb_string}"
185
+ end
186
+ end
187
+ else
188
+ puts ' - No Color Entry Info.'
189
+ end
190
+ end
191
+ end
192
+ end
193
+
194
+ puts
195
+
196
+ puts '#------------------------------------------------------------------------'
197
+ puts '# Ground Control Point (GCP) Info'
198
+ puts '#------------------------------------------------------------------------'
199
+ puts "* GCP count:\t\t\t#{dataset.gcp_count}"
200
+ if dataset.gcp_count > 0
201
+ puts "* GCP projection:\t\t'#{dataset.gcp_projection}'"
202
+ puts '* GCPs:'
203
+ puts "\t\t\t- ID:\t\t\t\t'#{dataset.gcps[:id]}'"
204
+ puts "\t\t\t- Info:\t\t\t'#{dataset.gcps[:info]}'"
205
+ puts "\t\t\t- Pixel:\t\t\t#{dataset.gcps[:pixel]}"
206
+ puts "\t\t\t- Line:\t\t\t#{dataset.gcps[:line]}"
207
+ puts "\t\t\t- X:\t\t\t\t#{dataset.gcps[:x]}"
208
+ puts "\t\t\t- Y:\t\t\t\t#{dataset.gcps[:y]}"
209
+ puts "\t\t\t- Z:\t\t\t\t#{dataset.gcps[:z]}"
210
+ end
211
+
212
+ puts
213
+ puts '#------------------------------------------------------------------------'
214
+ puts '# Geo-transform Info'
215
+ puts '#------------------------------------------------------------------------'
216
+ puts "* x origin (C):\t\t\t#{dataset.geo_transform.x_origin}"
217
+ puts "* y origin (F):\t\t\t#{dataset.geo_transform.y_origin}"
218
+ puts "* pixel width (A):\t\t#{dataset.geo_transform.pixel_width}"
219
+ puts "* pixel height (E):\t\t#{dataset.geo_transform.pixel_height}"
220
+ puts "* x rotation (B):\t\t#{dataset.geo_transform.x_rotation}"
221
+ puts "* y rotation (D):\t\t#{dataset.geo_transform.y_rotation}"
222
+ puts "* x projection (0.1, 0.2):\t#{dataset.geo_transform.x_projection(0.1, 0.2)}"
223
+ puts "* y projection (0.2, 0.1):\t#{dataset.geo_transform.y_projection(0.2, 0.1)}"
224
+ puts '#----------------------------------------------------'
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+ require 'ext/cpl_error_symbols'
3
+
4
+ describe Symbol do
5
+ describe '#to_ruby' do
6
+ context ':CE_None' do
7
+ subject { :CE_None }
8
+
9
+ it 'returns :none' do
10
+ expect(subject.to_ruby).to eq :none
11
+ end
12
+
13
+ context 'with an explicit value' do
14
+ it 'returns what the given param is' do
15
+ expect(subject.to_ruby(none: :pants)).to eq :pants
16
+ end
17
+ end
18
+ end
19
+
20
+ context ':CE_Debug' do
21
+ subject { :CE_Debug }
22
+
23
+ it 'returns :debug' do
24
+ expect(subject.to_ruby).to eq :debug
25
+ end
26
+
27
+ context 'with an explicit value' do
28
+ it 'returns what the given param is' do
29
+ expect(subject.to_ruby(debug: :pants)).to eq :pants
30
+ end
31
+ end
32
+ end
33
+
34
+ context ':CE_Warning' do
35
+ subject { :CE_Warning }
36
+
37
+ it 'returns :warning' do
38
+ expect(subject.to_ruby).to eq :warning
39
+ end
40
+
41
+ context 'with an explicit value' do
42
+ it 'returns what the given param is' do
43
+ expect(subject.to_ruby(warning: :pants)).to eq :pants
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#to_bool' do
50
+ context ':CE_None' do
51
+ subject { :CE_None.to_bool }
52
+ it { is_expected.to eq true }
53
+ end
54
+
55
+ context ':CE_Debug' do
56
+ subject { :CE_Debug.to_bool }
57
+ it { is_expected.to eq true }
58
+ end
59
+
60
+ context ':CE_Warning' do
61
+ subject { :CE_Warning.to_bool }
62
+ it { is_expected.to eq false }
63
+ end
64
+
65
+ context ':CE_Failure' do
66
+ subject { :CE_Failure }
67
+ it 'raises a CPLErrFailure' do
68
+ expect { subject.to_bool }.to raise_error GDAL::CPLErrFailure
69
+ end
70
+ end
71
+
72
+ context ':CE_Fatal' do
73
+ subject { :CE_Fatal }
74
+ it 'raises a CPLErrFailure' do
75
+ expect { subject.to_bool }.to raise_error GDAL::CPLErrFailure
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'support/integration_help'
3
+ require 'ffi-gdal'
4
+
5
+
6
+ TIF_FILES.each do |file|
7
+ dataset = GDAL::Dataset.open(file, 'r')
8
+
9
+ describe 'Color Table Info' do
10
+ after :all do
11
+ dataset.close
12
+ end
13
+
14
+ # TODO: Test against each raster band
15
+ subject do
16
+ band = GDAL::RasterBand.new(dataset.c_pointer, band_id: 1)
17
+ band.color_table
18
+ end
19
+
20
+ describe '#palette_interpretation' do
21
+ it 'returns a GDALPaletteInterp' do
22
+ next if subject.nil?
23
+
24
+ expect(subject.palette_interpretation).to eq :GPI_RGB
25
+ end
26
+ end
27
+
28
+ describe '#color_entry_count' do
29
+ it 'returns a Fixnum (256 with current test files)' do
30
+ next if subject.nil?
31
+
32
+ expect(subject.color_entry_count).to eq 256
33
+ end
34
+ end
35
+
36
+ describe '#color_entry' do
37
+ it 'returns a FFI::GDAL::GDALColorEntry' do
38
+ next if subject.nil?
39
+
40
+ expect(subject.color_entry(0)).to be_a FFI::GDAL::GDALColorEntry
41
+ end
42
+
43
+ it 'has 4 Fixnum values, >= 0' do
44
+ next if subject.nil?
45
+
46
+ expect(subject.color_entry(0)[:c1]).to be_a Fixnum
47
+ expect(subject.color_entry(0)[:c1]).to be >= 0
48
+
49
+ expect(subject.color_entry(0)[:c2]).to be_a Fixnum
50
+ expect(subject.color_entry(0)[:c2]).to be >= 0
51
+
52
+ expect(subject.color_entry(0)[:c3]).to be_a Fixnum
53
+ expect(subject.color_entry(0)[:c3]).to be >= 0
54
+
55
+ expect(subject.color_entry(0)[:c4]).to be_a Fixnum
56
+ expect(subject.color_entry(0)[:c4]).to be >= 0
57
+ end
58
+ end
59
+ end
60
+ end