forked from slawler/gdal
-
Notifications
You must be signed in to change notification settings - Fork 2
/
apps.go
97 lines (77 loc) · 2 KB
/
apps.go
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
package gdal
/*
#include "go_gdal.h"
#include "gdal_version.h"
#include "gdal_utils.h"
#cgo linux pkg-config: gdal
#cgo darwin pkg-config: gdal
#cgo windows LDFLAGS: -Lc:/gdal/release-1600-x64/lib -lgdal_i
#cgo windows CFLAGS: -IC:/gdal/release-1600-x64/include
*/
import "C"
import (
"fmt"
"unsafe"
)
var _ = fmt.Println
/* --------------------------------------------- */
/* GDAL utilities */
/* --------------------------------------------- */
type GDALTranslateOptions struct {
cval *C.GDALTranslateOptions
}
type GDALWarpAppOptions struct {
cval *C.GDALWarpAppOptions
}
func GDALTranslate(
destName string,
srcDS Dataset,
options []string,
) Dataset {
var err C.int
length := len(options)
cOptions := make([]*C.char, length+1)
for i := 0; i < length; i++ {
cOptions[i] = C.CString(options[i])
defer C.free(unsafe.Pointer(cOptions[i]))
}
cOptions[length] = (*C.char)(unsafe.Pointer(nil))
gdalTranslateOptions := GDALTranslateOptions{C.GDALTranslateOptionsNew((**C.char)(unsafe.Pointer(&cOptions[0])), nil)}
outputDs := C.GDALTranslate(
C.CString(destName),
srcDS.cval,
gdalTranslateOptions.cval,
&err,
)
return Dataset{outputDs}
}
func GDALWarp(
destName string,
dstDs Dataset,
srcDs []Dataset,
options []string,
) Dataset {
var err C.int
length := len(options)
cOptions := make([]*C.char, length+1)
for i := 0; i < length; i++ {
cOptions[i] = C.CString(options[i])
defer C.free(unsafe.Pointer(cOptions[i]))
}
cOptions[length] = (*C.char)(unsafe.Pointer(nil))
gdalWarpOptions := GDALWarpAppOptions{C.GDALWarpAppOptionsNew((**C.char)(unsafe.Pointer(&cOptions[0])), nil)}
pahSrcDs := make([]C.GDALDatasetH, len(srcDs)+1)
for i := 0; i < len(srcDs); i++ {
pahSrcDs[i] = srcDs[i].cval
}
pahSrcDs[len(srcDs)] = (C.GDALDatasetH)(unsafe.Pointer(nil))
outputDs := C.GDALWarp(
C.CString(destName),
dstDs.cval,
C.int(len(srcDs)),
(*C.GDALDatasetH)(unsafe.Pointer(&pahSrcDs[0])),
gdalWarpOptions.cval,
&err,
)
return Dataset{outputDs}
}