作者:kikh
项目:gda
// Advise driver of upcoming read requests
func (dataset Dataset) AdviseRead(
rwFlag RWFlag,
xOff, yOff, xSize, ySize, bufXSize, bufYSize int,
dataType DataType,
bandCount int,
bandMap []int,
options []string,
) error {
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))
err := C.GDALDatasetAdviseRead(
dataset.cval,
C.int(xOff), C.int(yOff), C.int(xSize), C.int(ySize),
C.int(bufXSize), C.int(bufYSize),
C.GDALDataType(dataType),
C.int(bandCount),
(*C.int)(unsafe.Pointer(&bandMap[0])),
(**C.char)(unsafe.Pointer(&cOptions[0])))
if err != 0 {
return error(err)
}
return nil
}
作者:kikh
项目:gda
// Create a new dataset with this driver.
func (driver Driver) Create(
filename string,
xSize, ySize, bands int,
dataType DataType,
options []string,
) Dataset {
name := C.CString(filename)
defer C.free(unsafe.Pointer(name))
length := len(options)
opts := make([]*C.char, length+1)
for i := 0; i < length; i++ {
opts[i] = C.CString(options[i])
defer C.free(unsafe.Pointer(opts[i]))
}
opts[length] = (*C.char)(unsafe.Pointer(nil))
h := C.GDALCreate(
driver.cval,
name,
C.int(xSize), C.int(ySize), C.int(bands),
C.GDALDataType(dataType),
(**C.char)(unsafe.Pointer(&opts[0])),
)
return Dataset{h}
}
作者:kikh
项目:gda
// Read / write a region of image data from multiple bands
func (dataset Dataset) IO(
rwFlag RWFlag,
xOff, yOff, xSize, ySize int,
buffer interface{},
bufXSize, bufYSize int,
bandCount int,
bandMap []int,
pixelSpace, lineSpace, bandSpace int,
) error {
var dataType DataType
var dataPtr unsafe.Pointer
switch data := buffer.(type) {
case []uint8:
dataType = Byte
dataPtr = unsafe.Pointer(&data[0])
case []int16:
dataType = Int16
dataPtr = unsafe.Pointer(&data[0])
case []uint16:
dataType = UInt16
dataPtr = unsafe.Pointer(&data[0])
case []int32:
dataType = Int32
dataPtr = unsafe.Pointer(&data[0])
case []uint32:
dataType = UInt32
dataPtr = unsafe.Pointer(&data[0])
case []float32:
dataType = Float32
dataPtr = unsafe.Pointer(&data[0])
case []float64:
dataType = Float64
dataPtr = unsafe.Pointer(&data[0])
case []complex64:
dataType = CFloat32
dataPtr = unsafe.Pointer(&data[0])
case []complex128:
dataType = CFloat64
dataPtr = unsafe.Pointer(&data[0])
default:
return fmt.Errorf("Error: buffer is not a valid data type (must be a valid numeric slice)")
}
err := C.GDALDatasetRasterIO(
dataset.cval,
C.GDALRWFlag(rwFlag),
C.int(xOff), C.int(yOff), C.int(xSize), C.int(ySize),
dataPtr,
C.int(bufXSize), C.int(bufYSize),
C.GDALDataType(dataType),
C.int(bandCount),
(*C.int)(unsafe.Pointer(&bandMap[0])),
C.int(pixelSpace), C.int(lineSpace), C.int(bandSpace))
if err != 0 {
return error(err)
}
return nil
}
作者:colek4
项目:gda
// Add a band to a dataset
func (dataset Dataset) AddBand(dataType DataType, options []string) error {
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))
return C.GDALAddBand(
dataset.cval,
C.GDALDataType(dataType),
(**C.char)(unsafe.Pointer(&cOptions[0])),
).Err()
}
作者:colek4
项目:gda
// Read / Write a region of image data for this band
func (rasterBand RasterBand) IO(
rwFlag RWFlag,
xOff, yOff, xSize, ySize int,
buffer interface{},
bufXSize, bufYSize int,
pixelSpace, lineSpace int,
) error {
var dataType DataType
var dataPtr unsafe.Pointer
switch data := buffer.(type) {
case []int8:
dataType = Byte
dataPtr = unsafe.Pointer(&data[0])
case []uint8:
dataType = Byte
dataPtr = unsafe.Pointer(&data[0])
case []int16:
dataType = Int16
dataPtr = unsafe.Pointer(&data[0])
case []uint16:
dataType = UInt16
dataPtr = unsafe.Pointer(&data[0])
case []int32:
dataType = Int32
dataPtr = unsafe.Pointer(&data[0])
case []uint32:
dataType = UInt32
dataPtr = unsafe.Pointer(&data[0])
case []float32:
dataType = Float32
dataPtr = unsafe.Pointer(&data[0])
case []float64:
dataType = Float64
dataPtr = unsafe.Pointer(&data[0])
default:
return fmt.Errorf("Error: buffer is not a valid data type (must be a valid numeric slice)")
}
return C.GDALRasterIO(
rasterBand.cval,
C.GDALRWFlag(rwFlag),
C.int(xOff), C.int(yOff), C.int(xSize), C.int(ySize),
dataPtr,
C.int(bufXSize), C.int(bufYSize),
C.GDALDataType(dataType),
C.int(pixelSpace), C.int(lineSpace),
).Err()
}
作者:kikh
项目:gda
func (dataType DataType) Name() string {
return C.GoString(C.GDALGetDataTypeName(C.GDALDataType(dataType)))
}
作者:kikh
项目:gda
func (dataType DataType) IsComplex() int {
return int(C.GDALDataTypeIsComplex(C.GDALDataType(dataType)))
}
作者:kikh
项目:gda
// Get data type size in bits.
func (dataType DataType) Size() int {
return int(C.GDALGetDataTypeSize(C.GDALDataType(dataType)))
}
作者:kikh
项目:gda
func (dataType DataType) Union(dataTypeB DataType) DataType {
return DataType(
C.GDALDataTypeUnion(C.GDALDataType(dataType), C.GDALDataType(dataTypeB)),
)
}