Arcgis的坐标参考文件一般是以.prj为后缀
即
std::string strPrj1 = "ESRI::" + strProjFileName1;
OGRSpatialReference oSourceSRS;
oSourceSRS.SetFromUserInput(strPrj1.c_str());
std::string strPrj2 = "ESRI::" + strProjFileName2;
OGRSpatialReference oTargetSRS;
oTargetSRS.SetFromUserInput(strPrj2.c_str());
//坐标系转换
double srcX = 120.235842;
double srcY = 30.222458;
double x = srcX;
double y = srcY;
OGRCoordinateTransformation *poCT = OGRCreateCoordinateTransformation(&oSourceSRS,
&oTargetSRS);
if (poCT == NULL || !poCT->Transform(1, &x, &y))
printf("Transformation failed.\n");
else
{
printf("(%f,%f) ->(%f,%f)\n", srcX, srcY, x, y);
}
因为如果解析字符串,容易出错