Skip to content

Commit

Permalink
Remove Get prefix from GCP functions, make GCPCount() private
Browse files Browse the repository at this point in the history
  • Loading branch information
pericles-tpt committed Oct 5, 2023
1 parent 6d49583 commit bc6630f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
10 changes: 5 additions & 5 deletions godal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3987,28 +3987,28 @@ func gdalGCPToGoGCPArray(gcp *C.GDAL_GCP, numGCPs int) []GCP {
}

// GetGCPSpatialRef runs the GDALGetGCPSpatialRef function
func (ds *Dataset) GetGCPSpatialRef() *SpatialRef {
func (ds *Dataset) GCPSpatialRef() *SpatialRef {
return &SpatialRef{handle: C.godalGetGCPSpatialRef(ds.handle()), isOwned: false}
}

// GetGCPCount runs the GDALGetGCPCount function
func (ds *Dataset) GetGCPCount() int {
func (ds *Dataset) gcpCount() int {
return int(C.godalGetGCPCount(ds.handle()))
}

// GetGCPs runs the GDALGetGCPs function
// TODO: This makes 2 cgo calls, we could reduce it to 1 by combining `godalGetGCPs` and `GetGCPCount`
func (ds *Dataset) GetGCPs() []GCP {
func (ds *Dataset) GCPs() []GCP {
hndl := C.godalGetGCPs(ds.handle())
numGCPs := ds.GetGCPCount()
numGCPs := ds.gcpCount()
if hndl != nil {
return gdalGCPToGoGCPArray(hndl, numGCPs)
}
return []GCP{}
}

// GetGCPProjection runs the GDALGetGCPProjection function
func (ds *Dataset) GetGCPProjection() string {
func (ds *Dataset) GCPProjection() string {
return C.GoString(C.godalGetGCPProjection(ds.handle()))
}

Expand Down
66 changes: 34 additions & 32 deletions godal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4571,10 +4571,10 @@ func TestSetGCPsAddTwoGCPs(t *testing.T) {
defer vrtDs.Close()

// Check `Get` methods before setting GCPs
assert.Equal(t, &SpatialRef{handle: nil, isOwned: false}, vrtDs.GetGCPSpatialRef())
assert.Equal(t, 0, vrtDs.GetGCPCount())
assert.Equal(t, []GCP{}, vrtDs.GetGCPs())
assert.Equal(t, "", vrtDs.GetGCPProjection())
assert.Equal(t, &SpatialRef{handle: nil, isOwned: false}, vrtDs.GCPSpatialRef())
gcps := vrtDs.GCPs()
assert.Equal(t, 0, len(gcps))
assert.Equal(t, "", vrtDs.GCPProjection())

var gcpList []GCP = []GCP{
{
Expand Down Expand Up @@ -4610,10 +4610,11 @@ func TestSetGCPsAddTwoGCPs(t *testing.T) {
}

// Check `Get` method after settings GCPs
assert.NotEqual(t, nil, vrtDs.GetGCPSpatialRef().handle)
assert.Equal(t, 2, vrtDs.GetGCPCount())
assert.Equal(t, gcpList, vrtDs.GetGCPs())
assert.Equal(t, srWkt, vrtDs.GetGCPProjection())
assert.NotEqual(t, nil, vrtDs.GCPSpatialRef().handle)
gcps = vrtDs.GCPs()
assert.Equal(t, 2, len(gcps))
assert.Equal(t, gcpList, gcps)
assert.Equal(t, srWkt, vrtDs.GCPProjection())
}

func TestSetGCPsAddZeroGCPs(t *testing.T) {
Expand All @@ -4625,10 +4626,10 @@ func TestSetGCPsAddZeroGCPs(t *testing.T) {
defer vrtDs.Close()

// Check `Get` methods before setting GCPs
assert.Equal(t, &SpatialRef{handle: nil, isOwned: false}, vrtDs.GetGCPSpatialRef())
assert.Equal(t, 0, vrtDs.GetGCPCount())
assert.Equal(t, []GCP{}, vrtDs.GetGCPs())
assert.Equal(t, "", vrtDs.GetGCPProjection())
assert.Equal(t, &SpatialRef{handle: nil, isOwned: false}, vrtDs.GCPSpatialRef())
gcps := vrtDs.GCPs()
assert.Equal(t, 0, len(gcps))
assert.Equal(t, "", vrtDs.GCPProjection())

var gcpList []GCP = []GCP{}
sr, err := NewSpatialRefFromEPSG(3857)
Expand All @@ -4645,10 +4646,10 @@ func TestSetGCPsAddZeroGCPs(t *testing.T) {
}

// Check `Get` method after settings GCPs
assert.NotEqual(t, nil, vrtDs.GetGCPSpatialRef().handle)
assert.Equal(t, 0, vrtDs.GetGCPCount())
assert.Equal(t, gcpList, vrtDs.GetGCPs())
assert.Equal(t, srWkt, vrtDs.GetGCPProjection())
assert.NotEqual(t, nil, vrtDs.GCPSpatialRef().handle)
gcps = vrtDs.GCPs()
assert.Equal(t, 0, len(gcps))
assert.Equal(t, srWkt, vrtDs.GCPProjection())
}

func TestSetGCPsInvalidDataset(t *testing.T) {
Expand Down Expand Up @@ -4685,10 +4686,10 @@ func TestSetGCPs2AddTwoGCPs(t *testing.T) {
defer vrtDs.Close()

// Check `Get` methods before setting GCPs
assert.Equal(t, &SpatialRef{handle: nil, isOwned: false}, vrtDs.GetGCPSpatialRef())
assert.Equal(t, 0, vrtDs.GetGCPCount())
assert.Equal(t, []GCP{}, vrtDs.GetGCPs())
assert.Equal(t, "", vrtDs.GetGCPProjection())
assert.Equal(t, &SpatialRef{handle: nil, isOwned: false}, vrtDs.GCPSpatialRef())
gcps := vrtDs.GCPs()
assert.Equal(t, 0, len(gcps))
assert.Equal(t, "", vrtDs.GCPProjection())

var gcpList []GCP = []GCP{
{
Expand Down Expand Up @@ -4724,10 +4725,11 @@ func TestSetGCPs2AddTwoGCPs(t *testing.T) {
}

// Check `Get` method after settings GCPs
assert.NotEqual(t, nil, vrtDs.GetGCPSpatialRef().handle)
assert.Equal(t, 2, vrtDs.GetGCPCount())
assert.Equal(t, gcpList, vrtDs.GetGCPs())
assert.Equal(t, srWkt, vrtDs.GetGCPProjection())
assert.NotEqual(t, nil, vrtDs.GCPSpatialRef().handle)
gcps = vrtDs.GCPs()
assert.Equal(t, 2, len(gcps))
assert.Equal(t, gcpList, gcps)
assert.Equal(t, srWkt, vrtDs.GCPProjection())
}

func TestSetGCPs2AddZeroGCPs(t *testing.T) {
Expand All @@ -4739,10 +4741,10 @@ func TestSetGCPs2AddZeroGCPs(t *testing.T) {
defer vrtDs.Close()

// Check `Get` methods before setting GCPs
assert.Equal(t, &SpatialRef{handle: nil, isOwned: false}, vrtDs.GetGCPSpatialRef())
assert.Equal(t, 0, vrtDs.GetGCPCount())
assert.Equal(t, []GCP{}, vrtDs.GetGCPs())
assert.Equal(t, "", vrtDs.GetGCPProjection())
assert.Equal(t, &SpatialRef{handle: nil, isOwned: false}, vrtDs.GCPSpatialRef())
gcps := vrtDs.GCPs()
assert.Equal(t, 0, len(gcps))
assert.Equal(t, "", vrtDs.GCPProjection())

var gcpList []GCP = []GCP{}
sr, err := NewSpatialRefFromEPSG(3857)
Expand All @@ -4759,10 +4761,10 @@ func TestSetGCPs2AddZeroGCPs(t *testing.T) {
}

// Check `Get` method after settings GCPs
assert.NotEqual(t, nil, vrtDs.GetGCPSpatialRef().handle)
assert.Equal(t, 0, vrtDs.GetGCPCount())
assert.Equal(t, gcpList, vrtDs.GetGCPs())
assert.Equal(t, srWkt, vrtDs.GetGCPProjection())
assert.NotEqual(t, nil, vrtDs.GCPSpatialRef().handle)
gcps = vrtDs.GCPs()
assert.Equal(t, 0, len(gcps))
assert.Equal(t, srWkt, vrtDs.GCPProjection())
}

func TestSetGCPs2InvalidDataset(t *testing.T) {
Expand Down

0 comments on commit bc6630f

Please sign in to comment.