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

SetGCPs in the HFA driver #4591

Closed
ctraizet opened this issue Oct 4, 2021 · 0 comments
Closed

SetGCPs in the HFA driver #4591

ctraizet opened this issue Oct 4, 2021 · 0 comments
Assignees

Comments

@ctraizet
Copy link

ctraizet commented Oct 4, 2021

Expected behavior and actual behavior.

In the GDALDataset API, SetGCPs should return CE_None on success and CE_Failure on error, for example if the driver does not support GCP writing.

However when using SetGCPs on a HFA dataset (with a non empty GCP list), the method returns CE_None, but it seems that no GCP is added to the dataset, GetGCPCount returns 0.

GDALPAMDataset is the base class of HFADataset and HFADataset uses its implementation of SetGCPs. When calling the method, the GCP are added to the .aux.xml file. But HFADataset implements its own version of GetGCPs, which doesn't return the GCPs of the .aux.xml file.

I don't know if the HFA driver should support GCP writing, but I think the SetGCPs method should return the correct error code if it does not.

Steps to reproduce the problem.

In command line, using an input image with GCPs

gdal_translate -of HFA /inputWithGCP.tif out.img

will create a out.img.aux.xml file containing gcps, but gdalinfo will not report the GCPs

In c++

#include "gdal_priv.h"
#include <iostream>

int main(int argc, char* argv[])
{
  auto inFilename = argv[1];
  auto outFilename = argv[2];
  auto format = argv[3];

  GDALDataset  *poDataset;
  GDALAllRegister();
  
  GDALDriver *poDriver = GetGDALDriverManager()->GetDriverByName(format);

  GDALDataset *poSrcDS = (GDALDataset *) GDALOpen( inFilename, GA_ReadOnly );
  GDALDataset *poDstDS;
  poDstDS = poDriver->CreateCopy( outFilename, poSrcDS, FALSE,
                                NULL, NULL, NULL );

  // CreateCopy also set the GCPs (I suppose?), this call is just here to highlight the problem
  auto success = poDstDS->SetGCPs(poSrcDS->GetGCPCount(), poSrcDS->GetGCPs(), poSrcDS->GetGCPProjection());

  // SetGCPs returns CE_None on success, and should report CE_Failure if the driver does not support gcp writing
  std::cout << "success: " << (success == CE_None) << std::endl;  // success: 1
  std::cout << "Number of input gcps: " << poSrcDS->GetGCPCount() << std::endl; // Number of input gcps: 4
  std::cout << "Number of output gcps: " << poDstDS->GetGCPCount() << std::endl; // Number of output gcps: 0

  if( poDstDS != NULL )
      GDALClose( (GDALDatasetH) poDstDS );
  GDALClose( (GDALDatasetH) poSrcDS );

  return 0;
}

Operating system

Ubuntu 20.04 64 bit

GDAL version and provenance

GDAL 3.0.4 installed with apt, also reproduced on a compiled 3.2.2 GDAL

@rouault rouault self-assigned this Oct 6, 2021
@rouault rouault closed this as completed in 103cca9 Oct 7, 2021
rouault added a commit that referenced this issue Oct 7, 2021
HFA: enable to read GCPs from PAM .aux.xml (fixes #4591)
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

No branches or pull requests

2 participants