Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用GDAL C++;? 我用C++来处理GDAL。< /P>_C++_Gdal - Fatal编程技术网

如何使用GDAL C++;? 我用C++来处理GDAL。< /P>

如何使用GDAL C++;? 我用C++来处理GDAL。< /P>,c++,gdal,C++,Gdal,我有一个创建黑白图像的代码: GDALAllRegister(); GDALDriver *pDriverTiff = GetGDALDriverManager()->GetDriverByName("GTiff"); GDALDataset *pNewDS; pNewDS = pDriverTiff->Create(output, nCols, nRows, 1, GDT_UInt16, NULL); double *transform = geotiff->get_tran

我有一个创建黑白图像的代码:

GDALAllRegister();
GDALDriver *pDriverTiff = GetGDALDriverManager()->GetDriverByName("GTiff");
GDALDataset *pNewDS;
pNewDS = pDriverTiff->Create(output, nCols, nRows, 1, GDT_UInt16, NULL);
double *transform = geotiff->get_transform();
pNewDS->SetProjection(geotiff->get_proj().c_str());
pNewDS->SetGeoTransform(geotiff->get_transform());
float *newRow = (float *) CPLMalloc(sizeof(float)*nCols);
for (int i = 0; i < nRows; i++){
    for (int j = 0; j < nCols; j++){
        newRow[j] = matrix[i * nCols + j];
    }
    pNewDS->GetRasterBand(1)->RasterIO(GF_Write, 0, i, nCols, 1, newRow, nCols, 1, GDT_Float32, 0, 0);
}
GDALClose(pNewDS);
GDALDestroyDriverManager();
GDALAllRegister();
GDALDriver*pDriverTiff=GetGDALDriverManager()->GetDriverByName(“GTiff”);
GDALDataset*pNewDS;
pNewDS=pDriverTiff->Create(输出、nCols、nRows、1、GDT_UInt16、NULL);
double*transform=geotiff->get_transform();
pNewDS->SetProjection(geotiff->get_proj().c_str());
pNewDS->SetGeoTransform(geotiff->get_transform());
float*newRow=(float*)CPLMalloc(sizeof(float)*nCols);
对于(int i=0;iGetRasterBand(1)->光栅(GF_Write,0,i,nCols,1,newRow,nCols,1,GDT_Float32,0,0);
}
GDALClose(pNewDS);
GDALDestroyDriverManager();
而且它工作得完美无瑕

但现在我想创建一个彩色RGB图像。我试着这样做:

GDALAllRegister();
GDALDriver *pDriverTiff = GetGDALDriverManager()->GetDriverByName("GTiff");
GDALDataset *pNewDS;
char* options[] = {"PHOTOMETRIC=RGB", "PROFILE=GeoTIFF"};
pNewDS = pDriverTiff->Create(output, nCols, nRows, 3, GDT_UInt16, options);
double *transform = geotiff->get_transform();
pNewDS->SetProjection(geotiff->get_proj().c_str());
pNewDS->SetGeoTransform(geotiff->get_transform());
float *newRow = (float *) CPLMalloc(sizeof(float)*nCols);
for (int i = 0; i < nRows; i++){
    for (int j = 0; j < nCols; j++){
        newRow[j] = matrix[i * nCols + j];
    }
    pNewDS->GetRasterBand(1)->RasterIO(GF_Write, 0, i, nCols, 1, newRow, nCols, 1, GDT_Float32, 0, 0);
}
for (int i = 0; i < nRows; i++){
    for (int j = 0; j < nCols; j++){
        newRow[j] = matrix[i * nCols + j];
    }
    pNewDS->GetRasterBand(2)->RasterIO(GF_Write, 0, i, nCols, 1, newRow, nCols, 1, GDT_Float32, 0, 0);
}
for (int i = 0; i < nRows; i++){
    for (int j = 0; j < nCols; j++){
        newRow[j] = matrix[i * nCols + j];
    }
    pNewDS->GetRasterBand(3)->RasterIO(GF_Write, 0, i, nCols, 1, newRow, nCols, 1, GDT_Float32, 0, 0);
}
pNewDS->GetRasterBand(1)->SetColorInterpretation(GCI_RedBand);
pNewDS->GetRasterBand(2)->SetColorInterpretation(GCI_GreenBand);
pNewDS->GetRasterBand(3)->SetColorInterpretation(GCI_BlueBand);
GDALClose(pNewDS);
GDALDestroyDriverManager();
GDALAllRegister();
GDALDriver*pDriverTiff=GetGDALDriverManager()->GetDriverByName(“GTiff”);
GDALDataset*pNewDS;
字符*选项[]={“光度控制=RGB”,“轮廓=GeoTIFF”};
pNewDS=pDriverTiff->Create(输出、NCOL、nRows、3、GDT_UInt16、选项);
double*transform=geotiff->get_transform();
pNewDS->SetProjection(geotiff->get_proj().c_str());
pNewDS->SetGeoTransform(geotiff->get_transform());
float*newRow=(float*)CPLMalloc(sizeof(float)*nCols);
对于(int i=0;iGetRasterBand(1)->光栅(GF_Write,0,i,nCols,1,newRow,nCols,1,GDT_Float32,0,0);
}
对于(int i=0;iGetRasterBand(2)->光栅(GF_Write,0,i,nCols,1,newRow,nCols,1,GDT_Float32,0,0);
}
对于(int i=0;iGetRasterBand(3)->光栅(GF_Write,0,i,nCols,1,newRow,nCols,1,GDT_Float32,0,0);
}
pNewDS->GetRasterBand(1)->设置颜色解释(GCI_红带);
pNewDS->GetRasterBand(2)->设置颜色解释(GCI_绿带);
pNewDS->GetRasterBand(3)->设置颜色解释(GCI_蓝带);
GDALClose(pNewDS);
GDALDestroyDriverManager();
但图像仍然是黑白的。如何使它着色