ffi-gdal 0.0.4 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -1
- data/Rakefile +12 -1
- data/TODO.md +11 -0
- data/ffi-gdal.gemspec +2 -2
- data/lib/ext/error_symbols.rb +59 -0
- data/lib/ext/float_ext.rb +15 -0
- data/lib/ext/narray_ext.rb +16 -0
- data/lib/ext/to_bool.rb +2 -0
- data/lib/ffi-gdal.rb +139 -4
- data/lib/ffi/{gdal/cpl_conv.rb → cpl/conv_h.rb} +2 -3
- data/lib/ffi/{gdal/cpl_error.rb → cpl/error_h.rb} +1 -25
- data/lib/ffi/cpl/minixml_h.rb +14 -0
- data/lib/ffi/{gdal/cpl_string.rb → cpl/string_h.rb} +0 -25
- data/lib/ffi/{gdal/cpl_vsi.rb → cpl/vsi_h.rb} +0 -0
- data/lib/ffi/cpl/xml_node.rb +13 -0
- data/lib/ffi/gdal.rb +57 -593
- data/lib/ffi/gdal/alg_h.rb +127 -0
- data/lib/ffi/gdal/gdal_grid_data_metrics_options.rb +14 -0
- data/lib/ffi/gdal/gdal_grid_inverse_distance_to_a_power_options.rb +19 -0
- data/lib/ffi/gdal/gdal_grid_moving_average_options.rb +14 -0
- data/lib/ffi/gdal/gdal_grid_nearest_neighbor_options.rb +13 -0
- data/lib/ffi/gdal/gdal_h.rb +683 -0
- data/lib/ffi/gdal/gdal_rpc_info.rb +27 -0
- data/lib/ffi/gdal/gdal_transformer_info.rb +14 -0
- data/lib/ffi/gdal/gdal_warp_options.rb +43 -0
- data/lib/ffi/gdal/grid_h.rb +51 -0
- data/lib/ffi/gdal/version.rb +1 -1
- data/lib/ffi/gdal/warper_h.rb +48 -0
- data/lib/ffi/ogr.rb +12 -0
- data/lib/ffi/ogr/api_h.rb +553 -0
- data/lib/ffi/ogr/core_h.rb +148 -0
- data/lib/ffi/ogr/featurestyle_h.rb +22 -0
- data/lib/ffi/ogr/geocoding_h.rb +21 -0
- data/lib/ffi/ogr/ogr_contour_writer_info.rb +14 -0
- data/lib/ffi/ogr/ogr_envelope.rb +12 -0
- data/lib/ffi/ogr/ogr_envelope_3d.rb +14 -0
- data/lib/ffi/ogr/ogr_field.rb +50 -0
- data/lib/ffi/ogr/ogr_style_param.rb +12 -0
- data/lib/ffi/ogr/ogr_style_value.rb +13 -0
- data/lib/ffi/ogr/srs_api_h.rb +325 -0
- data/lib/gdal/color_entry.rb +47 -0
- data/lib/gdal/color_entry_extensions.rb +30 -0
- data/lib/gdal/color_interpretation.rb +15 -0
- data/lib/gdal/color_table.rb +146 -0
- data/lib/gdal/color_table_extensions.rb +47 -0
- data/lib/gdal/color_table_types/cmyk.rb +25 -0
- data/lib/gdal/color_table_types/gray.rb +9 -0
- data/lib/gdal/color_table_types/hls.rb +21 -0
- data/lib/gdal/color_table_types/rgb.rb +25 -0
- data/lib/gdal/data_type.rb +38 -0
- data/lib/gdal/dataset.rb +437 -0
- data/lib/gdal/dataset_extensions.rb +496 -0
- data/lib/gdal/driver.rb +244 -0
- data/lib/gdal/driver_extensions.rb +56 -0
- data/lib/gdal/environment_methods.rb +43 -0
- data/lib/{ffi-gdal → gdal}/exceptions.rb +4 -1
- data/lib/gdal/geo_transform.rb +188 -0
- data/lib/gdal/geo_transform_extensions.rb +90 -0
- data/lib/gdal/logger.rb +7 -0
- data/lib/{ffi-gdal → gdal}/major_object.rb +15 -14
- data/lib/gdal/options.rb +49 -0
- data/lib/gdal/raster_attribute_table.rb +185 -0
- data/lib/gdal/raster_attribute_table_extensions.rb +40 -0
- data/lib/{ffi-gdal → gdal}/raster_band.rb +227 -99
- data/lib/gdal/raster_band_extensions.rb +198 -0
- data/lib/{ffi-gdal → gdal}/version_info.rb +8 -0
- data/lib/gdal/warp_operation.rb +96 -0
- data/lib/ogr/coordinate_transformation.rb +108 -0
- data/lib/ogr/data_source.rb +172 -0
- data/lib/ogr/data_source_extensions.rb +32 -0
- data/lib/ogr/driver.rb +119 -0
- data/lib/ogr/envelope.rb +80 -0
- data/lib/ogr/envelope_extensions.rb +92 -0
- data/lib/ogr/exceptions.rb +35 -0
- data/lib/ogr/feature.rb +212 -0
- data/lib/ogr/feature_definition.rb +120 -0
- data/lib/ogr/feature_definition_extensions.rb +36 -0
- data/lib/ogr/feature_extensions.rb +31 -0
- data/lib/ogr/field.rb +91 -0
- data/lib/ogr/field_extensions.rb +23 -0
- data/lib/ogr/geocoding_session.rb +84 -0
- data/lib/ogr/geometry.rb +617 -0
- data/lib/ogr/geometry_extensions.rb +60 -0
- data/lib/ogr/geometry_types/collection.rb +45 -0
- data/lib/ogr/geometry_types/curve.rb +120 -0
- data/lib/ogr/geometry_types/surface.rb +20 -0
- data/lib/ogr/layer.rb +226 -0
- data/lib/ogr/layer_extensions.rb +55 -0
- data/lib/ogr/line_string.rb +7 -0
- data/lib/ogr/linear_ring.rb +6 -0
- data/lib/ogr/multi_line_string.rb +9 -0
- data/lib/ogr/multi_point.rb +7 -0
- data/lib/ogr/multi_polygon.rb +14 -0
- data/lib/ogr/point.rb +89 -0
- data/lib/ogr/polygon.rb +9 -0
- data/lib/ogr/spatial_reference.rb +723 -0
- data/lib/ogr/spatial_reference_extensions.rb +32 -0
- data/lib/ogr/style_table.rb +17 -0
- data/lib/ogr/style_table_extensions.rb +16 -0
- data/spec/{ffi-gdal/integration → integration}/color_table_info_spec.rb +1 -1
- data/spec/{ffi-gdal/integration → integration}/dataset_info_spec.rb +0 -0
- data/spec/{ffi-gdal/integration → integration}/driver_info_spec.rb +1 -1
- data/spec/{ffi-gdal/integration → integration}/geo_transform_info_spec.rb +0 -0
- data/spec/{ffi-gdal/integration → integration}/raster_attribute_table_info_spec.rb +1 -1
- data/spec/{ffi-gdal/integration → integration}/raster_band_info_spec.rb +5 -5
- data/spec/spec_helper.rb +4 -1
- data/spec/support/shapefiles/states_21basic/states.prj +1 -0
- data/spec/support/shapefiles/states_21basic/states.sbn +0 -0
- data/spec/support/shapefiles/states_21basic/states.sbx +0 -0
- data/spec/support/shapefiles/states_21basic/states.shp +0 -0
- data/spec/support/worldfiles/SR_50M/SR_50M.VERSION.txt +1 -0
- data/spec/support/worldfiles/SR_50M/SR_50M.prj +1 -0
- data/spec/support/worldfiles/SR_50M/SR_50M.tfw +6 -0
- data/spec/{ext/cpl_error_symbols_spec.rb → unit/ext/error_symbols_spec.rb} +1 -1
- data/spec/unit/gdal/color_table_spec.rb +146 -0
- data/spec/unit/ogr/layer_spec.rb +97 -0
- data/spec/unit/ogr/linear_ring_spec.rb +111 -0
- data/spec/unit/ogr/point_spec.rb +321 -0
- data/spec/{ffi-gdal/unit → unit}/version_info_spec.rb +1 -1
- data/testing_gdal.rb +168 -0
- data/testing_gdalwarp.rb +91 -0
- data/testing_layer_to_layer.rb +35 -0
- data/testing_ndvi.rb +76 -0
- data/testing_nir.rb +77 -0
- data/testing_ogr.rb +63 -0
- metadata +167 -59
- data/lib/ext/cpl_error_symbols.rb +0 -37
- data/lib/ffi-gdal/color_table.rb +0 -59
- data/lib/ffi-gdal/dataset.rb +0 -359
- data/lib/ffi-gdal/driver.rb +0 -151
- data/lib/ffi-gdal/geo_transform.rb +0 -137
- data/lib/ffi-gdal/raster_attribute_table.rb +0 -78
- data/lib/ffi/gdal/ogr_api.rb +0 -21
- data/lib/ffi/gdal/ogr_core.rb +0 -195
- data/lib/ffi/gdal/ogr_srs_api.rb +0 -44
- data/meow.rb +0 -144
- data/rubby.rb +0 -224
@@ -0,0 +1,321 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe OGR::Point do
|
5
|
+
subject { described_class.create_from_wkt(wkt) }
|
6
|
+
let(:wkt) { 'POINT (1 2)' }
|
7
|
+
|
8
|
+
let(:another_point) do
|
9
|
+
a = described_class.create_from_wkt('POINT (2 3)')
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:same_point) do
|
13
|
+
described_class.create_from_wkt(wkt)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#dimension' do
|
17
|
+
specify { expect(subject.dimension).to be_zero }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#type' do
|
21
|
+
specify { expect(subject.type).to eq :wkbPoint }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#type_to_name' do
|
25
|
+
specify { expect(subject.type_to_name).to eq 'Point' }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#name' do
|
29
|
+
specify { expect(subject.name).to eq 'POINT' }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'non-empty point' do
|
33
|
+
describe '#coordinate_dimension' do
|
34
|
+
specify { expect(subject.coordinate_dimension).to eq 2 }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#envelope' do
|
38
|
+
it 'returns an OGR::Envelope' do
|
39
|
+
expect(subject.envelope).to be_a OGR::Envelope
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#count' do
|
44
|
+
specify { expect(subject.count).to be_zero }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#point_count' do
|
48
|
+
specify { expect(subject.point_count).to eq 1 }
|
49
|
+
end
|
50
|
+
|
51
|
+
# describe '#centroid' do
|
52
|
+
# it 'returns 0' do
|
53
|
+
# expect(subject.centroid.point).to eq(subject.point)
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
describe '#equals?' do
|
58
|
+
context 'a point with same coordinates' do
|
59
|
+
it 'returns true' do
|
60
|
+
expect(subject.equals?(same_point)).to eq true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'a point with difference coordinates' do
|
65
|
+
it 'returns false' do
|
66
|
+
expect(subject.equals?(another_point)).to eq false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#intersects?' do
|
72
|
+
context 'a point with same coordinates' do
|
73
|
+
it 'returns true' do
|
74
|
+
expect(subject.intersects?(same_point)).to eq true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'a point with difference coordinates' do
|
79
|
+
it 'returns false' do
|
80
|
+
expect(subject.intersects?(another_point)).to eq false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#disjoint?' do
|
86
|
+
context 'a point with same coordinates' do
|
87
|
+
it 'returns false' do
|
88
|
+
expect(subject.disjoint?(same_point)).to eq false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'a point with difference coordinates' do
|
93
|
+
it 'returns true' do
|
94
|
+
expect(subject.disjoint?(another_point)).to eq true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#touches?' do
|
100
|
+
context 'a point with same coordinates' do
|
101
|
+
# Not sure why this returns false...
|
102
|
+
it 'returns false' do
|
103
|
+
expect(subject.touches?(same_point)).to eq false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'a point with difference coordinates' do
|
108
|
+
it 'returns false' do
|
109
|
+
expect(subject.touches?(another_point)).to eq false
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#crosses?' do
|
115
|
+
context 'a point with same coordinates' do
|
116
|
+
it 'returns false' do
|
117
|
+
expect(subject.crosses?(same_point)).to eq false
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'a point with difference coordinates' do
|
122
|
+
it 'returns false' do
|
123
|
+
expect(subject.crosses?(another_point)).to eq false
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '#within?' do
|
129
|
+
context 'a point with same coordinates' do
|
130
|
+
it 'returns true' do
|
131
|
+
expect(subject.within?(same_point)).to eq true
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'a point with difference coordinates' do
|
136
|
+
it 'returns false' do
|
137
|
+
expect(subject.within?(another_point)).to eq false
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '#contains?' do
|
143
|
+
context 'a point with same coordinates' do
|
144
|
+
it 'returns true' do
|
145
|
+
expect(subject.contains?(same_point)).to eq true
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'a point with difference coordinates' do
|
150
|
+
it 'returns false' do
|
151
|
+
expect(subject.contains?(another_point)).to eq false
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '#overlaps?' do
|
157
|
+
context 'a point with same coordinates' do
|
158
|
+
it 'returns false' do
|
159
|
+
expect(subject.overlaps?(same_point)).to eq false
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'a point with difference coordinates' do
|
164
|
+
it 'returns false' do
|
165
|
+
expect(subject.overlaps?(another_point)).to eq false
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe '#empty?' do
|
171
|
+
it 'returns false' do
|
172
|
+
expect(subject.empty?).to eq false
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe '#valid?' do
|
177
|
+
it 'returns true' do
|
178
|
+
expect(subject.valid?).to eq true
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe '#simple?' do
|
183
|
+
it 'returns true' do
|
184
|
+
expect(subject.simple?).to eq true
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe '#ring?' do
|
189
|
+
it 'returns false' do
|
190
|
+
expect(subject.ring?).to eq false
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#polygonize' do
|
195
|
+
it 'returns nil' do
|
196
|
+
expect(subject.polygonize).to be_nil
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe '#x' do
|
201
|
+
it 'returns the x value' do
|
202
|
+
expect(subject.x).to eq 1
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe '#y' do
|
207
|
+
it 'returns the y value' do
|
208
|
+
expect(subject.y).to eq 2
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe '#point' do
|
213
|
+
it 'returns x & y as an array' do
|
214
|
+
expect(subject.point).to eq([1, 2])
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe '#set_point' do
|
219
|
+
it 'changes the x & y values' do
|
220
|
+
expect {
|
221
|
+
subject.set_point(5, 6)
|
222
|
+
}.to change { subject.points }.
|
223
|
+
from([[1, 2]]).to([[5.0, 6.0, 0.0]])
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe '#add_point' do
|
228
|
+
it 'changes the x & y values' do
|
229
|
+
expect {
|
230
|
+
subject.add_point(5, 6)
|
231
|
+
}.to change { subject.points }.
|
232
|
+
from([[1, 2]]).to([[5.0, 6.0, 0.0]])
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe '#empty!' do
|
237
|
+
it 'clears the point' do
|
238
|
+
expect {
|
239
|
+
subject.empty!
|
240
|
+
}.to change { subject.points }.
|
241
|
+
from([[1, 2]]).to([[]])
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'empty point' do
|
247
|
+
let(:wkt) { 'POINT EMPTY' }
|
248
|
+
|
249
|
+
describe '#coordinate_dimension' do
|
250
|
+
specify { expect(subject.coordinate_dimension).to eq 0 }
|
251
|
+
end
|
252
|
+
|
253
|
+
describe '#count' do
|
254
|
+
specify { expect(subject.count).to be_zero }
|
255
|
+
end
|
256
|
+
|
257
|
+
describe '#point_count' do
|
258
|
+
specify { expect(subject.point_count).to be_zero }
|
259
|
+
end
|
260
|
+
|
261
|
+
describe '#empty?' do
|
262
|
+
it 'returns true' do
|
263
|
+
expect(subject.empty?).to eq true
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
describe '#valid?' do
|
268
|
+
it 'returns true' do
|
269
|
+
expect(subject.valid?).to eq true
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
describe '#simple?' do
|
274
|
+
it 'returns true' do
|
275
|
+
expect(subject.simple?).to eq true
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
describe '#x' do
|
280
|
+
it 'returns nil' do
|
281
|
+
expect(subject.x).to be_nil
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
describe '#y' do
|
286
|
+
it 'returns nil' do
|
287
|
+
expect(subject.x).to be_nil
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe '#point' do
|
292
|
+
it 'returns an empty array' do
|
293
|
+
expect(subject.point).to eq([])
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
describe '#set_point' do
|
298
|
+
it 'changes the x & y values' do
|
299
|
+
expect {
|
300
|
+
subject.set_point(5, 6)
|
301
|
+
}.to change { subject.points }.
|
302
|
+
from([[]]).to([[5.0, 6.0, 0.0]])
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
describe '#add_point' do
|
307
|
+
it 'changes the x & y values' do
|
308
|
+
expect {
|
309
|
+
subject.add_point(5, 6)
|
310
|
+
}.to change { subject.points }.
|
311
|
+
from([[]]).to([[5.0, 6.0, 0.0]])
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe '#envelope' do
|
316
|
+
it 'returns nil' do
|
317
|
+
expect(subject.envelope).to be_nil
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
data/testing_gdal.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'RMagick'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'pry'
|
4
|
+
require 'ffi-gdal'
|
5
|
+
|
6
|
+
GDAL::Logger.logging_enabled = true
|
7
|
+
|
8
|
+
#proj = 'MULTIPOLYGON (((-120.03296317083633 44.226828996384285, -120.03199741570855 44.230616638863914, -120.03305119285443 44.23322276021398, -120.03305439612939 44.23323503554639, -120.03305423080232 44.233247523039175, -120.03305070309673 44.23325975261691, -120.03304394580853 44.233271263913274, -120.03303421330706 44.233281623601044, -120.0330218719597 44.23329044170392, -120.03300738634044 44.23329738627662, -120.03299130174162 44.23330219590042, -120.03297422364709 44.23330468952384, -120.03295679493954 44.23330477327791, -120.0329396717 44.23330244400986, -120.03259652218235 44.23323046886841, -120.03259605091168 44.23323469214073, -120.03259130838445 44.233246748969734, -120.03258339633375 44.23325791928269, -120.03257261443646 44.233267779993575, -120.03255937106756 44.233275957618844, -120.03254416783288 44.23328214242357, -120.03252758057009 44.23328610015274, -120.03251023753826 44.2332876809039, -120.032492795622 44.23328682480475, -120.0324759154512 44.23328356428076, -120.03246023637918 44.23327802282714, -120.03244635226639 44.233270410331386, -120.03229057481504 44.233166296752856, -120.03144275436163 44.23298846700243, -120.03135705202111 44.23542539118272, -120.03135483571377 44.23543806847976, -120.0313491680669 44.2354501823413, -120.0313402724131 44.23546125542315, -120.03132849928409 44.23547085139311, -120.03131431259804 44.235478592124444, -120.03129827137883 44.235484172595754, -120.03128100772805 44.23548737291011, -120.03126320191683 44.23548806696012, -120.03124555558011 44.235486227396926, -120.03122876406881 44.235481926707976, -120.03121348904955 44.23547533436071, -120.03120033243181 44.23546671012462, -120.03118981264993 44.23545639383555, -120.02629194435607 44.229488174527326, -120.0262841759258 44.22947593881562, -120.0262801234077 44.229462813795166, -120.02627996353844 44.22944937186798, -120.0262837032901 44.22943619925734, -120.02629117956641 44.22942387044152, -120.02630206631528 44.22941292309999, -120.02631588874878 44.229403834664076, -120.02650834059244 44.22930162063937, -120.02596466290531 44.22893822933382, -120.02595288197551 44.22892861642798, -120.02594398682248 44.22891752390089, -120.02593832881524 44.2289053899198, -120.02593613145164 44.22889269379079, -120.02593748153026 44.22887993702566, -120.02594232572132 44.2288676235318, -120.02595047267361 44.22885623970722, -120.0259616005729 44.228846235226946, -120.02597526985406 44.22883800528063, -120.0259909405644 44.22883187496161, -120.02600799369236 44.22882808642537, -120.02602575561929 44.228826789324046, -120.02604352472815 44.22882803489487, -120.02606059911827 44.2288317739361, -120.02607630433104 44.22883785875077, -120.02675839864344 44.229168810839475, -120.02688733695234 44.22910032953997, -120.02611125484312 44.228061533840545, -120.02610457348571 44.22805003875662, -120.02610110582951 44.22803783693943, -120.02610098163969 44.228025384999874, -120.02610420556363 44.2280131489091, -120.02611065695699 44.22800158656121, -120.0261200943985 44.22799113063793, -120.02613216472427 44.22798217241707, -120.02614641624366 44.227975047130094, -120.0261623156424 44.22797002141719, -120.02617926794002 44.22796728334896, -120.0261966387548 44.227966935388565, -120.02621377804353 44.22796899055725, -120.02623004442708 44.22797337194719, -120.0262448291917 44.2279799155993, -120.02625757906833 44.22798837663918, -120.02626781693645 44.22799843844071, -120.02754662923428 44.229551257921585, -120.030836241635 44.23114734101261, -120.03136956622194 44.229959117652726, -120.03138391393463 44.22955111324294, -120.03138620312208 44.229538207384174, -120.0313920671636 44.22952589494864, -120.03140126651873 44.229514678887824, -120.03141342540293 44.229505017367465, -120.03142804713777 44.22949730505196, -120.03144453443974 44.229491856982676, -120.03146221381887 44.22948889570851, -120.03148036308987 44.22948854219496, -120.03149824087296 44.229490810882744, -120.03151511687828 44.22949560909792, -120.03153030173767 44.22950274083756, -120.03154317516459 44.22951191477631, -120.0315532112922 44.22952275616695, -120.03156000257852 44.22953482814357, -120.03278854263438 44.22679758476189, -120.03286127379035 44.226512326846944, -120.03286465252121 44.226503048718484, -120.03286991708133 44.22649423317623, -120.03301731535839 44.22629080564284, -120.03302703028369 44.22628013425537, -120.03303948802117 44.22627104306898, -120.03305420051213 44.22626388825138, -120.03307059136289 44.22625895010873, -120.0330880184265 44.22625642210408, -120.03310579896007 44.22625640327766, -120.03312323637284 44.226258894367135, -120.03313964751646 44.22626379777834, -120.03315438944897 44.22627092140904, -120.03316688462326 44.22627998617475, -120.03317664351395 44.22629063694302, -120.03318328379541 44.22630245644617, -120.03318654532022 44.226314981629145, -120.03318630031114 44.22632772179051, -120.0331825583669 44.22634017780693, -120.03296317083633 44.226828996384285)))'
|
9
|
+
|
10
|
+
floyd_too_big_wkt = 'MULTIPOLYGON (((-87.55634718933241 31.168633650404765, -87.552227316286 31.16870709121005, -87.55234533348232 31.169808696448463, -87.5478606800096 31.1698913163249, -87.54777484932141 31.168679550914895, -87.54380517997858 31.168615290194918, -87.54396611251944 31.16511760526154, -87.55647593536513 31.164906454793982, -87.55634718933241 31.168633650404765)))'
|
11
|
+
floyd_wkt = 'MULTIPOLYGON (((-87.5530099868775 31.16710573359053,-87.5530099868775 31.165600160261103,-87.55384683609009 31.16710573359053,-87.5530099868775 31.16710573359053)))'
|
12
|
+
floyd_srid = 4326
|
13
|
+
|
14
|
+
harper_path = '/Users/sloveless/Development/projects/ffi-gdal/spec/support/images/Harper/Harper_1058_20140612_NRGB.tif'
|
15
|
+
harper = GDAL::Dataset.open(harper_path, 'r')
|
16
|
+
|
17
|
+
floyd_path = '/Users/sloveless/Development/projects/ffi-gdal/spec/support/images/Floyd/Floyd_1058_20140612_NRGB.tif'
|
18
|
+
floyd = GDAL::Dataset.open(floyd_path, 'r')
|
19
|
+
|
20
|
+
spatial_ref = OGR::SpatialReference.new(floyd.projection)
|
21
|
+
floyd_geometry = OGR::Geometry.create_from_wkt(floyd_wkt, spatial_ref)
|
22
|
+
|
23
|
+
usg_path = '/Users/sloveless/Development/projects/ffi-gdal/spec/support/images/osgeo/geotiff/usgs/c41078a1.tif'
|
24
|
+
usg = GDAL::Dataset.open(usg_path, 'r')
|
25
|
+
|
26
|
+
world_file_path = "#{__dir__}/spec/support/worldfiles/SR_50M/SR_50M.tif"
|
27
|
+
world_file = GDAL::GeoTransform.from_world_file(world_file_path, 'tfw')
|
28
|
+
|
29
|
+
binding.pry
|
30
|
+
|
31
|
+
def extract_ndvi(dataset, destination_path, wkt_geometry)
|
32
|
+
nir_band = dataset.raster_band(1)
|
33
|
+
red_band = dataset.raster_band(2)
|
34
|
+
nir_array = nir_band.to_na
|
35
|
+
red_array = red_band.to_na
|
36
|
+
|
37
|
+
# Create an OGR::Geometry from the WKT and convert to dataset's projection.
|
38
|
+
wkt_spatial_ref = OGR::SpatialReference.new_from_epsg(4326)
|
39
|
+
geometry = OGR::Geometry.create_from_wkt(wkt_geometry,
|
40
|
+
wkt_spatial_ref)
|
41
|
+
geometry.transform_to!(dataset.spatial_reference)
|
42
|
+
|
43
|
+
# Create the geo_tranform for the geometry-raster, based on the original
|
44
|
+
# dataset's geo_transform.
|
45
|
+
pixel_extent = geometry.envelope.world_to_pixel(dataset.geo_transform)
|
46
|
+
p pixel_extent
|
47
|
+
pixel_height = pixel_extent[:x_max]
|
48
|
+
pixel_width = pixel_extent[:y_max]
|
49
|
+
|
50
|
+
y_range = pixel_extent[:y_origin]..(pixel_extent[:y_max] - 1)
|
51
|
+
x_range = pixel_extent[:x_origin]...(pixel_extent[:x_max] - 1)
|
52
|
+
red_clip_array = red_array[x_range, y_range]
|
53
|
+
nir_clip_array = nir_array[x_range, y_range]
|
54
|
+
|
55
|
+
|
56
|
+
#geo = GDAL::GeoTransform.new
|
57
|
+
geo = dataset.geo_transform
|
58
|
+
#geo.x_origin = dataset.geo_transform.x_origin + pixel_extent[:x_origin]
|
59
|
+
geo.x_origin = pixel_extent[:x_origin]
|
60
|
+
geo.pixel_width = pixel_extent[:pixel_width]
|
61
|
+
geo.x_rotation = 0
|
62
|
+
|
63
|
+
#geo.y_origin = dataset.geo_transform.y_origin + pixel_extent[:y_origin]
|
64
|
+
#geo.y_origin = pixel_extent[:y_origin]
|
65
|
+
geo.y_origin = pixel_extent[:y_max].abs # the book shows this--is it right?
|
66
|
+
geo.pixel_height = pixel_extent[:pixel_height]
|
67
|
+
geo.y_rotation = 0
|
68
|
+
|
69
|
+
# Get pixels for each point of each linear ring in the geometry.
|
70
|
+
pixels = case geometry.type
|
71
|
+
when :wkbMultiPolygon
|
72
|
+
polygon = geometry.geometry_at(0)
|
73
|
+
linear_ring = polygon.geometry_at(0)
|
74
|
+
#linear_ring.pixels(dataset.geo_transform)
|
75
|
+
linear_ring.pixels(geo)
|
76
|
+
else
|
77
|
+
raise 'bleh'
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
# Write the pixels to an array at the size of the new image
|
82
|
+
image = Magick::Image.new(pixel_extent[:x_max], pixel_extent[:y_max])
|
83
|
+
poly = Magick::Draw.new
|
84
|
+
poly.fill('#00ffff')
|
85
|
+
poly.polygon(*pixels)
|
86
|
+
poly.draw(image)
|
87
|
+
image.write('bobo.tif')
|
88
|
+
|
89
|
+
excerpted_image = image.excerpt(pixel_extent[:x_origin], pixel_extent[:y_origin],
|
90
|
+
pixel_extent[:pixel_count], pixel_extent[:line_count])
|
91
|
+
# rasterized_pixels = excerpted_image.export_pixels(0, 0,
|
92
|
+
# pixel_extent[:pixel_count], pixel_extent[:line_count], 'I')
|
93
|
+
rasterized_pixels = image.export_pixels(pixel_extent[:x_origin], pixel_extent[:y_origin],
|
94
|
+
pixel_extent[:pixel_count], pixel_extent[:line_count], 'I')
|
95
|
+
mask = NArray[rasterized_pixels]
|
96
|
+
mask.reshape!(pixel_extent[:pixel_count], pixel_extent[:line_count])
|
97
|
+
p mask.to_a.flatten.count { |b| !b.zero? }
|
98
|
+
p red_clip_array.to_a.flatten.count { |b| !b.zero? }
|
99
|
+
p nir_clip_array.to_a.flatten.count { |b| !b.zero? }
|
100
|
+
|
101
|
+
|
102
|
+
i = 0
|
103
|
+
red_clip_array.each do |_|
|
104
|
+
if mask[i] == 65535
|
105
|
+
red_clip_array[i] = 1.0
|
106
|
+
end
|
107
|
+
|
108
|
+
i += 1
|
109
|
+
end
|
110
|
+
|
111
|
+
i = 0
|
112
|
+
nir_clip_array.each do |_|
|
113
|
+
if mask[i] == 65535
|
114
|
+
nir_clip_array[i] = 1.0
|
115
|
+
end
|
116
|
+
|
117
|
+
i += 1
|
118
|
+
end
|
119
|
+
|
120
|
+
p mask.flatten.to_a.count { |b| !b.zero? }
|
121
|
+
p red_clip_array.to_a.flatten.count { |b| !b.zero? }
|
122
|
+
p nir_clip_array.to_a.flatten.count { |b| !b.zero? }
|
123
|
+
|
124
|
+
binding.pry
|
125
|
+
#ndvi_array = 1.0 * (nir_array - red_array) / nir_array + red_array + 1.0
|
126
|
+
ndvi_array = 1.0 * (nir_clip_array - red_clip_array) / (nir_clip_array + red_clip_array) + 1.0
|
127
|
+
#ndvi_array = (nir_clip_array - red_clip_array) / (nir_clip_array + red_clip_array)
|
128
|
+
|
129
|
+
driver = GDAL::Driver.by_name('GTiff')
|
130
|
+
ndvi_dataset = driver.create_dataset('ndvi.tif', pixel_extent[:x_max], pixel_extent[:y_max]) do |ndvi|
|
131
|
+
ndvi.projection = dataset.projection
|
132
|
+
ndvi.geo_transform = geo
|
133
|
+
|
134
|
+
ndvi_band = ndvi.raster_band(1)
|
135
|
+
# tmp_band.write_array(mask, x_offset: pixel_extent[:x_origin].abs,
|
136
|
+
# y_offset: pixel_extent[:y_origin].abs, data_type: :GDT_Float32)
|
137
|
+
#ndvi_band.write_array(ndvi_array, data_type: :GDT_Float32)
|
138
|
+
ndvi_band.write_array(ndvi_array)
|
139
|
+
#ndvi_band.no_data_value = -9999
|
140
|
+
end
|
141
|
+
|
142
|
+
ndvi_dataset.close
|
143
|
+
|
144
|
+
# Create new dataset from the geometry
|
145
|
+
#tmp_dataset.rasterize_geometries!(1, linear_ring, 1000)
|
146
|
+
|
147
|
+
#binding.pry
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
#floyd.image_warp('meow.tif', 'GTiff', 1, cutline: floyd_geometry )
|
152
|
+
#extract_ndvi(floyd, 'ndvi.tif', floyd_wkt)
|
153
|
+
|
154
|
+
def warp_to_geometry(dataset, wkt_geometry)
|
155
|
+
|
156
|
+
# Create an OGR::Geometry from the WKT and convert to dataset's projection.
|
157
|
+
wkt_spatial_ref = OGR::SpatialReference.new_from_epsg(4326)
|
158
|
+
geometry = OGR::Geometry.create_from_wkt(wkt_geometry, wkt_spatial_ref)
|
159
|
+
geometry.transform_to!(dataset.spatial_reference)
|
160
|
+
|
161
|
+
binding.pry
|
162
|
+
# Create a .shp from the geometry
|
163
|
+
shape = geometry.to_vector('geom.shp', 'ESRI Shapefile',
|
164
|
+
spatial_reference: dataset.spatial_reference)
|
165
|
+
shape.close
|
166
|
+
end
|
167
|
+
|
168
|
+
#warp_to_geometry(floyd, floyd_wkt)
|