美文网首页开源
C++ gdal 地心坐标系转wgs84坐标系

C++ gdal 地心坐标系转wgs84坐标系

作者: hehehehe | 来源:发表于2019-10-24 19:48 被阅读0次
#include<iostream>
#include"gdal_priv.h"
using namespace std;

int main() {

    //CPLSetConfigOption("GDAL_DATA", "gdaldata");

    //OGRSpatialReference* pMySR = new OGRSpatialReference;
    //pMySR->SetWellKnownGeogCS("EPSG:4326");

    //OGRSpatialReference spatialReference;
    //spatialReference.importFromEPSG(4610);
    //char* pszWKT = nullptr;
    //spatialReference.exportToPrettyWkt(&pszWKT);


    OGRSpatialReference oSourceSRS, oTargetSRS;
    OGRCoordinateTransformation* poCT;
    double x, y, z;

    oTargetSRS.importFromEPSG(4326);
    oSourceSRS.importFromProj4("+proj=geocent +datum = WGS84 +units = m +no_defs");
    char* pszWKT = nullptr;
    oSourceSRS.exportToPrettyWkt(&pszWKT);
    cout << pszWKT << endl;

    poCT = OGRCreateCoordinateTransformation(&oSourceSRS, &oTargetSRS);
    x = -2253592.8895144262;
    y = 5018382.544662854;
    z = 3216871.543521031;
    if (poCT == NULL || !poCT->Transform(1, &x, &y, &z))
        printf("Transformation failed.\n");
    else
        printf("%0.15f,%0.15f\n", x, y);


    return 0;
}

相关文章

网友评论

    本文标题:C++ gdal 地心坐标系转wgs84坐标系

    本文链接:https://www.haomeiwen.com/subject/bbgdvctx.html