Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented GDALGridCreate CGo wrapper for all available algorithms #51

Merged
merged 9 commits into from
Jun 3, 2020
Prev Previous commit
Next Next commit
implementing GDALGridCreate wrapper...
  • Loading branch information
mtfelian committed Jun 2, 2020
commit 9cdf945732c89c61f7ac5787325e1dd293be582b
68 changes: 44 additions & 24 deletions algorithms.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,26 @@ const (
// - const double *padfX,
// - const double *padfY,
// - const double *padfZ,
// double dfXMin,
// double dfXMax,
// double dfYMin,
// double dfYMax,
// GUInt32 nXSize,
// GUInt32 nYSize,
// GDALDataType eType,
// void *pData,
// GDALProgressFunc pfnProgress,
// void *pProgressArg
// - double dfXMin,
// - double dfXMax,
// - double dfYMin,
// - double dfYMax,
// - GUInt32 nXSize,
// - GUInt32 nYSize,
// - GDALDataType eType,
// - void *pData,
// - GDALProgressFunc pfnProgress,
// - void *pProgressArg
// )
func CreateGrid(algo GDALGridAlgorithm, options []string, x, y, z []float64) error {
func CreateGrid(
algo GDALGridAlgorithm,
options []string,
x, y, z []float64,
nX, nY uint,
buffer interface{}, // should be pre-initialized slice!
progress ProgressFunc,
data interface{},
) error {
// options
length := len(options)
ooptions := make([]*C.char, length+1)
Expand Down Expand Up @@ -368,19 +376,31 @@ func CreateGrid(algo GDALGridAlgorithm, options []string, x, y, z []float64) err
}
}

return nil
//return C.GDALGridCreate(
// C.GDALGridAlgorithm(algo),
// (**C.char)(unsafe.Pointer(&ooptions[0])),
// C.Int(len(x)),
// (*C.double)(unsafe.Pointer(&x[0])),
// (*C.double)(unsafe.Pointer(&y[0])),
// (*C.double)(unsafe.Pointer(&z[0])),
// C.double(lx),
// C.double(hx),
// C.double(ly),
// C.double(hy),
//).Err()
dataType, dataPtr, err := determineBufferType(buffer)
if err != nil {
return err
}

arg := &goGDALProgressFuncProxyArgs{progress, data}

return C.GDALGridCreate(
C.GDALGridAlgorithm(algo),
unsafe.Pointer(&ooptions[0]),
C.uint(uint(len(x))),
(*C.double)(unsafe.Pointer(&x[0])),
(*C.double)(unsafe.Pointer(&y[0])),
(*C.double)(unsafe.Pointer(&z[0])),
C.double(lx),
C.double(hx),
C.double(ly),
C.double(hy),
C.uint(nX),
C.uint(nY),
C.GDALDataType(dataType),
dataPtr,
C.goGDALProgressFuncProxyB(),
unsafe.Pointer(arg),
).Err()
}

//Unimplemented: ComputeMatchingPoints
64 changes: 22 additions & 42 deletions gdal.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,18 +880,7 @@ func (dataset Dataset) AutoCreateWarpedVRT(srcWKT, dstWKT string, resampleAlg Re
// Unimplemented: GDALBeginAsyncReader
// Unimplemented: GDALEndAsyncReader

// 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
func determineBufferType(buffer interface{}) (dataType DataType, dataPtr unsafe.Pointer, err error) {
switch data := buffer.(type) {
case []int8:
dataType = Byte
Expand All @@ -918,7 +907,24 @@ func (dataset Dataset) IO(
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)")
err = fmt.Errorf("Error: buffer is not a valid data type (must be a valid numeric slice)")
}
return
}

// 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 {
dataType, dataPtr, err := determineBufferType(buffer)
if err != nil {
return err
}

return C.GDALDatasetRasterIO(
Expand Down Expand Up @@ -1153,35 +1159,9 @@ func (rasterBand RasterBand) IO(
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)")
dataType, dataPtr, err := determineBufferType(buffer)
if err != nil {
return err
}

return C.GDALRasterIO(
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/lukeroth/gdal
module github.com/mtfelian/gdal

go 1.13