ffi-gdal 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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/lib/ffi/gdal.rb ADDED
@@ -0,0 +1,607 @@
1
+ require 'ffi'
2
+ require_relative 'gdal/version'
3
+ require_relative 'gdal/cpl_conv'
4
+ require_relative 'gdal/cpl_error'
5
+ require_relative 'gdal/cpl_string'
6
+ require_relative 'gdal/cpl_vsi'
7
+ require_relative 'gdal/gdal_color_entry'
8
+ require_relative 'gdal/gdal_gcp'
9
+ require_relative 'gdal/ogr_core'
10
+ require_relative 'gdal/ogr_api'
11
+ require_relative 'gdal/ogr_srs_api'
12
+ require_relative '../ext/to_bool'
13
+
14
+ module FFI
15
+ module GDAL
16
+ extend ::FFI::Library
17
+ ffi_lib 'gdal'
18
+
19
+ include CPLError
20
+ include CPLConv
21
+ include CPLString
22
+ include CPLVSI
23
+ include OGRCore
24
+ include OGRAPI
25
+ include OGRSRSAPI
26
+
27
+ #-----------------------------------------------------------------
28
+ # Defines
29
+ #-----------------------------------------------------------------
30
+ GDALMD_AREA_OR_POINT = 'AREA_OR_POINT'
31
+ GDALMD_AOP_AREA = 'Area'
32
+ GDALMD_AOP_POINT = 'Point'
33
+
34
+ CPLE_WrongFormat = 200
35
+
36
+ GDAL_DMD_LONGNAME = 'DMD_LONGNAME'
37
+ GDAL_DMD_HELPTOPIC = 'DMD_HELPTOPIC'
38
+ GDAL_DMD_MIMETYPE = 'DMD_MIMETYPE'
39
+ GDAL_DMD_EXTENSION = 'DMD_EXTENSION'
40
+ GDAL_DMD_EXTENSIONS = 'DMD_EXTENSIONS'
41
+ GDAL_DMD_CREATIONOPTIONLIST = 'DMD_CREATIONOPTIONLIST'
42
+ GDAL_DMD_OPTIONLIST = 'DMD_OPTIONLIST'
43
+ GDAL_DMD_CREATIONDATATYPES = 'DMD_CREATIONDATATYPES'
44
+ GDAL_DMD_SUBDATASETS = 'DMD_SUBDATASETS'
45
+
46
+ GDAL_DCAP_OPEN = 'DCAP_OPEN'
47
+ GDAL_DCAP_CREATE = 'DCAP_CREATE'
48
+ GDAL_DCAP_CREATECOPY = 'DCAP_CREATECOPY'
49
+ GDAL_DCAP_VIRTUALIO = 'DCAP_VIRTUALIO'
50
+ GDAL_DCAP_RASTER = 'DCAP_RASTER'
51
+ GDAL_DCAP_VECTOR = 'DCAP_VECTOR'
52
+
53
+ GDAL_OF_READONLY = 0x00
54
+ GDAL_OF_UPDATE = 0x01
55
+ GDAL_OF_ALL = 0x00
56
+ GDAL_OF_RASTER = 0x02
57
+ GDAL_OF_VECTOR = 0x04
58
+ GDAL_OF_SHARED = 0x20
59
+ GDAL_OF_VERBOSE_ERROR = 0x40
60
+
61
+ GDAL_DS_LAYER_CREATIONOPTIONLIST= 'DS_LAYER_CREATIONOPTIONLIST'
62
+
63
+ GMF_ALL_VALID = 0x01
64
+ GMF_PER_DATASET = 0x02
65
+ GMF_ALPHA = 0x04
66
+ GMF_NODATA = 0x08
67
+
68
+ def srcval(popo_source, e_src_type, ii)
69
+ end
70
+
71
+ def gdal_check_version(psz_calling_component_name)
72
+ end
73
+
74
+ #-----------------------------------------------------------------
75
+ # Enums
76
+ #-----------------------------------------------------------------
77
+ GDALDataType = enum :GDT_Unknown, 0,
78
+ :GDT_Byte, 1,
79
+ :GDT_UInt16, 2,
80
+ :GDT_Int16, 3,
81
+ :GDT_UInt32, 4,
82
+ :GDT_Int32, 5,
83
+ :GDT_Float32, 6,
84
+ :GDT_Float64, 7,
85
+ :GDT_CInt16, 8,
86
+ :GDT_CInt32, 9,
87
+ :GDT_CFloat32, 10,
88
+ :GDT_CFloat64, 11,
89
+ :GDT_TypeCount, 12
90
+
91
+ GDALAsyncStatusType = enum :GARIO_PENDING, 0,
92
+ :GARIO_UPDATE, 1,
93
+ :GARIO_ERROR, 2,
94
+ :GARIO_COMPLETE, 3,
95
+ :GARIO_TypeCount, 4
96
+
97
+ GDALAccess = enum :GA_ReadOnly, 0,
98
+ :GA_update, 1
99
+
100
+ GDALRWFlag = enum :GF_Read, 0,
101
+ :GF_Write, 1
102
+
103
+ GDALColorInterp = enum :GCI_Undefined, 0,
104
+ :GCI_GrayIndex, 1,
105
+ :GCI_PaletteIndex, 2,
106
+ :GCI_RedBand, 3,
107
+ :GCI_GreenBand, 4,
108
+ :GCI_BlueBand, 5,
109
+ :GCI_AlphaBand, 6,
110
+ :GCI_HueBand, 7,
111
+ :GCI_SaturationBand, 8,
112
+ :GCI_LightnessBand, 9,
113
+ :GCI_CyanBand, 10,
114
+ :GCI_MagentaBand, 11,
115
+ :GCI_YellowBand, 12,
116
+ :GCI_BlackBand, 13,
117
+ :GCI_YCbCr_YBand, 14,
118
+ :GCI_YCbCr_CbBand, 15,
119
+ :GCI_YCbCr_CrBand, 16,
120
+ :GCI_Max, 16 # Seems wrong that this is also 16...
121
+
122
+ GDALPaletteInterp = enum :GPI_Gray, 0,
123
+ :GPI_RGB, 1,
124
+ :GPI_CMYK, 2,
125
+ :GPI_HLS, 3
126
+
127
+ GDALRATFieldType = enum :GFT_Integer,
128
+ :GFT_Real,
129
+ :GFT_String
130
+
131
+ GDALRATFieldUsage = enum :GFU_Generic, 0,
132
+ :GFU_PixelCount, 1,
133
+ :GFU_Name, 2,
134
+ :GFU_Min, 3,
135
+ :GFU_Max, 4,
136
+ :GFU_MinMax, 5,
137
+ :GFU_Red, 6,
138
+ :GFU_Green, 7,
139
+ :GFU_Blue, 8,
140
+ :GFU_Alpha, 9,
141
+ :GFU_RedMin, 10,
142
+ :GFU_GreenMin, 11,
143
+ :GFU_BlueMin, 12,
144
+ :GFU_AlphaMin, 13,
145
+ :GFU_RedMax, 14,
146
+ :GFU_GreenMax, 15,
147
+ :GFU_BlueMax, 16,
148
+ :GFU_AlphaMax, 17,
149
+ :GFU_MaxCount
150
+
151
+ GDALTileOrganization = enum :GTO_TIP,
152
+ :GTO_BIT,
153
+ :GTO_BSQ
154
+
155
+ #-----------------------------------------------------------------
156
+ # typedefs
157
+ #-----------------------------------------------------------------
158
+ typedef :pointer, :GDALMajorObjectH
159
+ typedef :pointer, :GDALDatasetH
160
+ typedef :pointer, :GDALRasterBandH
161
+ typedef :pointer, :GDALDriverH
162
+ typedef :pointer, :GDALColorTableH
163
+ typedef :pointer, :GDALRasterAttributeTableH
164
+ typedef :pointer, :GDALAsyncReaderH
165
+ #typedef :pointer, :OGRGeometryH
166
+
167
+ #-----------------------------------------------------------------
168
+ # functions
169
+ #-----------------------------------------------------------------
170
+ # @param completion [Float]
171
+ # @param message [String]
172
+ # @param progress_arg [Pointer]
173
+ # @return [Boolean] true if the operation should continue; false if the
174
+ # user has cancelled.
175
+ callback :GDALProgressFunc, [:double, :string, :pointer], :bool
176
+
177
+ callback :GDALDerivedPixelFunc,
178
+ [:pointer, :int, :pointer, :int, :int, GDALDataType, GDALDataType, :int, :int],
179
+ :int
180
+
181
+ attach_function :GDALVersionInfo, %i[string], :string
182
+
183
+ # DataType
184
+ attach_function :GDALGetDataTypeSize, [GDALDataType], :int
185
+ attach_function :GDALDataTypeIsComplex, [GDALDataType], :int
186
+ attach_function :GDALGetDataTypeName, [GDALDataType], :string
187
+ attach_function :GDALGetDataTypeByName, [:string], GDALDataType
188
+ attach_function :GDALDataTypeUnion, [GDALDataType, GDALDataType], GDALDataType
189
+
190
+ # AsyncStatus
191
+ attach_function :GDALGetAsyncStatusTypeName, [GDALAsyncStatusType], :string
192
+ attach_function :GDALGetAsyncStatusTypeByName, [:string], GDALAsyncStatusType
193
+
194
+ # ColorInterpretation
195
+ attach_function :GDALGetColorInterpretationName, [GDALColorInterp], :string
196
+ attach_function :GDALGetColorInterpretationByName, [:string], GDALColorInterp
197
+
198
+ # PaletteInterpretation
199
+ attach_function :GDALGetPaletteInterpretationName, [GDALPaletteInterp], :string
200
+ attach_function :GDALGetPaletteInterpretation, [:GDALColorTableH], GDALPaletteInterp
201
+ attach_function :GDALGetColorEntryCount, [:GDALColorTableH], :int
202
+ attach_function :GDALGetColorEntry, [:GDALColorTableH, :int], GDALColorEntry.ptr
203
+ attach_function :GDALGetColorEntryAsRGB, [:GDALColorTableH, :int, GDALColorEntry], :int
204
+
205
+ attach_function :GDALAllRegister, [], :void
206
+ attach_function :GDALCreate,
207
+ [:GDALDriverH, :string, :int, :int, :int, GDALDataType, :pointer],
208
+ :GDALDatasetH
209
+ attach_function :GDALCreateCopy,
210
+ [:GDALDriverH, :string, :GDALDatasetH, :int, :pointer, :GDALProgressFunc, :pointer],
211
+ :GDALDatasetH
212
+ attach_function :GDALIdentifyDriver,
213
+ [:string, :pointer],
214
+ :GDALDriverH
215
+ attach_function :GDALOpen, [:string, GDALAccess], :GDALDatasetH
216
+ attach_function :GDALOpenShared,
217
+ [:string, GDALAccess],
218
+ :GDALDatasetH
219
+ #attach_function :GDALOpenEx,
220
+ #[:string, :uint, :string, :string, :string],
221
+ #:GDALDatasetH
222
+
223
+ attach_function :GDALDumpOpenDatasets, [:pointer], :int
224
+ attach_function :GDALGetDriverByName, [:string], :GDALDriverH
225
+ attach_function :GDALGetDriverCount, [], :int
226
+ attach_function :GDALGetDriver, [:int], :GDALDriverH
227
+ attach_function :GDALDestroyDriver, [:GDALDriverH], :void
228
+ attach_function :GDALRegisterDriver, [:GDALDriverH], :int
229
+ attach_function :GDALDeregisterDriver, [:GDALDriverH], :void
230
+ attach_function :GDALDestroyDriverManager, [:void], :void
231
+ #attach_function :GDALDestroy, [], :void
232
+
233
+ attach_function :GDALDeleteDataset, [:GDALDriverH, :string], CPLErr
234
+ attach_function :GDALRenameDataset,
235
+ [:GDALDriverH, :string, :string],
236
+ CPLErr
237
+ attach_function :GDALCopyDatasetFiles,
238
+ [:GDALDriverH, :string, :string],
239
+ CPLErr
240
+
241
+ attach_function :GDALValidateCreationOptions,
242
+ [:GDALDriverH, :pointer],
243
+ CPLErr
244
+
245
+ attach_function :GDALGetDriverShortName, [:GDALDriverH], :string
246
+ attach_function :GDALGetDriverLongName, [:GDALDriverH], :string
247
+ attach_function :GDALGetDriverHelpTopic, [:GDALDriverH], :string
248
+ attach_function :GDALGetDriverCreationOptionList, [:GDALDriverH], :string
249
+
250
+ attach_function :GDALInitGCPs, [:int, :pointer], :void
251
+ attach_function :GDALDeinitGCPs, [:int, :pointer], :void
252
+ attach_function :GDALDuplicateGCPs, [:int, :pointer], :pointer
253
+ attach_function :GDALGCPsToGeoTransform,
254
+ [:int, :pointer, :pointer, :int],
255
+ :int
256
+ attach_function :GDALInvGeoTransform,
257
+ [:pointer, :pointer],
258
+ :int
259
+ attach_function :GDALApplyGeoTransform,
260
+ [:pointer, :double, :double, :pointer, :pointer],
261
+ :void
262
+ attach_function :GDALComposeGeoTransforms,
263
+ [:pointer, :pointer, :pointer],
264
+ :void
265
+
266
+ attach_function :GDALGetMetadataDomainList, [:GDALMajorObjectH], :pointer
267
+ attach_function :GDALGetMetadata, [:GDALMajorObjectH, :string], :pointer
268
+ attach_function :GDALSetMetadata,
269
+ [:GDALMajorObjectH, :pointer, :string],
270
+ CPLErr
271
+ attach_function :GDALGetMetadataItem,
272
+ [:GDALMajorObjectH, :string, :string],
273
+ :string
274
+ attach_function :GDALSetMetadataItem,
275
+ [:GDALMajorObjectH, :string, :string, :string],
276
+ CPLErr
277
+ attach_function :GDALGetDescription, [:GDALMajorObjectH], :string
278
+ attach_function :GDALSetDescription, [:GDALMajorObjectH, :string], :void
279
+
280
+ attach_function :GDALGetDatasetDriver, [:GDALMajorObjectH], :GDALDriverH
281
+ attach_function :GDALGetFileList, [:GDALDatasetH], :pointer
282
+ attach_function :GDALClose, [:GDALDatasetH], :void
283
+
284
+ #-----------------
285
+ # Raster functions
286
+ #-----------------
287
+ attach_function :GDALGetRasterXSize, [:GDALDatasetH], :int
288
+ attach_function :GDALGetRasterYSize, [:GDALDatasetH], :int
289
+ attach_function :GDALGetRasterCount, [:GDALDatasetH], :int
290
+ attach_function :GDALGetRasterBand, [:GDALDatasetH, :int], :GDALRasterBandH
291
+
292
+ attach_function :GDALAddBand,
293
+ [:GDALDatasetH, GDALDataType, :pointer],
294
+ CPLErr
295
+
296
+ attach_function :GDALBeginAsyncReader,
297
+ [
298
+ :GDALDatasetH,
299
+ GDALRWFlag,
300
+ :int,
301
+ :int,
302
+ :int,
303
+ :int,
304
+ :pointer,
305
+ :int,
306
+ :int,
307
+ GDALDataType,
308
+ :int,
309
+ :pointer,
310
+ :int,
311
+ :int,
312
+ :int
313
+ ], :GDALAsyncReaderH
314
+
315
+ attach_function :GDALEndAsyncReader,
316
+ [:GDALDatasetH, :GDALAsyncReaderH],
317
+ :void
318
+
319
+ attach_function :GDALDatasetRasterIO,
320
+ [
321
+ :GDALDatasetH,
322
+ GDALRWFlag,
323
+ :int,
324
+ :int,
325
+ :int,
326
+ :int,
327
+ :pointer,
328
+ :int,
329
+ :int,
330
+ GDALDataType,
331
+ :int,
332
+ :pointer,
333
+ :int,
334
+ :int,
335
+ :int
336
+ ], CPLErr
337
+
338
+ attach_function :GDALDatasetAdviseRead,
339
+ [
340
+ :GDALDatasetH,
341
+ :int,
342
+ :int,
343
+ :int,
344
+ :int,
345
+ :int,
346
+ :int,
347
+ GDALDataType,
348
+ :int,
349
+ :pointer,
350
+ :pointer
351
+ ], CPLErr
352
+
353
+ #-----------------
354
+ # Projection functions
355
+ #-----------------
356
+ attach_function :GDALGetProjectionRef, [:GDALDatasetH], :string
357
+ attach_function :GDALSetProjection, [:GDALDatasetH, :string], CPLErr
358
+ attach_function :GDALGetGeoTransform, [:GDALDatasetH, :pointer], CPLErr
359
+ attach_function :GDALSetGeoTransform,
360
+ [:GDALDatasetH, :pointer],
361
+ CPLErr
362
+ attach_function :GDALGetGCPCount, [:GDALDatasetH], :int
363
+ attach_function :GDALGetGCPProjection, [:GDALDatasetH], :string
364
+ attach_function :GDALGetGCPs, [:GDALDatasetH], :pointer
365
+ attach_function :GDALSetGCPs,
366
+ [:GDALDatasetH, :int, :pointer, :string],
367
+ CPLErr
368
+
369
+ attach_function :GDALGetInternalHandle, [:GDALDatasetH, :string], :pointer
370
+ attach_function :GDALReferenceDataset, [:GDALDatasetH], :int
371
+ attach_function :GDALDereferenceDataset, [:GDALDatasetH], :int
372
+
373
+ attach_function :GDALBuildOverviews,
374
+ [
375
+ :GDALDatasetH,
376
+ :string,
377
+ :int,
378
+ :pointer,
379
+ :int,
380
+ :pointer,
381
+ :GDALProgressFunc,
382
+ :pointer
383
+ ], CPLErr
384
+
385
+ attach_function :GDALGetOpenDatasets, [:pointer, :pointer], :void
386
+ attach_function :GDALGetAccess, [:GDALDatasetH], :int
387
+ attach_function :GDALFlushCache, [:GDALDatasetH], :void
388
+ attach_function :GDALCreateDatasetMaskBand, [:GDALDatasetH, :int], CPLErr
389
+ attach_function :GDALDatasetCopyWholeRaster,
390
+ [:GDALDatasetH, :GDALDatasetH, :pointer, :GDALProgressFunc, :pointer],
391
+ CPLErr
392
+ attach_function :GDALRasterBandCopyWholeRaster,
393
+ [
394
+ :GDALRasterBandH,
395
+ :GDALRasterBandH,
396
+ :pointer,
397
+ :GDALProgressFunc,
398
+ :pointer
399
+ ], CPLErr
400
+ attach_function :GDALRegenerateOverviews,
401
+ [
402
+ :GDALRasterBandH,
403
+ :int,
404
+ :pointer,
405
+ :string,
406
+ :GDALProgressFunc,
407
+ :pointer
408
+ ], CPLErr
409
+ attach_function :GDALGetMaskBand, [:GDALRasterBandH], :GDALRasterBandH
410
+ attach_function :GDALGetMaskFlags, [:GDALRasterBandH], :int
411
+ #attach_function :GDALDatasetGetLayerCount, [:GDALDatasetH], :int
412
+ #attach_function :GDALDatasetGetLayer, [:GDALDatasetH, :int], :OGRLayerH
413
+ #attach_function :GDALDatasetGetLayerByName, [:GDALDatasetH, :string], :OGRLayerH
414
+ #attach_function :GDALDatasetDeleteLayer, [:GDALDatasetH, :int], :OGRErr
415
+ #attach_function :GDALDatasetCreateLayer
416
+ #attach_function :GDALDatasetCopyLayer
417
+ #attach_function :GDALDatasetTestCapability, [:GDALDatasetH, :string], :int
418
+ #attach_function :GDALDatasetExecuteSQL,
419
+ # [:GDALDatasetH, :string, :OGRGeometryH, :string],
420
+ # :int
421
+ #attach_function :GDALDatasetReleaseResultSet
422
+ #attach_function :GDALDatasetGetStyleTable, [:GDALDatasetH], :OGRStyleTableH
423
+ #attach_function :GDALDatasetSetStyleTableDirectly
424
+ #attach_function :GDALDatasetSetStyleTable
425
+
426
+ attach_function :GDALGetRasterDataType, [:GDALRasterBandH], GDALDataType
427
+ attach_function :GDALGetBlockSize,
428
+ [:GDALRasterBandH, :pointer, :pointer],
429
+ GDALDataType
430
+
431
+ attach_function :GDALRasterAdviseRead,
432
+ [
433
+ :GDALRasterBandH,
434
+ :int,
435
+ :int,
436
+ :int,
437
+ :int,
438
+ :int,
439
+ :int,
440
+ GDALDataType,
441
+ :pointer
442
+ ], CPLErr
443
+
444
+ attach_function :GDALRasterIO,
445
+ [
446
+ :GDALRasterBandH,
447
+ GDALRWFlag,
448
+ :int,
449
+ :int,
450
+ :int,
451
+ :int,
452
+ :pointer,
453
+ :int,
454
+ :int,
455
+ GDALDataType,
456
+ :int,
457
+ :int
458
+ ], CPLErr
459
+ attach_function :GDALReadBlock,
460
+ [:GDALRasterBandH, :int, :int, :pointer],
461
+ CPLErr
462
+ attach_function :GDALWriteBlock,
463
+ [:GDALRasterBandH, :int, :int, :pointer],
464
+ CPLErr
465
+ attach_function :GDALGetRasterBandXSize, [:GDALRasterBandH], :int
466
+ attach_function :GDALGetRasterBandYSize, [:GDALRasterBandH], :int
467
+ attach_function :GDALGetRasterAccess, [:GDALRasterBandH], GDALAccess
468
+ attach_function :GDALGetBandNumber, [:GDALRasterBandH], :int
469
+ attach_function :GDALGetBandDataset, [:GDALRasterBandH], :GDALDatasetH
470
+ attach_function :GDALGetRasterColorInterpretation,
471
+ [:GDALRasterBandH],
472
+ GDALColorInterp
473
+ attach_function :GDALSetRasterColorInterpretation,
474
+ [:GDALRasterBandH, GDALColorInterp],
475
+ CPLErr
476
+ attach_function :GDALGetRasterColorTable,
477
+ [:GDALRasterBandH],
478
+ :GDALColorTableH
479
+
480
+ attach_function :GDALHasArbitraryOverviews, [:GDALRasterBandH], :int
481
+ attach_function :GDALGetOverviewCount, [:GDALRasterBandH], :int
482
+ attach_function :GDALGetOverview, [:GDALRasterBandH, :int], :GDALRasterBandH
483
+ attach_function :GDALGetRasterNoDataValue,
484
+ [:GDALRasterBandH, :pointer],
485
+ :double
486
+ attach_function :GDALSetRasterNoDataValue,
487
+ [:GDALRasterBandH, :double],
488
+ CPLErr
489
+ attach_function :GDALGetRasterCategoryNames,
490
+ [:GDALRasterBandH],
491
+ :pointer
492
+ attach_function :GDALSetRasterCategoryNames,
493
+ [:GDALRasterBandH, :pointer],
494
+ CPLErr
495
+ attach_function :GDALGetRasterMinimum,
496
+ [:GDALRasterBandH, :pointer],
497
+ :double
498
+ attach_function :GDALGetRasterMaximum,
499
+ [:GDALRasterBandH, :pointer],
500
+ :double
501
+ attach_function :GDALGetRasterStatistics,
502
+ [:GDALRasterBandH, :bool, :bool, :pointer, :pointer, :pointer, :pointer],
503
+ CPLErr
504
+ attach_function :GDALComputeRasterStatistics,
505
+ [
506
+ :GDALRasterBandH,
507
+ :int,
508
+ :int,
509
+ :pointer,
510
+ :pointer,
511
+ :pointer,
512
+ :pointer,
513
+ :GDALProgressFunc,
514
+ :pointer
515
+ ], CPLErr
516
+ attach_function :GDALSetRasterStatistics,
517
+ [:GDALRasterBandH, :double, :double, :double, :double],
518
+ CPLErr
519
+ attach_function :GDALGetRasterUnitType, [:GDALRasterBandH], :string
520
+ attach_function :GDALSetRasterUnitType, [:GDALRasterBandH, :string], CPLErr
521
+ attach_function :GDALGetRasterOffset, [:GDALRasterBandH, :pointer], :double
522
+ attach_function :GDALSetRasterOffset, [:GDALRasterBandH, :double], CPLErr
523
+ attach_function :GDALGetRasterScale, [:GDALRasterBandH, :pointer], :double
524
+ attach_function :GDALSetRasterScale, [:GDALRasterBandH, :double], CPLErr
525
+ attach_function :GDALComputeRasterMinMax,
526
+ [:GDALRasterBandH, :int, :pointer],
527
+ :void
528
+ attach_function :GDALFlushRasterCache, [:GDALRasterBandH], CPLErr
529
+ attach_function :GDALGetRasterHistogram,
530
+ [
531
+ :GDALRasterBandH,
532
+ :double,
533
+ :double,
534
+ :int,
535
+ :pointer,
536
+ :bool,
537
+ :bool,
538
+ :GDALProgressFunc,
539
+ :pointer
540
+ ], CPLErr
541
+
542
+ attach_function :GDALGetDefaultHistogram,
543
+ [
544
+ :GDALRasterBandH,
545
+ :pointer,
546
+ :pointer,
547
+ :pointer,
548
+ :pointer,
549
+ :bool,
550
+ :GDALProgressFunc,
551
+ :pointer
552
+ ], CPLErr
553
+ attach_function :GDALSetDefaultHistogram,
554
+ [
555
+ :GDALRasterBandH,
556
+ :double,
557
+ :double,
558
+ :int,
559
+ :pointer
560
+ ], CPLErr
561
+
562
+ attach_function :GDALGetRandomRasterSample,
563
+ [:GDALRasterBandH, :int, :pointer],
564
+ :int
565
+ attach_function :GDALGetRasterSampleOverview,
566
+ [:GDALRasterBandH, :int],
567
+ :GDALRasterBandH
568
+ attach_function :GDALFillRaster,
569
+ [:GDALRasterBandH, :double, :double],
570
+ CPLErr
571
+
572
+ # Raster Attribute Table functions
573
+ attach_function :GDALGetDefaultRAT,
574
+ [:GDALRasterBandH],
575
+ :GDALRasterAttributeTableH
576
+ attach_function :GDALSetDefaultRAT,
577
+ [:GDALRasterBandH, :GDALRasterAttributeTableH],
578
+ CPLErr
579
+ attach_function :GDALRATGetColumnCount,
580
+ [:GDALRasterAttributeTableH],
581
+ :int
582
+ attach_function :GDALRATGetNameOfCol,
583
+ [:GDALRasterAttributeTableH, :int],
584
+ :string
585
+ attach_function :GDALRATGetUsageOfCol,
586
+ [:GDALRasterAttributeTableH, :int],
587
+ GDALRATFieldUsage
588
+ attach_function :GDALRATGetTypeOfCol,
589
+ [:GDALRasterAttributeTableH, :int],
590
+ GDALRATFieldType
591
+ attach_function :GDALRATGetColOfUsage,
592
+ [:GDALRasterAttributeTableH, GDALRATFieldUsage],
593
+ :int
594
+ attach_function :GDALRATGetRowCount,
595
+ [:GDALRasterAttributeTableH],
596
+ :int
597
+ attach_function :GDALRATTranslateToColorTable,
598
+ [:GDALRasterAttributeTableH, :int],
599
+ :GDALColorTableH
600
+ attach_function :GDALRATDumpReadable,
601
+ [:GDALRasterAttributeTableH, :string],
602
+ :void
603
+
604
+ # Register all drivers!
605
+ FFI::GDAL.GDALAllRegister
606
+ end
607
+ end
@@ -0,0 +1,59 @@
1
+ require_relative '../ffi/gdal'
2
+
3
+
4
+ module GDAL
5
+ class ColorTable
6
+ include FFI::GDAL
7
+
8
+ def initialize(gdal_raster_band, color_table_pointer: nil)
9
+ @gdal_raster_band = if gdal_raster_band.is_a? GDAL::RasterBand
10
+ gdal_raster_band.c_pointer
11
+ else
12
+ gdal_raster_band
13
+ end
14
+
15
+ @gdal_color_table = color_table_pointer
16
+ end
17
+
18
+ def c_pointer
19
+ @gdal_color_table ||= GDALGetRasterColorTable(@gdal_raster_band)
20
+ end
21
+
22
+ def null?
23
+ c_pointer.nil? || c_pointer.null?
24
+ end
25
+
26
+ # Usually :GPI_RGB.
27
+ #
28
+ # @return [Symbol] One of FFI::GDAL::GDALPaletteInterp.
29
+ def palette_interpretation
30
+ GDALGetPaletteInterpretation(c_pointer)
31
+ end
32
+
33
+ # @return [Fixnum]
34
+ def color_entry_count
35
+ return 0 if null?
36
+
37
+ GDALGetColorEntryCount(c_pointer)
38
+ end
39
+
40
+ # @param index [Fixnum]
41
+ # @return [FFI::GDAL::GDALColorEntry]
42
+ def color_entry(index)
43
+ return nil if null?
44
+
45
+ GDALGetColorEntry(c_pointer, index)
46
+ end
47
+
48
+ # @param index [Fixnum]
49
+ # @return [GGI::GDAL::GDALColorEntry]
50
+ def color_entry_as_rgb(index)
51
+ return nil if null?
52
+
53
+ entry = GDALColorEntry.new
54
+ GDALGetColorEntryAsRGB(c_pointer, index, entry)
55
+
56
+ entry
57
+ end
58
+ end
59
+ end