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.
data/things.rb DELETED
@@ -1,84 +0,0 @@
1
- require './lib/ffi-gdal'
2
-
3
-
4
- #dir = '../../agrian/gis_engine/test/test_files'
5
- #name = 'empty_red_image.tif'
6
- #name = 'empty_black_image.tif'
7
-
8
- #dir = '~/Desktop/geotiffs'
9
- #name = 'NDVI20000201032.tif'
10
- #name = 'NDVI20000701183.tif'
11
- #name = 'NDVI20000701183.zip'
12
- #name = 'NDVI20000401092.tif'
13
-
14
- #dir = './spec/support'
15
- #name = 'google_earth_test.jpg'
16
- #name = 'compassdata_gcparchive_google_earth.kmz'
17
-
18
- #dir = './spec/support/aaron/Floyd'
19
- #name = 'Floyd_1058_20140612_NRGB.tif'
20
- dir = './spec/support/images/Harper'
21
- name = 'Harper_1058_20140612_NRGB.tif'
22
-
23
- #dir = './spec/support/osgeo'
24
- #name = 'c41078a1.tif'
25
-
26
-
27
- filename = File.expand_path(name, dir)
28
- dataset = GDAL::Dataset.open(filename, 'r')
29
- histogram = FFI::MemoryPointer.new(:int, 256)
30
-
31
- if dataset.raster_count > 0
32
- (1..dataset.raster_count).each do |i|
33
- band = dataset.raster_band(i)
34
- puts "raster #{i} data type: #{band.data_type}"
35
-
36
- block_size = band.block_size
37
- puts "raster #{i} block size: #{block_size}"
38
-
39
- x_blocks = (band.x_size + block_size[:x] - 1) / block_size[:x]
40
- puts "raster #{i} X blocks (#{band.x_size} + #{block_size[:x]} - 1): #{x_blocks}"
41
-
42
- y_blocks = (band.y_size + block_size[:y] - 1) / block_size[:y]
43
- puts "raster #{i} Y blocks (#{band.y_size} + #{block_size[:y]} - 1): #{y_blocks}"
44
-
45
- data_pointer = FFI::MemoryPointer.new(:uchar, block_size[:x] * block_size[:y])
46
-
47
- (0...y_blocks).each do |y_block|
48
- (0...x_blocks).each do |x_block|
49
- band.read_block(x_block, y_block, data_pointer)
50
-
51
- x_valid = if x_block + 1 * block_size[:x] > band.x_size
52
- band.x_size - x_block * block_size[:x]
53
- else
54
- block_size[:x]
55
- end
56
-
57
- y_valid = if y_block + 1 * block_size[:y] > band.y_size
58
- band.y_size - y_block * block_size[:y]
59
- else
60
- block_size[:y]
61
- end
62
-
63
- $stdout.sync
64
- (0...y_valid).each do |y|
65
- (0...x_valid).each do |x|
66
- offset = x + y * block_size[:x]
67
-
68
- begin
69
- value = histogram[offset]
70
- int = value.read_int
71
- print "y block: #{y_block}, x block: #{x_block}, offset: #{offset}, value: #{int}, e: #{y_block - int}\r"
72
- histogram[offset].write_int(value.read_int + 1)
73
- rescue IndexError
74
- #puts "MERER"
75
- end
76
- end
77
- end
78
-
79
- end
80
- end
81
-
82
- p histogram.read_array_of_int(0)
83
- end
84
- end