由于数据比较大,放在ftp服务器中,下载到本地再处理比较占空间和费时,gdal可以直接读取ftp中的影像进行处理的,读取也比较简单,注意输入路径的格式即可,参考官网。
路径的组织格式:
"/vsicurl/ftp://user:password@ip:port/global/raw/2022/hanshou/xxx.tif"
"/vsicurl/ftp://"+用户+":"+密码+"@"+ip+":"+端口+路径
int main()
{
std::string file = "/vsicurl/ftp://xxx:xxx@192.168.30.11:6789/global/raw/2022/hanshou/CG/0824_1249_2070_1070/0824_1249_2070_1070/3_dsm_ortho/2_mosaic/0824_1249_2070_1070_transparent_mosaic_group1.tif";
GDALDataset* poDataset;
GDALAllRegister();
poDataset = (GDALDataset*)GDALOpen(file.c_str(), GA_ReadOnly);
if (poDataset == NULL) {
return NULL;
}
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]);
}
return EXIT_SUCCESS;
}