GDAL读取HDF,NETCDF等subdatasets数据(多个数据集数据) 您所在的位置:网站首页 matlab读取hdf5文件多个数据集 GDAL读取HDF,NETCDF等subdatasets数据(多个数据集数据)

GDAL读取HDF,NETCDF等subdatasets数据(多个数据集数据)

2023-11-26 18:11| 来源: 网络整理| 查看: 265

 

          由于modis卫星数据(HDF数据)跟我们经常遇到的geotif数据组织方式不一样,读取的时候一定要特别注意。geotif数据,一般是一个文件,包含了多个波段的数据;而modis呢,一个文件包含了多各SUBdatasets 。GDAL,每个subdataset又包含多个波段数据。另外默认编译的GDAL并不包含对MODIS数据支持,需要单独下载针对HDF4,HDF5的源码,再修改下make.opt文件,这时再编译GDAL,就支持modis数据的读写了。如果嫌麻烦就下载一个别人编译好了的来用,网上有很多基于GDAL的开源项目,搜一下就可以了。       下面给一个例子,关键GDAL读取hdf数据、netcdf数据集、NTIF数据等多个数据集的数据格式;

#include #include #includeusing namespace std;#include#include gdal.h"#include gdal_priv.h"#include ogr_srs_api.h"#include cpl_string.h"#include cpl_conv.h"#pragma comment (lib,"..//lib//gdal_i.lib")int main(int argc, char *argv[]){        GDALAllRegister();    vector datasets;              char *   hdfFileName="D://fsbdata//V2KRNS10__20060411_NDVI__SE-Asia//0001//0001_NDV.HDF";    GDALDataset *tmpDataset = (GDALDataset *) GDALOpen( hdfFileName, GA_ReadOnly);    if(tmpDataset==NULL) return 0;    GDALDriver * driver=tmpDataset->GetDriver ();    string papszMetadata=GDALGetDriverShortName((GDALDriverH)tmpDataset);        int index=papszMetadata.find_first_of("hdf");    if(index            printf( "Subdatasets:/n" );            for(int  i = 0; SUBDATASETS[i] != NULL; i++ )            {                if(i%2==0)                {                    string tmpstr=string(SUBDATASETS[i]);                    tmpstr=tmpstr.substr(tmpstr.find_first_of("=")+1);                    const char *tmpfilename=tmpstr.c_str();                    GDALDataset * tmpdt=(GDALDataset *) GDALOpen(tmpfilename, GA_ReadOnly);                    if(tmpdt)                    {                        datasets.push_back(tmpdt);                    }                }                        }        }        else        {            int bandCount=tmpDataset->GetRasterCount();            if(bandCount>0)            {                GDALRasterBand * poband=tmpDataset->GetRasterBand(1);            }            printf( "it contains %d bands! /n",bandCount);        }    }    if(!datasets.empty())    {        int count=datasets.size();        int bandCount=0;        for(int i=0;iGetRasterCount();            if(datasets[i]->GetRasterCount()>0)            {                GDALRasterBand * poband=datasets[i]->GetRasterBand(1);            }        }        printf( "it contains %d bands! /n",bandCount);        for(i=0;i



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有