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); } }
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);//默认为白天 } }
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); } }