C++ 如何将Json文件中的数据转换为值(double、int…)

C++ 如何将Json文件中的数据转换为值(double、int…),c++,json,geojson,gdal,C++,Json,Geojson,Gdal,我不熟悉JSON文件,因此这可能是一个非常愚蠢的错误: 我已经用C++中的GDAL将形状文件转换成GeJiSon文件。我使用的代码是在C++中的GDAL API中显示的代码。我正确地读取了shape文件,然后使用以下代码将其转换为JSON文件 char * json_poly = Polygon->exportToJson(); Json::Value GeoJson; Json::Reader reader; reader.parse(json_poly,

我不熟悉JSON文件,因此这可能是一个非常愚蠢的错误:

我已经用C++中的GDAL将形状文件转换成GeJiSon文件。我使用的代码是在C++中的GDAL API中显示的代码。我正确地读取了shape文件,然后使用以下代码将其转换为JSON文件

    char * json_poly = Polygon->exportToJson();
    Json::Value GeoJson;
    Json::Reader reader;
    reader.parse(json_poly,GeoJson);
其中多边形是GDAL对象。现在GeoJson是一个JSON::VALUE,如下所示

   "coordinates" : 
    [
            [
                    [
                            586417.77972987387,
                            6884063.8642021669
                    ],
                    [
                            586655.1163914972,
                            6884198.7810712075
                    ],
                    [
                            586707.31919375062,
                            6884238.8010942638
                    ],
                    [
                            586703.2053746446,
                            6884258.7722300319
                    ],
                    [
                            586754.77872091066,
                            6884309.6043649064
                    ],
                    [
                            586832.7780266488,
                            6884413.5168099366
                    ]
但是当我试图用一个简单的for循环来计算质心时,就像下面的代码片段一样

double x = 0 ; 
double y = 0 ; 
for( int i = 0 ; i < GeoJson["coordinates"][0].size() ; i++ )
{
    x +=  GeoJson["coordinates"][0][i][0];
    y +=  GeoJson["coordinates"][0][i][1];
}
x /=  GeoJson["coordinates"][0].size() ;
y /=  GeoJson["coordinates"][0].size() ;

cout << "The centroid is in " << x<< " , " << y << endl;
如果我尝试将值转换为double doubleGeoJson[coordinates][0][I][0],我会得到以下错误

 no match for ‘operator+=’ (operand types are ‘double’ and ‘Json::Value’)
error: invalid cast from type ‘Json::Value’ to type ‘double’
如何转换这些值,以便对它们进行算术运算

在“获取数据集信息”主题下进行解释

double        adfGeoTransform[6];
printf("Driver: %s/%s\n", poDataset->GetDriver()->GetDescription(),
       poDataset->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME ) );
printf("Size is %dx%dx%d\n",
       poDataset->GetRasterXSize(), poDataset->GetRasterYSize(),
       poDataset->GetRasterCount() );
if( poDataset->GetProjectionRef()  != NULL )
    printf( "Projection is `%s'\n", poDataset->GetProjectionRef() );
if( poDataset->GetGeoTransform( adfGeoTransform ) == CE_None )
{
    printf( "Origin = (%.6f,%.6f)\n",
            adfGeoTransform[0], adfGeoTransform[3] );
    printf( "Pixel Size = (%.6f,%.6f)\n",
            adfGeoTransform[1], adfGeoTransform[5] );
}

虚拟CPLRR GETGEATION双*PADFFATH在此被记录:

我如何铸造值-如果你使用的库依赖于你铸造东西,我会感到惊讶。需要强制转换违背C++所提供的类型安全性。可能有一些成员功能可以完成这项工作。谢谢您的评论。我正在使用以下库,包括OK,我在这里找到了答案。谢谢你指出了正确的方向@PaulMcKenzie。