private void TryGetInfosFromRasterProvider(string fname) { string extension = Path.GetExtension(fname).ToUpper(); foreach (string ext in EXTENSIONS) { if (extension == ext) { return; } } if (!File.Exists(fname)) { return; } AbstractWarpDataset prd = null; //IGeoDataDriver id = null; try { prd = WarpDataset.Open(fname); if (prd != null) { _projectName = GetProjectionIdentify(prd.SpatialRef.GetAttrValue("GEOGCS", 0)); DataIdentify df = prd.DataIdentify; if (string.IsNullOrEmpty(Satellite) || Satellite.ToUpper() == "NUL") { Satellite = df.Satellite; } if (string.IsNullOrEmpty(Sensor) || Sensor.ToUpper() == "NUL") { Sensor = df.Sensor; } if (OrbitDateTime == DateTime.MinValue) { OrbitDateTime = df.OrbitDateTime; } if (string.IsNullOrWhiteSpace(Resolution) || Resolution == "NULL") { Resolution = TryGetResolution(prd.ResolutionX); } } } catch { } finally { if (prd != null) { prd.Dispose(); } } }
private void TryGetProject(string fname) { AbstractWarpDataset prd = WarpDataset.Open(fname); try { if (prd != null) { _projectName = GetProjectionIdentify(prd.SpatialRef.GetAttrValue("GEOGCS", 0)); } } finally { if (prd != null) { prd.Dispose(); } } }
private void TryMosaicFile(InputArg inArg, AbstractWarpDataset fileRaster, RasterDatasetInfo dataIdentify, DateTime dateTime, string dayOrNight) { if (inArg.MosaicInputArg == null || string.IsNullOrWhiteSpace(inArg.MosaicInputArg.OutputDir) || inArg.MosaicInputArg.Envelope == null) { return; } //if (!Day.Contains(dayOrNight)) //{ // Console.WriteLine("非白天数据,不执行拼接"); // return; //} MosaicInputArg mosaicInputArg = inArg.MosaicInputArg; string projectionIdentify = inArg.ProjectionIdentify; string station = ParseStation(inArg.InputFilename); MosaicOutputArg outArg = new MosaicOutputArg(); outArg.Satellite = dataIdentify.SatelliteID; outArg.Sensor = dataIdentify.SensorID; outArg.Level = "L1"; outArg.ProjectionIdentify = projectionIdentify; outArg.ObservationDate = dateTime.ToString("yyyyMMdd"); outArg.Station = station; outArg.DayOrNight = dayOrNight; AbstractWarpDataset mosaicFileRaster = null; try { string mosaicFilename = CreateMosaicFilename(inArg, dataIdentify, dateTime, projectionIdentify, fileRaster.ResolutionX, station, dayOrNight); mosaicFilename = Path.Combine(mosaicInputArg.OutputDir, mosaicFilename); Mosaic mosaic = new Mosaic(inArg, fileRaster, new Action <int, string>(OnProgress)); mosaicFileRaster = mosaic.MosaicToFile(mosaicFilename); OutFileArg fileArg = new OutFileArg(); if (mosaicFileRaster != null) { OnProgress(0, "生成缩略图"); string overViewFilename = OverViewHelper.OverView(mosaicFileRaster, 1024); OnProgress(100, "完成缩略图"); fileArg.Envelope = mosaicInputArg.Envelope; fileArg.ResolutionX = mosaicFileRaster.ResolutionX.ToString(); fileArg.ResolutionY = mosaicFileRaster.ResolutionY.ToString(); fileArg.OutputFilename = Path.GetFileName(mosaicFileRaster.fileName); fileArg.Thumbnail = (string.IsNullOrWhiteSpace(overViewFilename) ? "" : Path.GetFileName(overViewFilename)); fileArg.ExtendFiles = Path.ChangeExtension(Path.GetFileName(mosaicFileRaster.fileName), "hdr"); fileArg.Length = new FileInfo(mosaicFileRaster.fileName).Length; } outArg.OutputFiles = new OutFileArg[] { fileArg }; outArg.LogLevel = "info"; outArg.LogInfo = "拼接完成"; } catch (Exception ex) { outArg.LogLevel = "error"; outArg.LogInfo = ex.Message; } finally { if (mosaicFileRaster != null) { mosaicFileRaster.Dispose(); } string outXmlFilename = Path.Combine(inArg.MosaicInputArg.OutputDir, Path.GetFileName(inArg.InputFilename) + ".xml"); MosaicOutputArg.WriteXml(outArg, outXmlFilename); } }