GDAL的点投影转换

GDALAllRegister(); GDALDatasetH hSrcDS = GDALOpen(strInImg, GA_ReadOnly); double padfTransform[6]; GDALGetGeoTransform(hSrcDS,padfTransform); double x = padfTransform[0]; double y = padfTransform[3]; OGRSpatialReference oSRS; OGRCoordinateTransformation *poTransform = NULL; OGRSpatialReference *poLatLong = NULL; const char * pszProjection = GDALGetProjectionRef(hSrcDS); //获得原图像地理参考坐标系。 if( oSRS.importFromWkt( (char **) &pszProjection ) != OGRERR_NONE ) { CPLError( CE_Failure, CPLE_AppDefined, "Failed to import coordinate system `%s'.", pszProjection ); } poLatLong = oSRS.CloneGeogCS(); // poTransform = OGRCreateCoordinateTransformation( poLatLong, &oSRS ); poTransform = OGRCreateCoordinateTransformation(&oSRS,poLatLong); if( poTransform != NULL ) poTransform->Transform( 1, &x, &y, NULL ); CString a; a.Format("%lf %lf %lf %lf ",x,y,padfTransform[0],padfTransform[3]); AfxMessageBox(a); if( poTransform != NULL ) delete poTransform; if( poLatLong != NULL ) delete poLatLong;

你可能感兴趣的:(GDAL相关应用)