如何将JSON文件中的数据转换为值(double,int ..)
How to Convert Data in Json File to Values (double,int...)
我是JSON文件的新手,所以这可能是一个非常愚蠢的错误:
我使用c 中的gdal将形状文件转换为geojson文件。我使用的代码是C 的GDAL API中显示的代码(链接(。我正确读取了形状文件,然后将其转换为带有以下代码的JSON文件
char * json_poly = Polygon->exportToJson();
Json::Value GeoJson;
Json::Reader reader;
reader.parse(json_poly,GeoJson);
多边形是GDAL对象。现在Geojson是一个JSON ::值,看起来像这样
"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
]
但是,当我尝试用简单的循环计算质心时,例如在以下片段
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;
我得到以下错误
no match for ‘operator+=’ (operand types are ‘double’ and ‘Json::Value’)
,如果我尝试将值施放为double double(GeoJson["coordinates"][0][i][0])
,我会得到以下错误
error: invalid cast from type ‘Json::Value’ to type ‘double’
如何施放值以与它们进行算术操作?
链接在主题下说明"获取数据集信息"
double adfGeoTransform[6];
printf("Driver: %s/%sn", poDataset->GetDriver()->GetDescription(),
poDataset->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME ) );
printf("Size is %dx%dx%dn",
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] );
}
virtual CPLErr GetGeoTransform (double *padfTransform)
在此处记录:link
相关文章:
- C++在数学计算中将double转换为int
- 使输出流式处理运算符适用于 boost::variant<std::vector<int>、int、double 的正确方法是什么>
- 进程为包含double但不包含int的模板返回了-103741819(0xC0000005)
- 在C++中,为什么int可以使用new运算符初始化变量,而double不能
- 错误:"int pow(double,int)"与上一个声明int pov(double a,int
- 重载函数 int vs double
- 如何修复 E2015 "ambiguity between pow(double,double) and pow(float,int)"
- 用于检查"is int"/"is double"/等的模板函数
- 使用 double 在 C++ 中初始化 int 之间的差异
- 如何为包含map<int,*double>成员的类编写析构函数?
- 如何使用 JNI 将 double 和无符号 int 从本机 c 库返回到 java
- 对类似"struct {double, int}"对象使用reinterpret_cast进行对象访问
- 函数将double/int转换为字符串
- c++中从double/int/string到bool的自动转换
- 共享库从 void * "invalid conversion" 到 double(*) (int*) 时出错?
- 无效的数组下标类型' double[int] '
- 错误cv::SURF::SURF(double,int,int,bool,bool)在OpenCV和c++中实现SURF
- 我面临这个:我的程序中数组下标的无效类型"double[int]"
- 算术问题(double = int / int)
- 为什么从c++ 11中删除了std::pow(double, int) ?