-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapps.go
100 lines (81 loc) · 2.26 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
98
99
100
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 */
/* --------------------------------------------- */
//GDALTranslateOptions holds options to be passed to gdal translated
type GDALTranslateOptions struct {
cval *C.GDALTranslateOptions
}
//GDALWarpAppOptions holds options to be passed to gdal translated
type GDALWarpAppOptions struct {
cval *C.GDALWarpAppOptions
}
//GDALTranslate is a utility to convert images into different formats
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}
}
//GDALWarp is a utility to warp images into different projections
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}
}