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

Add GDALNearblack binding #114

Merged
merged 70 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
59a03b0
Implement functional `godalGridCreate` wrapper (WIP)
pericles-tpt Aug 4, 2023
68ace26
Add `gridCreateOpts` go struct
pericles-tpt Aug 4, 2023
b3440ca
Implement `GridCreate` go function, add `GriddingAlg` enum
pericles-tpt Aug 4, 2023
cbf5c30
Add working `TestGridCreate` (needs asserts)
pericles-tpt Aug 4, 2023
21751d1
Update `godalGridCreate` to support multiple gridding algs and their …
pericles-tpt Aug 12, 2023
4ebb848
Update `GridCreate` for new `godalGridCreate` signature
pericles-tpt Aug 12, 2023
a8120dc
Fix `GridCreate` call in `TestGridCreate`
pericles-tpt Aug 12, 2023
5fb5963
Remove unused `String()` method for `GriddingAlg`, add `gridAlgFromSt…
pericles-tpt Aug 18, 2023
93fdfc5
Replace redundant `gridAlgorithm` param, replace with string lookup o…
pericles-tpt Aug 18, 2023
4d7e2af
Finish `TestGridCreate()` add required test files to "testdata/"
pericles-tpt Aug 18, 2023
97b6247
Update `go.sum`
pericles-tpt Aug 18, 2023
2c6ab1b
Remove TODOs, minor naming changes
pericles-tpt Aug 18, 2023
f46ce9c
Replace hardcoded size properties
pericles-tpt Aug 24, 2023
6745188
Create separate `GDALGridParseAlgorithmAndOptions()` binding
pericles-tpt Aug 24, 2023
dc22310
Update `GridCreate()` to use new `godalGridParseAlgorithmAndOptions()…
pericles-tpt Aug 24, 2023
07826c4
Add `setGridCreateOption`
pericles-tpt Aug 24, 2023
8fb3bc4
Add comment for `GridCreate()`
pericles-tpt Aug 24, 2023
cdb176d
Add `GDAL_VERSION_NUM` check to include the correct function name for…
pericles-tpt Aug 25, 2023
a06e3bc
Fix indentation
pericles-tpt Aug 25, 2023
912be53
Make `GriddingAlg` a private enum
pericles-tpt Aug 31, 2023
7724496
Improve clarity of griddingAlg string -> enum conversion
pericles-tpt Aug 31, 2023
65a90bd
Merge functionality from `godalGridParseAlgorithmAndOptions` into `go…
pericles-tpt Aug 31, 2023
d4775b1
Remove `[]byte` return parameter from `GridCreate`
pericles-tpt Aug 31, 2023
960be8a
Update `TestGridCreate` for `GridCreate` changes
pericles-tpt Aug 31, 2023
faa1c50
Change `uint32` params in `GridCreate()` to `int`
pericles-tpt Aug 31, 2023
16ce078
Remove "grid" test files from `testdata/`
pericles-tpt Sep 7, 2023
e478b45
Rename `setGridCreateOption()` to `setGridCreateOpt()` (for consistency)
pericles-tpt Sep 7, 2023
18bec58
Remove unused `options` pointer
pericles-tpt Sep 7, 2023
8f758d2
Remove redundant `griddingAlg` and `gridAlg()`
pericles-tpt Sep 7, 2023
1f2c6a1
Improve `GridCreate` tests by - testing two algorithms and justifying…
pericles-tpt Sep 7, 2023
dd5e8ad
Remove unneeded import, update `go.mod`
pericles-tpt Sep 7, 2023
e5b000d
Remove duplicate `gridCreateOpts`
pericles-tpt Sep 7, 2023
0752f00
Improve error message for "unknown gridding algorithm"
pericles-tpt Sep 7, 2023
3e9c76c
Remove `numCoords` from `GridCreate()`, add array equality check
pericles-tpt Sep 7, 2023
b14a350
Add compatibility check in `godalGridCreate`, update test behaviour
pericles-tpt Sep 8, 2023
b294589
Implement `GDALGrid` binding and tests for it
pericles-tpt Sep 8, 2023
30b6d19
Minor test fixes
pericles-tpt Sep 8, 2023
9c625ec
Remove unneeded code, add temporary log to test
pericles-tpt Sep 8, 2023
6889829
Add manual `t.Fail()` for results logging
pericles-tpt Sep 8, 2023
df45c87
Fix WKT coords and remove temporary lines in tests
pericles-tpt Sep 8, 2023
d8786a1
Minor change for testing
pericles-tpt Sep 8, 2023
a567ff0
Minor change testing transform modification
pericles-tpt Sep 8, 2023
f4302eb
Remove temporary testing modification
pericles-tpt Sep 8, 2023
7b59ad9
Add missing `return` for error condition
pericles-tpt Sep 8, 2023
6786078
Swap `-tye` args for `TestGridLinear()`
pericles-tpt Sep 14, 2023
42e7a40
Add comment explaining `yMin`/`yMax` swap
pericles-tpt Sep 14, 2023
7f90ec2
Merge branch 'airbusgeo:main' into grid
pericles-tpt Sep 14, 2023
3c013ab
Merge branch 'grid'
pericles-tpt Sep 14, 2023
44bcdc8
Removing suggested sections for testing
pericles-tpt Sep 15, 2023
f4ecb34
Add `Grid()` tests for "Unsupported" and "Unknown" switches
pericles-tpt Sep 15, 2023
35739b4
Add layer to ds for "switch" tests
pericles-tpt Sep 15, 2023
0e5c475
Try removing `TestGridUnsupportedSwitch`
pericles-tpt Sep 15, 2023
ab4f6c9
Update godal.cpp
pericles-tpt Sep 15, 2023
4e0e1a3
Update godal.go
pericles-tpt Sep 15, 2023
00694e6
User error handler in `TestGridUnknownSwitch()`
pericles-tpt Sep 15, 2023
ee953a9
Add `GridOption` to `ErrLogger`
pericles-tpt Sep 15, 2023
90d400f
Add `TestGridInvalidSwitch()` which uses `ErrorHandler`
pericles-tpt Sep 15, 2023
f55a363
Merge branch 'grid-2'
pericles-tpt Sep 15, 2023
e55f4dc
Implemented `Nearblack` binding and tests
pericles-tpt Sep 21, 2023
7f873c3
Merge branch 'near-black'
pericles-tpt Sep 21, 2023
9e6676d
Change to `TestNearblackWhite` to improve test coverage
pericles-tpt Sep 21, 2023
70d195d
Add new `TestNearblackReplaceSrcDs` test
pericles-tpt Sep 21, 2023
d8cc18a
Add error check without `ErrorHandler` back to `Grid` test
pericles-tpt Sep 21, 2023
4e2914f
Update comment
pericles-tpt Sep 22, 2023
07157ce
Update comment
pericles-tpt Sep 22, 2023
d9ab5ba
Remove duplicate `godalGrid` function signature
pericles-tpt Sep 22, 2023
ec2de04
Add missing deferred `Close()`
pericles-tpt Sep 22, 2023
b95aaee
Add missing deferred `Close()`
pericles-tpt Sep 22, 2023
95b7d58
Split `Nearblack` into `Nearblack` and `NearblackInto` functions, add…
pericles-tpt Sep 22, 2023
71f3dd2
Split `Nearblack` and `NearblackInto` documentation
pericles-tpt Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func ErrLogger(fn ErrorHandler) interface {
SetStatisticsOption
ClearStatisticsOption
GridOption
NearblackOption
} {
return errorCallback{fn}
}
Expand Down Expand Up @@ -368,6 +369,9 @@ func (ec errorCallback) setGridCreateOpt(o *gridCreateOpts) {
func (ec errorCallback) setGridOpt(o *gridOpts) {
o.errorHandler = ec.fn
}
func (ec errorCallback) setNearblackOpt(o *nearBlackOpts) {
o.errorHandler = ec.fn
}

type multiError struct {
errs []error
Expand Down
21 changes: 21 additions & 0 deletions godal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,27 @@ GDALDatasetH godalGrid(cctx *ctx, const char *pszDest, GDALDatasetH hSrcDS, char
forceError(ctx);
}

godalUnwrap();
return ret;
}

GDALDatasetH godalNearblack(cctx *ctx, const char *pszDest, GDALDatasetH hDstDS, GDALDatasetH hSrcDS, char **switches) {
godalWrap(ctx);

GDALNearblackOptions *nbopts = GDALNearblackOptionsNew(switches,nullptr);
if(failed(ctx)) {
GDALNearblackOptionsFree(nbopts);
godalUnwrap();
return nullptr;
}

int usageErr=0;
GDALDatasetH ret = GDALNearblack(pszDest, hDstDS, hSrcDS, nbopts, &usageErr);
GDALNearblackOptionsFree(nbopts);
if(ret==nullptr || usageErr!=0) {
forceError(ctx);
}

godalUnwrap();
return ret;
}
78 changes: 76 additions & 2 deletions godal.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (band Band) ClearNoData(opts ...SetNoDataOption) error {
return cgc.close()
}

//SetScaleOffset sets the band's scale and offset
// SetScaleOffset sets the band's scale and offset
func (band Band) SetScaleOffset(scale, offset float64, opts ...SetScaleOffsetOption) error {
setterOpts := &setScaleOffsetOpts{}
for _, opt := range opts {
Expand Down Expand Up @@ -891,7 +891,7 @@ func (ds *Dataset) SetNoData(nd float64, opts ...SetNoDataOption) error {
return cgc.close()
}

//SetScale sets the band's scale and offset
// SetScaleOffset sets the band's scale and offset
func (ds *Dataset) SetScaleOffset(scale, offset float64, opts ...SetScaleOffsetOption) error {
setterOpts := &setScaleOffsetOpts{}
for _, opt := range opts {
Expand Down Expand Up @@ -3849,6 +3849,80 @@ func (ds *Dataset) Grid(destPath string, switches []string, opts ...GridOption)
return &Dataset{majorObject{C.GDALMajorObjectH(dsRet)}}, nil
}

// Nearblack runs the library version of nearblack
//
// See the nearblack doc page to determine the valid flags/opts that can be set in switches.
//
// Example switches :
//
// []string{"-white", "-near", "10"}
//
// Creation options and driver may be set in the switches slice with
//
// switches:=[]string{"-co","TILED=YES","-of","GTiff"}
//
// NOTE: Some switches are NOT compatible with this binding, as a `nullptr` is passed to a later call to
// `GDALNearblackOptionsNew()` (as the 2nd argument). Those switches are: "-o", "-q", "-quiet"
func (ds *Dataset) Nearblack(dstDS string, switches []string, opts ...NearblackOption) (*Dataset, error) {
nearBlackOpts := nearBlackOpts{}
for _, opt := range opts {
opt.setNearblackOpt(&nearBlackOpts)
}

cswitches := sliceToCStringArray(switches)
defer cswitches.free()

dest := unsafe.Pointer(C.CString(dstDS))
defer C.free(dest)

cgc := createCGOContext(nil, nearBlackOpts.errorHandler)

ret, err := C.godalNearblack(cgc.cPointer(), (*C.char)(dest), nil, ds.handle(), cswitches.cPointer())
if err = cgc.close(); err != nil {
return nil, err
}

return &Dataset{majorObject{C.GDALMajorObjectH(ret)}}, nil
}

// NearblackInto writes the provided `sourceDs` into the Dataset that this method was called on, and
// runs the library version of nearblack.
//
// See the nearblack doc page to determine the valid flags/opts that can be set in switches.
//
// Example switches :
//
// []string{"-white", "-near", "10"}
//
// Creation options and driver may be set in the switches slice with
//
// switches:=[]string{"-co","TILED=YES","-of","GTiff"}
//
// NOTE: Some switches are NOT compatible with this binding, as a `nullptr` is passed to a later call to
// `GDALNearblackOptionsNew()` (as the 2nd argument). Those switches are: "-o", "-q", "-quiet"
func (ds *Dataset) NearblackInto(sourceDs *Dataset, switches []string, opts ...NearblackOption) error {
nearBlackOpts := nearBlackOpts{}
for _, opt := range opts {
opt.setNearblackOpt(&nearBlackOpts)
}

cswitches := sliceToCStringArray(switches)
defer cswitches.free()

cgc := createCGOContext(nil, nearBlackOpts.errorHandler)

var srcDsHandle C.GDALDatasetH = nil
if sourceDs != nil {
srcDsHandle = sourceDs.handle()
}
_ = C.godalNearblack(cgc.cPointer(), nil, ds.handle(), srcDsHandle, cswitches.cPointer())
if err := cgc.close(); err != nil {
return err
}

return nil
}

type cgoContext struct {
cctx *C.cctx
opts cStringArray
Expand Down
1 change: 1 addition & 0 deletions godal.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ extern "C" {
void godalSetRasterStatistics(cctx *ctx, GDALRasterBandH bnd, double dfMin, double dfMax, double dfMean, double dfStdDev);
void godalGridCreate(cctx *ctx, char *pszAlgorithm, GDALGridAlgorithm eAlgorithm, GUInt32 nPoints, 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);
GDALDatasetH godalGrid(cctx *ctx, const char *pszDest, GDALDatasetH hSrcDS, char **switches);
GDALDatasetH godalNearblack(cctx *ctx, const char *pszDest, GDALDatasetH hDstDS, GDALDatasetH hSrcDS, char **switches);
#ifdef __cplusplus
}
#endif
Expand Down
Loading
Loading