I'm using the GDAL/OGR API (C++) to reproject XY points into Lat/Long coordinates from a given Tiff.
I'm able to achieve it right now, but, the coordenates that i am getting do not correspond to the actual coordinates i am trying to get.
I realized that the method is not reading the input dataset, so, there is not an "starting point".
In fact, using the gdaltranslate
tool from the command line, gives the right corrdinates, because i am sending the Tiff as a parameter. Unfortunately, i cannot afford the use of this command.
Below is my code (so far) and the example of gdaltranslate
, as the outputs:
C++ Method:
void reproject_coords(string map_biomass) {
GDALDataset *dataset;
GDALAllRegister();
string ds = map_biomass;
dataset = (GDALDataset *) GDALOpen(ds.c_str(), GA_ReadOnly);
OGRSpatialReference source(dataset->GetMetadata()), target;
OGRCoordinateTransformation *poCT;
target.importFromEPSG(4326);
//source.AutoIdentifyEPSG();
//source.SetWellKnownGeogCS("32643");
double x = 1794, y = 6644;
//source.dumpReadable();
poCT = OGRCreateCoordinateTransformation(&source, &target);
if( poCT == NULL || !poCT->Transform( 1, &x, &y ) )
printf( "Transformation failed.\n" );
else
printf( "(%f,%f)\n",
x, y );
}
Input: x = 1794 y = 6644
Output: (70.527326,0.059926)
Command Line:
gdaltransform Karnataka_biomass.tif -t_srs EPSG:4326 -s_srs EPSG:32643
Input: x = 1794 y = 6644
Output: 75.7461474090405 12.4826172522718
The question is if is there any way to "read" the Tiff in the C++ Method in order to get the real Lat/Long coords. I need?