예제 #1
0
        private bool CheckDataSetExists(string filename, Hdf4Operator oper, out Size size, out Type datatype, out int datatypeSize)
        {
            size = new Size(0, 0);
            Size proSize = Size.Empty;

            datatype     = typeof(UInt16);
            datatypeSize = 0;
            foreach (DataSetMosaicInfo item in _currMosaicInfos.DataSetMosaicInfos)
            {
                if (!oper.GetDatasetNames.Contains(item.DataSetName))
                {
                    AddLog(Path.GetFileName(filename) + "的[" + item.DataSetName + "]数据集不存在!");
                    return(false);
                }
                else
                {
                    int bandCount = 0;
                    HDF4Helper.DataTypeDefinitions hdf4DataType = HDF4Helper.DataTypeDefinitions.DFNT_NUINT16;
                    if (GetDataSetSize(item.DataSetName, oper, out size, out bandCount, out hdf4DataType, out datatype, out datatypeSize))
                    {
                        if (proSize.Height == 0 && proSize.Width == 0)
                        {
                            proSize = size;
                        }
                        if (proSize.Width != size.Width || proSize.Height != size.Height)
                        {
                            AddLog(Path.GetFileName(filename) + "的[" + item.DataSetName + "]数据集行列数不一致!");
                            return(false);
                        }
                        proSize = size;
                    }
                }
            }
            return(true);
        }
예제 #2
0
        private bool CheckProjectInfos(string filename, Hdf4Operator oper)
        {
            string arg = "";

            SetAttr(oper.GetAttributes(), _projectNames, ref arg);
            if (!string.IsNullOrEmpty(arg) || !string.IsNullOrEmpty(_currMosaicInfos.Project))
            {
                if ((string.IsNullOrEmpty(arg) || string.IsNullOrEmpty(_currMosaicInfos.Project)) ||
                    arg.Trim().ToUpper() != _currMosaicInfos.Project.Trim().ToUpper())
                {
                    AddLog(Path.GetFileName(filename) + "投影方式不一致!");
                    return(false);
                }
                else if (!string.IsNullOrEmpty(arg) && arg.Trim().ToUpper().IndexOf("GLL") == -1)
                {
                    SetAttr(oper.GetAttributes(), _projectArgsNames, ref arg);
                    if ((string.IsNullOrEmpty(arg) || string.IsNullOrEmpty(_currMosaicInfos.ProjectArgs)) ||
                        arg.Trim().ToUpper() != _currMosaicInfos.ProjectArgs.Trim().ToUpper())
                    {
                        AddLog(Path.GetFileName(filename) + "投影参数不一致!");
                        return(false);
                    }
                }
            }
            return(true);
        }
예제 #3
0
 public override Dictionary <string, string> GetDatasetAttributes(string datasetName)
 {
     using (IHdfOperator hdf = new Hdf4Operator(_provider.fileName))
     {
         return(hdf.GetAttributes(datasetName));
     }
 }
예제 #4
0
 private void GetFileAttrInfos(FileListItem fli)
 {
     if (HDF4Helper.IsHdf4(fli.FileName))
     {
         Hdf4Operator oper = new Hdf4Operator(fli.FileName);
         try
         {
             Dictionary <string, string> fileAtrr = null;
             if (oper != null)
             {
                 fileAtrr = oper.GetAttributes();
                 if (fileAtrr != null)
                 {
                     InitFileAttr(fileAtrr);
                 }
                 else
                 {
                     ClearFileAtrr();
                 }
                 InitDataset(oper.GetDatasetNames, oper);
             }
         }
         catch (Exception ex)
         {
             AddLog(fli.FileName + "文件读取失败:" + ex.Message);
         }
         finally
         {
             if (oper != null)
             {
                 oper.Dispose();
             }
         }
     }
 }
예제 #5
0
        public override IRasterBand[] GetDefaultBands()
        {
            if (_matchedBandProviderDef == null || _matchedBandProviderDef.DefaultBandDatasetDefs == null || _matchedBandProviderDef.DefaultBandDatasetDefs.Count == 0)
            {
                return(null);
            }
            IBandNameParser bandNameParser = new DefaultBandNameParser();

            using (Hdf4Operator hdf4 = new Hdf4Operator(_provider.fileName))
            {
                List <IRasterBand> rasterBands = new List <IRasterBand>();
                foreach (DefaultBandDatasetDef dsdef in _matchedBandProviderDef.DefaultBandDatasetDefs)
                {
                    string        bandNos = hdf4.GetAttributeValue(dsdef.Name, dsdef.BandNoAttribute);
                    BandName[]    bNames  = bandNameParser.Parse(bandNos);
                    Dataset       ds      = Gdal.Open(ToDatasetFullName(dsdef.Name), _access);
                    IRasterBand[] rBands  = ReadBandsFromDataset(ds, _provider);
                    rasterBands.AddRange(rBands);
                    for (int i = 0; i < rBands.Length; i++)
                    {
                        rBands[i].Description = bNames[i].Name;
                        rBands[i].BandNo      = bNames[i].Index;
                    }
                }
                rasterBands.Sort();
                return(rasterBands.Count > 0 ? rasterBands.ToArray() : null);
            }
        }
예제 #6
0
        private string TryGetDayOrnight(Hdf4Operator hdf)
        {
            string dayornight = hdf.GetAttributeValue("DAYNIGHTFLAG");

            if (string.IsNullOrWhiteSpace(dayornight))
            {
                return(null);
            }
            dayornight = dayornight.Trim();
            string up = dayornight.ToUpper();

            if (up == "DAY" || up == "D")
            {
                return("Day");
            }
            else if (up == "NIGHT" || up == "N")
            {
                return("Night");
            }
            else if (up == "BOTH")
            {
                return("Night");
            }
            else
            {
                return(dayornight);//默认为白天
            }
        }
 public override Dictionary <string, string> GetAttributes()
 {
     using (Hdf4Operator hdf4 = new Hdf4Operator(_provider.fileName))
     {
         return(hdf4.GetAttributes());
     }
 }
 public override string[] GetDatasetNames()
 {
     using (Hdf4Operator hdf4 = new Hdf4Operator(_provider.fileName))
     {
         return(hdf4.GetDatasetNames);
     }
 }
예제 #9
0
        private void lstDataSets_SelectedIndexChanged(object sender, EventArgs e)
        {
            ClearDataSetCombox();
            if (lstDataSets.SelectedItems.Count == 0 || lstDataSets.SelectedItems[0].Tag == null ||
                lstFileInfoList.SelectedItems.Count == 0 || (lstFileInfoList.SelectedItems[0]).Tag == null)
            {
                return;
            }
            FileListItem      fli = (lstFileInfoList.SelectedItems[0]).Tag as FileListItem;
            DataSetMosaicInfo dsi = lstDataSets.SelectedItems[0].Tag as DataSetMosaicInfo;

            if (fli == null)
            {
                return;
            }
            if (HDF4Helper.IsHdf4(fli.FileName))
            {
                Hdf4Operator oper = new Hdf4Operator(fli.FileName);
                try
                {
                    Dictionary <string, string> datasetAtrr = new Dictionary <string, string>();
                    if (oper != null)
                    {
                        datasetAtrr = oper.GetAttributes(dsi.DataSetName);
                        if (datasetAtrr != null)
                        {
                            InitDataSetAttr(datasetAtrr, ref dsi);
                        }
                        Size size      = Size.Empty;
                        int  bandCount = 0;
                        Type datatype;
                        int  datatypeSize = 0;
                        HDF4Helper.DataTypeDefinitions hdf4DataType = HDF4Helper.DataTypeDefinitions.DFNT_NUINT16;
                        if (GetDataSetSize(dsi.DataSetName, oper, out size, out bandCount, out hdf4DataType, out datatype, out datatypeSize))
                        {
                            InitHeigthWidth(size.Width, size.Height, bandCount, ref dsi);
                            if (dsi != null)
                            {
                                dsi.HDF4DataType = hdf4DataType;
                            }
                        }
                    }
                }
                finally
                {
                    if (oper != null)
                    {
                        oper.Dispose();
                    }
                }
            }
        }
예제 #10
0
        private bool GetDataSetSize(string datasetName, Hdf4Operator oper, out Size size, out int bandCount, out HDF4Helper.DataTypeDefinitions hdf4DataType, out Type datatype, out int datatypeSize)
        {
            StringBuilder sds_name = new StringBuilder();
            int           rank     = 0;

            int[] dimsizes = null;
            datatype     = typeof(UInt16);
            datatypeSize = 0;
            hdf4DataType = HDF4Helper.DataTypeDefinitions.DFNT_NUINT16;
            oper.GetDataSizeInfos(datasetName, out rank, out dimsizes, out hdf4DataType, out datatype, out datatypeSize);
            size      = new Size(0, 0);
            bandCount = 1;
            switch (rank)
            {
            case 1:
                size      = new Size(dimsizes[0], -1);
                bandCount = 1;
                break;

            case 2:
                size      = new Size(dimsizes[1], dimsizes[0]);
                bandCount = 1;
                break;

            case 3:
                if (dimsizes[0] == dimsizes.Min())
                {
                    size = new Size(dimsizes[2], dimsizes[1]);
                }
                else if (dimsizes[1] == dimsizes.Min())
                {
                    size = new Size(dimsizes[2], dimsizes[0]);
                }
                else if (dimsizes[2] == dimsizes.Min())
                {
                    size = new Size(dimsizes[1], dimsizes[0]);
                }
                bandCount = dimsizes.Min();
                break;

            default:
                return(false);
            }
            return(true);
        }
예제 #11
0
        private void InitDataset(string[] dataset, Hdf4Operator oper)
        {
            lstDataSets.Items.Clear();
            if (dataset == null || dataset.Length == 0)
            {
                return;
            }
            ListViewItem lvi = null;
            Dictionary <string, string> attValues = null;

            foreach (string item in dataset)
            {
                lvi       = new ListViewItem(item);
                attValues = oper.GetAttributes(item);
                lvi.SubItems.Add(attValues != null && attValues.ContainsKey("long_name") ? attValues["long_name"] : "");
                lvi.Tag     = new DataSetMosaicInfo(item);
                lvi.Checked = true;
                lstDataSets.Items.Add(lvi);
            }
        }
예제 #12
0
        private bool CheckRegion(string filename, Hdf4Operator oper, out HdrFile.Envelope envelope)
        {
            envelope = null;
            string lefrupArg = "";

            SetAttr(oper.GetAttributes(), _leftupPointNames, ref lefrupArg);
            if (string.IsNullOrEmpty(lefrupArg))
            {
                AddLog(Path.GetFileName(filename) + "左上角坐标未找到!");
                return(false);
            }
            string ringhtDownArg = "";

            SetAttr(oper.GetAttributes(), _rightDownPointNames, ref ringhtDownArg);
            if (string.IsNullOrEmpty(ringhtDownArg))
            {
                AddLog(Path.GetFileName(filename) + "右下角坐标未找到!");
                return(false);
            }
            envelope = GetEnvelopeByAttr(lefrupArg, ringhtDownArg);
            return(true);
        }
예제 #13
0
        private void TryGetBandProviderDefinition(string fname, Dictionary <string, string> subdatasets)
        {
            List <string> datasetNames = null;

            if (subdatasets != null)
            {
                datasetNames = GetDatasetNames(subdatasets);
            }
            BandProviderDef[] bandProviderDefs = null;
            //Console.WriteLine(this.GetType().Assembly.Location);
            string configfile = Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.Location), "GeoDo.RSS.DF.GDAL.H4BandPrd.xml");

            using (H4BandProviderXmlParser xml = new H4BandProviderXmlParser(configfile))
            {
                bandProviderDefs = xml.GetBandProviderDefs();
            }
            if (bandProviderDefs == null)
            {
                return;
            }
            string dayornight = "";

            using (Hdf4Operator hdf = new Hdf4Operator(fname))
            {
                foreach (BandProviderDef prddef in bandProviderDefs)
                {
                    bool isMatched = true;
                    if (datasetNames != null)
                    {
                        foreach (DefaultBandDatasetDef bandDef in prddef.DefaultBandDatasetDefs)
                        {
                            if (!datasetNames.Contains(bandDef.Name))
                            {
                                isMatched = false;
                                break;
                            }
                        }
                        if (!isMatched)
                        {
                            continue;
                        }
                    }
                    foreach (IdentifyAttDef id in prddef.IdentifyAttDefs)
                    {
                        string attvalue = hdf.GetAttributeValue(id.Name);
                        if (attvalue != id.Value)
                        {
                            isMatched = false;
                            break;
                        }
                    }
                    //增加对网站下载MODIS数据的支持,数据未在属性中定义卫星、传感器信息
                    if (!isMatched)
                    {
                        DataIdentify di = DataIdentifyMatcher.Match(fname);
                        if (di != null && !string.IsNullOrEmpty(di.Satellite))
                        {
                            foreach (IdentifyAttDef id in prddef.IdentifyAttDefs)
                            {
                                if (di.Satellite.ToUpper() == id.Value.ToUpper())
                                {
                                    isMatched = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (isMatched)
                    {
                        _matchedBandProviderDef = prddef;
                        break;
                    }
                }
                dayornight = TryGetDayOrnight(hdf);
            }
            if (_matchedBandProviderDef != null)
            {
                _dataIdentify         = new DataIdentify(_matchedBandProviderDef.Satellite, _matchedBandProviderDef.Sensor);
                _dataIdentify.IsOrbit = true;
                TrySetIdentifyByName(fname);
                TryGetOrbitDirection(dayornight, _matchedBandProviderDef.Satellite);
            }
        }