Skip to content

Commit

Permalink
Remove SetGCPs2, add logic to SetGCPs to handle a projection `str…
Browse files Browse the repository at this point in the history
…ing` or `*SpatialRef`
  • Loading branch information
pericles-tpt committed Oct 4, 2023
1 parent 74d8882 commit 6d49583
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
30 changes: 7 additions & 23 deletions godal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions godal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}

0 comments on commit 6d49583

Please sign in to comment.