From 6d49583dc146dacaf9d7a4e5be5deb8a402d2232 Mon Sep 17 00:00:00 2001 From: Pericles Telemachou Date: Thu, 5 Oct 2023 10:47:16 +1100 Subject: [PATCH] Remove `SetGCPs2`, add logic to `SetGCPs` to handle a projection `string` or `*SpatialRef` --- godal.go | 30 +++++++----------------------- godal_test.go | 16 ++++++++-------- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/godal.go b/godal.go index e79c857..972a64b 100644 --- a/godal.go +++ b/godal.go @@ -4013,37 +4013,21 @@ func (ds *Dataset) GetGCPProjection() string { } // SetGCPs runs the GDALSetGCPs function -func (ds *Dataset) SetGCPs(GCPList []GCP, pszGCPProjection string, opts ...SetGCPsOption) error { +func (ds *Dataset) SetGCPs(GCPList []GCP, opts ...SetGCPsOption) error { setGCPsOpts := setGCPsOpts{} for _, opt := range opts { opt.setSetGCPsOpt(&setGCPsOpts) } - cgc := createCGOContext(nil, setGCPsOpts.errorHandler) - - GCPProj := C.CString(pszGCPProjection) - defer C.free(unsafe.Pointer(GCPProj)) - C.godalSetGCPs(cgc.cPointer(), ds.handle(), C.int(len(GCPList)), goGCPArrayToGDALGCP(GCPList), GCPProj) - if err := cgc.close(); err != nil { - return err - } - return nil -} - -// SetGCPs2 runs the GDALSetGCPs2 function -func (ds *Dataset) SetGCPs2(GCPList []GCP, sr *SpatialRef, opts ...SetGCPsOption) error { - setGCPsOpts := setGCPsOpts{} - for _, opt := range opts { - opt.setSetGCPsOpt(&setGCPsOpts) - } cgc := createCGOContext(nil, setGCPsOpts.errorHandler) - - srHandle := C.OGRSpatialReferenceH(nil) - if sr != nil { - srHandle = sr.handle + if setGCPsOpts.sr != nil { + C.godalSetGCPs2(cgc.cPointer(), ds.handle(), C.int(len(GCPList)), goGCPArrayToGDALGCP(GCPList), setGCPsOpts.sr.handle) + } else { + GCPProj := C.CString(setGCPsOpts.projString) + defer C.free(unsafe.Pointer(GCPProj)) + C.godalSetGCPs(cgc.cPointer(), ds.handle(), C.int(len(GCPList)), goGCPArrayToGDALGCP(GCPList), GCPProj) } - C.godalSetGCPs2(cgc.cPointer(), ds.handle(), C.int(len(GCPList)), goGCPArrayToGDALGCP(GCPList), srHandle) if err := cgc.close(); err != nil { return err } diff --git a/godal_test.go b/godal_test.go index fe98b7c..5d8d41a 100644 --- a/godal_test.go +++ b/godal_test.go @@ -4604,7 +4604,7 @@ func TestSetGCPsAddTwoGCPs(t *testing.T) { if err != nil { t.Error(err) } - err = vrtDs.SetGCPs(gcpList, srWkt) + err = vrtDs.SetGCPs(gcpList, GCPProjection(srWkt)) if err != nil { t.Error(err) } @@ -4639,7 +4639,7 @@ func TestSetGCPsAddZeroGCPs(t *testing.T) { if err != nil { t.Error(err) } - err = vrtDs.SetGCPs(gcpList, srWkt) + err = vrtDs.SetGCPs(gcpList, GCPProjection(srWkt)) if err != nil { t.Error(err) } @@ -4669,10 +4669,10 @@ func TestSetGCPsInvalidDataset(t *testing.T) { } ehc := eh() - err = vrtDs.SetGCPs([]GCP{}, srWkt, ErrLogger(ehc.ErrorHandler)) + err = vrtDs.SetGCPs([]GCP{}, GCPProjection(srWkt), ErrLogger(ehc.ErrorHandler)) assert.Error(t, err) - err = vrtDs.SetGCPs([]GCP{}, srWkt) + err = vrtDs.SetGCPs([]GCP{}, GCPProjection(srWkt)) assert.Error(t, err) } @@ -4718,7 +4718,7 @@ func TestSetGCPs2AddTwoGCPs(t *testing.T) { if err != nil { t.Error(err) } - err = vrtDs.SetGCPs2(gcpList, sr) + err = vrtDs.SetGCPs(gcpList, GCPSpatialRef(sr)) if err != nil { t.Error(err) } @@ -4753,7 +4753,7 @@ func TestSetGCPs2AddZeroGCPs(t *testing.T) { if err != nil { t.Error(err) } - err = vrtDs.SetGCPs2(gcpList, sr) + err = vrtDs.SetGCPs(gcpList, GCPSpatialRef(sr)) if err != nil { t.Error(err) } @@ -4774,9 +4774,9 @@ func TestSetGCPs2InvalidDataset(t *testing.T) { defer vrtDs.Close() ehc := eh() - err = vrtDs.SetGCPs2([]GCP{}, &SpatialRef{}, ErrLogger(ehc.ErrorHandler)) + err = vrtDs.SetGCPs([]GCP{}, GCPSpatialRef(&SpatialRef{}), ErrLogger(ehc.ErrorHandler)) assert.Error(t, err) - err = vrtDs.SetGCPs2([]GCP{}, &SpatialRef{}) + err = vrtDs.SetGCPs([]GCP{}, GCPSpatialRef(&SpatialRef{})) assert.Error(t, err) }