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 a gdal::GCP class to make GCP handling from C++ easier #9285

Merged
merged 10 commits into from
Mar 11, 2024

Conversation

rouault
Copy link
Member

@rouault rouault commented Feb 22, 2024

GDAL_GCP is a C-only structure. The typical/recommended pattern to create GCPs from C is:

GDAL_GCP* gcps = (GDAL_GCP*)CPLMalloc( count * sizeof(GDAL_GCP) );
GDALInitGCPs( count, gcps );  // zero-initialize  pixel,line,x,y,z double members of each gcps[], and affects a CPLStrdup("") string to pszId and pszInfo members of each gcps[]
CPLFree(gcps[0].pszId); // free the initial empty string
gcps[0].pszId = CPLStrdup("foo"); // for example
GDALDeinitGCPs( count, gcps ); // free memory of gcps[i].pszId and gcps[i].pszInfo
CPLFree(gcps); // free the array itself

This is "fine" for a C user, but quite tedious in a C++ context. Big users of creating GCPs are GDAL drivers themselves.

So we introduce a gdal::GCP class that has a single GDAL_GCP private member, and handle memory allocation/deallocation, with helpers to navigate between the C and C++ worlds.

No attempt has been made (yet?) to modify the C++ API, in particularly the GDALDataset::GetGCPCount(), GetGCPs(), SetGCPs() method. I guess we'd need to keep the existing methods to avoid breaking external code, as wrappers over new methods that would return / accept std::vector<gdal::GCP>

(This is an alternative to the messy earlier attempt of #9191)

@dg0yt @dbaston thoughts?

@rouault rouault force-pushed the gcp_cppification branch 2 times, most recently from 13c03f3 to 84f0c44 Compare February 22, 2024 21:52
@rouault rouault marked this pull request as draft February 22, 2024 22:47
@coveralls
Copy link
Collaborator

coveralls commented Feb 22, 2024

Coverage Status

coverage: 68.831% (+0.006%) from 68.825%
when pulling 1e7aed6 on rouault:gcp_cppification
into 64cf9b4 on OSGeo:master.

@rouault
Copy link
Member Author

rouault commented Feb 26, 2024

@elpaso any opinion on this?

@elpaso
Copy link
Collaborator

elpaso commented Feb 26, 2024

@elpaso any opinion on this?

Good work!
Much nicer to use for C++ consumers.

@rouault rouault changed the title [WIP] Add a gdal::GCP class to make GCP handling from C++ easier Add a gdal::GCP class to make GCP handling from C++ easier Feb 26, 2024
@rouault rouault marked this pull request as ready for review February 26, 2024 16:09
@rouault
Copy link
Member Author

rouault commented Feb 26, 2024

This is ready for review

@rouault rouault merged commit f1edddc into OSGeo:master Mar 11, 2024
32 checks passed
@rouault rouault added this to the 3.9.0 milestone Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants