GDAL进行坐标转换的前提是GDAL在编译的时候引入了PROJ库,GDAL的坐标转换功能是基于PROJ库实现的
参考代码
#include <gdal_priv.h>
#include <iostream>
using namespace std;
int main()
{
OGRSpatialReference ssr;
ssr.SetWellKnownGeogCS("WGS84");
OGRSpatialReference dsr;
dsr.importFromEPSG(3857);
OGRCoordinateTransformation * OGRCT = OGRCreateCoordinateTransformation(&ssr, &dsr);
if (OGRCT == NULL)
{
cout << "Fail to create OGRCoordinateTransformation!" << endl;
return 0;
}
double y[] = { 121};
double x[] = { 31 };
OGRCT->Transform(1, x, y, NULL);
cout << "转换后点的坐标为:" << endl;
cout << x[i] << " " << y[i] << endl;
system("pause");
return 0;
}