我得到了这段代码来将地理投影设置为 GeoTiff 文件。
poDataset = (GDALDataset *) GDALOpen( fileName.c_str(), GA_Update);
OGRSpatialReference oSRS;
char *pszSRS_WKT = NULL;
oSRS.SetWellKnownGeogCS( "WGS84" );
oSRS.exportToWkt( &pszSRS_WKT );
oSRS.SetProjCS( pszSRS_WKT );
std::cout<<"Setted Proj: "<<pszSRS_WKT<<endl;
CPLErr err = poDataset->SetProjection( pszSRS_WKT );
std::cout<<"Proj Error: "<<err<<endl;
double adfGeoTransform[6];
CPLErr err2 = poDataset->GetGeoTransform( adfGeoTransform );
std::cout<<"Error: "<<err2<<endl;
std::string str = poDataset->GetProjectionRef();
std::cout<<"Retrieved Proj: "<<str<<endl;
结果是
Proj: GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,A
UTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM
["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHOR
ITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]]**
Proj Error: 0
Error: 3
Retrieved Proj:
代码看起来很合理,这个错误的原因可能是什么?
提前致谢