我试图从S3访问一些Landsat数据而不制作文件的本地副本。作为测试,我想在文件上运行一个简单的GetRasterBand,但我不确定如何在不下载文件的情况下将VSILFILE视为GDALDataset。
GDAL API指南声明VSILFILE"不能用于" VSI * L"以外的任何功能。一系列功能。他们不是真实的" FILE对象。"
剪切我的代码:
VSILFILE *poVs3Dataset;
//GDALDataset *poDataset;
GDALRasterBand *poBand;
char * path = (char *)"/vsis3/landsat-pds/c1/L8/139/045/LC08_L1TP_139045_20170304_20170316_01_T1/LC08_L1TP_139045_20170304_20170316_01_T1_B1.TIF";
GDALAllRegister();
VSIInstallS3FileHandler();
CPLSetConfigOption( "AWS_ACCESS_KEY_ID", "XXX" );
CPLSetConfigOption( "AWS_SECRET_ACCESS_KEY", "XXX" );
poVs3Dataset = VSIFOpenL(path, "r");
poBand = poVs3Dataset->GetRasterBand( 1 );
最终并且理所当然地失败了
g ++ -g -L / usr / local / lib -lgdal stats.cpp 错误:'VSILFILE'没有名为'GetRasterBand'的成员
有没有可以解决的好C ++示例?
谢谢!
答案 0 :(得分:1)
在调用可执行文件之前设置我的环境变量似乎有所帮助:
$> env AWS_ACCESS_KEY_ID = xxx AWS_SECRET_ACCESS_KEY = xxx ./a.out /vsis3/landsat-pds/c1/L8/139/045/LC08_L1TP_139045_20170304_20170316_01_T1/LC08_L1TP_139045_20170304_20170316_01_T1_B1.TIF
现在我的测试代码向我自己证明我可以同时访问GDALOpenEx& VSIFOpenExL适用于帮助其他人的情况:
VSILFILE *fpL;
GDALDataset *poDataset;
GDALRasterBand *poBand;
char * path = (char *)"/vsis3/landsat-pds/c1/L8/139/045/LC08_L1TP_139045_20170304_20170316_01_T1/LC08_L1TP_139045_20170304_20170316_01_T1_B1.TIF";
VSIStatBufL sStat;
const char* const apszAllowedDrivers[] = { "GTiff", NULL };
GDALAllRegister();
poDataset = reinterpret_cast<GDALDataset*>(GDALOpenEx(path, GDAL_OF_READONLY | GDAL_OF_RASTER | GDAL_OF_VERBOSE_ERROR, NULL, NULL, NULL));
if( poDataset == NULL )
{
std::cout << "Couldn't open " << std::endl;
}
poBand = poDataset->GetRasterBand( 1 );
int nXSize = poBand->GetXSize();
int nYSize = poBand->GetYSize();
std::cout << "nXSize : " << nXSize << std::endl;
std::cout << "nYSize : " << nYSize << std::endl;
fpL = VSIFOpenExL(path, "rb", 1);
if( fpL != NULL )
{
....
works!!!