-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathGDALCore.bas
506 lines (423 loc) · 17.2 KB
/
GDALCore.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
Attribute VB_Name = "GDALCore"
'*****************************************************************************
' $Id$
'
' Project: GDAL VB6 Bindings
' Purpose: GDAL VB6 internal support functions. Items in this module should
' only be used by the VB6 shadow classes and GDAL.bas. Application
' level code should not need access to this module.
' Author: Frank Warmerdam, warmerdam@pobox.com
'
'*****************************************************************************
' Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
'
' Permission is hereby granted, free of charge, to any person obtaining a
' copy of this software and associated documentation files (the "Software"),
' to deal in the Software without restriction, including without limitation
' the rights to use, copy, modify, merge, publish, distribute, sublicense,
' and/or sell copies of the Software, and to permit persons to whom the
' Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included
' in all copies or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
' OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
'*****************************************************************************
'
' $Log$
' Revision 1.8 2005/08/04 20:53:51 fwarmerdam
' convert to DOS text mode
'
' Revision 1.7 2005/04/11 19:58:47 fwarmerdam
' added CPLSet/GetConfigOption
'
' Revision 1.6 2005/04/08 14:36:25 fwarmerdam
' applied owned flag, and auto-destroy
'
' Revision 1.5 2005/04/06 22:30:15 fwarmerdam
' added OGRCoordinateTransformation and OGRSpatialReference functions
'
' Revision 1.4 2005/04/04 15:34:30 fwarmerdam
' fixed in bindings for colortable stuff per bug 814
'
' Revision 1.3 2005/04/04 15:32:35 fwarmerdam
' use gdal12.dll
'
' Revision 1.2 2005/03/16 23:34:55 fwarmerdam
' added colortable support
'
' Revision 1.1 2005/03/16 19:45:19 fwarmerdam
' new
'
'
' ****************************************************************************
' Declarations for C API functions.
' ****************************************************************************
Public Const ObjIsNULLError = 1001
' ----------------------------------------------------------------------------
' Misc
' ----------------------------------------------------------------------------
Public Declare Function GDALGetDataTypeName _
Lib "gdal12.dll" _
Alias "_GDALGetDataTypeName@4" _
(ByVal DataType As Long) As Long
Public Declare Function GDALGetDataTypeSize _
Lib "gdal12.dll" _
Alias "_GDALGetDataTypeSize@4" _
(ByVal DataType As Long) As Long
Public Declare Function CPLGetLastErrorMsg _
Lib "gdal12.dll" _
Alias "_CPLGetLastErrorMsg@0" _
() As Long
Public Declare Sub CSLDestroy _
Lib "gdal12.dll" _
Alias "_CSLDestroy@4" _
(ByVal CSLList As Long)
Public Declare Function CPLGetConfigOption _
Lib "gdal12.dll" _
Alias "_CPLGetConfigOption@8" _
(ByVal Key As String, ByVal Default As String) As Long
Public Declare Sub CPLSetConfigOption _
Lib "gdal12.dll" _
Alias "_CPLSetConfigOption@8" _
(ByVal Key As String, ByVal Value As String)
' ----------------------------------------------------------------------------
' GDALMajorObject
' ----------------------------------------------------------------------------
Public Declare Function GDALGetMetadataItem _
Lib "gdal12.dll" _
Alias "_GDALGetMetadataItem@12" _
(ByVal Handle As Long, ByVal Name As String, _
ByVal Domain As String) As Long
Public Declare Function GDALGetMetadata _
Lib "gdal12.dll" _
Alias "_GDALGetMetadata@8" _
(ByVal Handle As Long, ByVal Domain As String) As Long
Public Declare Function GDALSetMetadataItem _
Lib "gdal12.dll" _
Alias "_GDALSetMetadataItem@16" _
(ByVal Handle As Long, ByVal Name As String, _
ByVal Value As String, ByVal Domain As String) As Long
Public Declare Function GDALSetMetadata _
Lib "gdal12.dll" _
Alias "_GDALSetMetadata@12" _
(ByVal Handle As Long, ByVal MetaData As Long, _
ByVal Domain As String) As Long
Public Declare Function GDALGetDescription _
Lib "gdal12.dll" _
Alias "_GDALGetDescription@4" _
(ByVal Handle As Long) As Long
Public Declare Sub GDALSetDescription _
Lib "gdal12.dll" _
Alias "_GDALSetDescription@8" _
(ByVal Handle As Long, ByVal Description As String)
' ----------------------------------------------------------------------------
' GDAL Dataset
' ----------------------------------------------------------------------------
Public Declare Function GDALOpen _
Lib "gdal12.dll" _
Alias "_GDALOpen@8" _
(ByVal Filename As String, ByVal Access As Long) As Long
Public Declare Function GDALOpenShared _
Lib "gdal12.dll" _
Alias "_GDALOpenShared@8" _
(ByVal Filename As String, ByVal Access As Long) As Long
Public Declare Sub GDALClose _
Lib "gdal12.dll" _
Alias "_GDALClose@4" _
(ByVal Handle As Long)
Public Declare Function GDALGetRasterXSize _
Lib "gdal12.dll" _
Alias "_GDALGetRasterXSize@4" _
(ByVal Handle As Long) As Long
Public Declare Function GDALGetRasterYSize _
Lib "gdal12.dll" _
Alias "_GDALGetRasterYSize@4" _
(ByVal Handle As Long) As Long
Public Declare Function GDALGetRasterCount _
Lib "gdal12.dll" _
Alias "_GDALGetRasterCount@4" _
(ByVal Handle As Long) As Long
Public Declare Function GDALGetRasterBand _
Lib "gdal12.dll" _
Alias "_GDALGetRasterBand@8" _
(ByVal Handle As Long, ByVal BandNo As Long) As Long
Public Declare Function GDALGetProjectionRef _
Lib "gdal12.dll" _
Alias "_GDALGetProjectionRef@4" _
(ByVal Handle As Long) As Long
Public Declare Function GDALSetProjection _
Lib "gdal12.dll" _
Alias "_GDALSetProjection@8" _
(ByVal Handle As Long, ByVal WKTProj As String) As Long
Public Declare Function GDALGetGeoTransform _
Lib "gdal12.dll" _
Alias "_GDALGetGeoTransform@8" _
(ByVal Handle As Long, ByRef Geotransform As Double) As Long
Public Declare Function GDALSetGeoTransform _
Lib "gdal12.dll" _
Alias "_GDALSetGeoTransform@8" _
(ByVal Handle As Long, ByRef Geotransform As Double) As Long
Public Declare Function GDALReferenceDataset _
Lib "gdal12.dll" _
Alias "_GDALReferenceDataset@4" _
(ByVal Handle As Long) As Long
Public Declare Function GDALDereferenceDataset _
Lib "gdal12.dll" _
Alias "_GDALDereferenceDataset@4" _
(ByVal Handle As Long) As Long
Public Declare Sub GDALFlushCache _
Lib "gdal12.dll" _
Alias "_GDALFlushCache@4" _
(ByVal Handle As Long)
' ----------------------------------------------------------------------------
' GDALRasterBand
' ----------------------------------------------------------------------------
Public Declare Function GDALGetRasterDataType _
Lib "gdal12.dll" _
Alias "_GDALGetRasterDataType@4" _
(ByVal Handle As Long) As Long
Public Declare Function GDALGetRasterBandXSize _
Lib "gdal12.dll" _
Alias "_GDALGetRasterBandXSize@4" _
(ByVal Handle As Long) As Long
Public Declare Function GDALGetRasterBandYSize _
Lib "gdal12.dll" _
Alias "_GDALGetRasterBandYSize@4" _
(ByVal Handle As Long) As Long
Public Declare Sub GDALGetBlockSize _
Lib "gdal12.dll" _
Alias "_GDALGetBlockSize@12" _
(ByVal Handle As Long, ByRef XSize As Long, ByRef YSize As Long)
Public Declare Function GDALGetRasterNoDataValue _
Lib "gdal12.dll" _
Alias "_GDALGetRasterNoDataValue@8" _
(ByVal Handle As Long, ByRef bSuccess As Long) As Double
Public Declare Function GDALSetRasterNoDataValue _
Lib "gdal12.dll" _
Alias "_GDALSetRasterNoDataValue@12" _
(ByVal Handle As Long, ByVal NoDataValue As Double) As Long
Public Declare Function GDALGetRasterMinimum _
Lib "gdal12.dll" _
Alias "_GDALGetRasterMinimum@8" _
(ByVal Handle As Long, ByRef bSuccess As Long) As Double
Public Declare Function GDALGetRasterMaximum _
Lib "gdal12.dll" _
Alias "_GDALGetRasterMaximum@8" _
(ByVal Handle As Long, ByRef bSuccess As Long) As Double
Public Declare Function GDALGetRasterOffset _
Lib "gdal12.dll" _
Alias "_GDALGetRasterOffset@8" _
(ByVal Handle As Long, ByRef bSuccess As Long) As Double
Public Declare Function GDALSetRasterOffset _
Lib "gdal12.dll" _
Alias "_GDALSetRasterOffset@12" _
(ByVal Handle As Long, ByVal Offset As Double) As Long
Public Declare Function GDALGetRasterScale _
Lib "gdal12.dll" _
Alias "_GDALGetRasterScale@8" _
(ByVal Handle As Long, ByRef bSuccess As Long) As Double
Public Declare Function GDALSetRasterScale _
Lib "gdal12.dll" _
Alias "_GDALSetRasterScale@12" _
(ByVal Handle As Long, ByVal NewScale As Double) As Long
Public Declare Function GDALRasterIO _
Lib "gdal12.dll" _
Alias "_GDALRasterIO@48" _
(ByVal Handle As Long, ByVal RWFlag As Long, _
ByVal XOff As Long, ByVal YOff As Long, _
ByVal XSize As Long, ByVal YSize As Long, _
ByVal pData As Long, ByVal BufXSize As Long, ByVal BufYSize As Long, _
ByVal DataType As Long, _
ByVal PixelSpace As Long, ByVal LineSpace As Long) As Long
Public Declare Function GDALGetRasterColorTable _
Lib "gdal12.dll" _
Alias "_GDALGetRasterColorTable@4" _
(ByVal Handle As Long) As Long
Public Declare Function GDALSetRasterColorTable _
Lib "gdal12.dll" _
Alias "_GDALSetRasterColorTable@8" _
(ByVal BandHandle As Long, ByVal TableHandle As Long) As Long
' ----------------------------------------------------------------------------
' GDALDriver
' ----------------------------------------------------------------------------
Public Declare Sub GDALAllRegister _
Lib "gdal12.dll" _
Alias "_GDALAllRegister@0" ()
Public Declare Function GDALGetDriverByName _
Lib "gdal12.dll" _
Alias "_GDALGetDriverByName@4" _
(ByVal Filename As String) As Long
Public Declare Function GDALGetDriverCount _
Lib "gdal12.dll" _
Alias "_GDALGetDriverCount@0" () As Long
Public Declare Function GDALGetDriver _
Lib "gdal12.dll" _
Alias "_GDALGetDriver@4" _
(ByVal DriverIndex As Long) As Long
Public Declare Sub GDALDestroyDriverManager _
Lib "gdal12.dll" _
Alias "_GDALDestroyDriverManager@0" ()
Public Declare Function GDALCreate _
Lib "gdal12.dll" _
Alias "_GDALCreate@28" _
(ByVal Handle As Long, ByVal Filename As String, _
ByVal XSize As Long, ByVal YSize As Long, ByVal BandCount As Long, _
ByVal DataType As Long, ByVal Options As Long) As Long
Public Declare Function GDALCreateCopy _
Lib "gdal12.dll" _
Alias "_GDALCreateCopy@28" _
(ByVal Handle As Long, ByVal Filename As String, _
ByVal SrcDS As Long, ByVal ApproxOK As Long, ByVal Options As Long, _
ByVal ProgressFunc As Long, ByVal ProgressArg As Long) As Long
' ----------------------------------------------------------------------------
' GDALColorTable
' ----------------------------------------------------------------------------
Public Declare Function GDALCreateColorTable _
Lib "gdal12.dll" _
Alias "_GDALCreateColorTable@4" _
(ByVal PaletteInterp As Long) As Long
Public Declare Sub GDALDestroyColorTable _
Lib "gdal12.dll" _
Alias "_GDALDestroyColorTable@4" _
(ByVal Handle As Long)
Public Declare Function GDALCloneColorTable _
Lib "gdal12.dll" _
Alias "_GDALCloneColorTable@4" _
(ByVal Handle As Long) As Long
Public Declare Function GDALGetPaletteInterpretation _
Lib "gdal12.dll" _
Alias "_GDALGetPaletteInterpretation@4" _
(ByVal Handle As Long) As Long
Public Declare Function GDALGetColorEntryCount _
Lib "gdal12.dll" _
Alias "_GDALGetColorEntryCount@4" _
(ByVal Handle As Long) As Long
Public Declare Function GDALGetColorEntryAsRGB _
Lib "gdal12.dll" _
Alias "_GDALGetColorEntryAsRGB@12" _
(ByVal Handle As Long, ByVal ColorIndex As Long, _
ByRef ColorEntry As Integer) As Long
Public Declare Function GDALGetColorEntry _
Lib "gdal12.dll" _
Alias "_GDALGetColorEntry@12" _
(ByVal Handle As Long, ByVal ColorIndex As Long, _
ByRef ColorEntry As Integer) As Long
Public Declare Sub GDALSetColorEntry _
Lib "gdal12.dll" _
Alias "_GDALSetColorEntry@12" _
(ByVal Handle As Long, ByVal ColorIndex As Long, _
ByRef ColorEntry As Integer)
' ----------------------------------------------------------------------------
' OGRSpatialReference
' ----------------------------------------------------------------------------
Public Declare Function OSRNewSpatialReference _
Lib "gdal12.dll" _
Alias "_OSRNewSpatialReference@4" _
(ByVal WKT As String) As Long
Public Declare Function OSRCloneGeogCS _
Lib "gdal12.dll" _
Alias "_OSRCloneGeogCS@4" _
(ByVal Handle As Long) As Long
Public Declare Function OSRClone _
Lib "gdal12.dll" _
Alias "_OSRClone@4" _
(ByVal Handle As Long) As Long
Public Declare Sub OSRDestroySpatialReference _
Lib "gdal12.dll" _
Alias "_OSRDestroySpatialReference@4" _
(ByVal Handle As Long)
Public Declare Function OSRImportFromEPSG _
Lib "gdal12.dll" _
Alias "_OSRImportFromEPSG@8" _
(ByVal Handle As Long, EPSGCode As Long) As Long
Public Declare Function OSRExportToWkt _
Lib "gdal12.dll" _
Alias "_OSRExportToWkt@8" _
(ByVal Handle As Long, ByRef wktptr As Long) As Long
Public Declare Function OSRExportToPrettyWkt _
Lib "gdal12.dll" _
Alias "_OSRExportToPrettyWkt@12" _
(ByVal Handle As Long, ByRef wktptr As Long, Simplify As Long) As Long
Public Declare Function OSRSetFromUserInput _
Lib "gdal12.dll" _
Alias "_OSRSetFromUserInput@8" _
(ByVal Handle As Long, ByVal UserInput As String) As Long
Public Declare Function OSRSetAttrValue _
Lib "gdal12.dll" _
Alias "_OSRSetAttrValue@12" _
(ByVal Handle As Long, ByVal NodePath As String, _
ByVal NodeValue As String) As Long
Public Declare Function OSRGetAttrValue _
Lib "gdal12.dll" _
Alias "_OSRGetAttrValue@12" _
(ByVal Handle As Long, ByVal NodePath As String, _
ByVal iChild As Long) As Long
' ----------------------------------------------------------------------------
' OGRCoordinateTransformation
' ----------------------------------------------------------------------------
Public Declare Function OCTNewCoordinateTransformation _
Lib "gdal12.dll" _
Alias "_OCTNewCoordinateTransformation@8" _
(ByVal hSourceSRS As Long, ByVal hTargetSRS As Long) As Long
Public Declare Sub OCTDestroyCoordinateTransformation _
Lib "gdal12.dll" _
Alias "_OCTDestroyCoordinateTransformation@4" _
(ByVal Handle As Long)
Public Declare Function OCTTransformEx _
Lib "gdal12.dll" _
Alias "_OCTTransformEx@24" _
(ByVal Handle As Long, ByVal PointCount As Long, _
ByRef X As Double, ByRef Y As Double, ByRef Z As Double, _
ByRef Success As Long) As Long
' ----------------------------------------------------------------------------
' Special VB6 Support functions
' ----------------------------------------------------------------------------
Public Declare Function CStringToVB6 _
Lib "gdal12.dll" _
Alias "_vbCStringToVB6@8" _
(result As Variant, ByVal cString As Long) As Long
Public Declare Function VariantToCSL _
Lib "gdal12.dll" _
Alias "_vbVariantToCSL@4" _
(InList As Variant) As Long
Public Declare Sub CSLToVariant _
Lib "gdal12.dll" _
Alias "_vbCSLToVariant@8" _
(ByVal InList As Long, OutList As Variant)
Public Declare Function SafeArrayToPtr _
Lib "gdal12.dll" _
Alias "_vbSafeArrayToPtr@16" _
(InArray As Variant, ByRef DataType As Long, _
ByRef XSize As Long, ByRef YSize As Long) As Long
' ****************************************************************************
' VB Wrapper functions.
' ****************************************************************************
' ----------------------------------------------------------------------------
Public Function CStr2VB(c_str As Long)
Dim msg As Variant
Dim n As Long
n = CStringToVB6(msg, c_str)
CStr2VB = msg
End Function
' ----------------------------------------------------------------------------
Public Function GetMetadata(MajorObject As Long, Domain As String)
Dim CSLMetadata As Long
Dim ResultMD As Variant
CSLMetadata = GDALGetMetadata(MajorObject, Domain)
Call CSLToVariant(CSLMetadata, ResultMD)
GetMetadata = ResultMD
End Function
Public Function SetMetadata(Object As Long, MetaData As Variant, _
Domain As String)
Dim CSLMetadata As Long
CSLMetadata = VariantToCSL(MetaData)
SetMetadata = GDALSetMetadata(Object, CSLMetadata, Domain)
Call CSLDestroy(CSLMetadata)
End Function