【发布时间】:2018-04-17 22:43:07
【问题描述】:
我正在使用 GDAL/OGR API (C++) 将 XY 点从给定的 Tiff 重新投影到纬度/经度坐标。
我现在可以实现它,但是,我得到的坐标与我试图得到的实际坐标不对应。
我意识到该方法不是读取输入数据集,因此,没有“起点”。
事实上,使用命令行中的gdaltranslate 工具可以提供正确的坐标,因为我将 Tiff 作为参数发送。不幸的是,我不能使用这个命令。
以下是我的代码(到目前为止)和gdaltranslate 的示例,作为输出:
C++ 方法:
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 );
}
输入:x = 1794 y = 6644
输出:(70.527326,0.059926)
命令行:
gdaltransform Karnataka_biomass.tif -t_srs EPSG:4326 -s_srs EPSG:32643
输入:x = 1794 y = 6644
输出:75.7461474090405 12.4826172522718
问题是是否有任何方法可以“读取”C++ 方法中的 Tiff 以获得真正的纬度/经度坐标。我需要吗?
【问题讨论】: