Ejemplo n.º 1
0
 private void CheckAtg(InputArg inArg)
 {
     if (string.IsNullOrWhiteSpace(inArg.InputFilename))
     {
         throw new Exception("参数InputFilename为空值");
     }
     if (!File.Exists(inArg.InputFilename))
     {
         throw new Exception("参数InputFilename提供的文件不存在或者不可访问[" + inArg.InputFilename + "]");
     }
 }
Ejemplo n.º 2
0
        private IRasterDataProvider CreateMosaicFile(string mosaicFilename, InputArg inArg)
        {
            ISpatialReference spatialRef = fileRaster.SpatialRef;
            PrjEnvelope       env        = inArg.MosaicInputArg.Envelope.PrjEnvelope;
            string            bandNames  = BandNameString(fileRaster as ILdfDataProvider);
            Size outSize = env.GetSize(fileRaster.ResolutionX, fileRaster.ResolutionY);

            string[] options = new string[] {
                "INTERLEAVE=BSQ",
                "VERSION=LDF",
                "WITHHDR=TRUE",
                "SPATIALREF=" + spatialRef.ToProj4String(),
                "MAPINFO={" + 1 + "," + 1 + "}:{" + env.MinX + "," + env.MaxY + "}:{" + fileRaster.ResolutionX + "," + fileRaster.ResolutionY + "}",
                "BANDNAMES=" + bandNames
            };
            return(CreateOutFile(mosaicFilename, fileRaster.BandCount, outSize, enumDataType.UInt16, options));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// FY3A_MERSI_GBAL_L1_20120808_0000_1000M_MS.HDF->
        /// FY3A_MERSI_GBAL_GLL_L1_20120808_0000_1000M_MS_D.ldf
        /// </summary>
        /// <param name="inArg"></param>
        /// <param name="dataIdentify"></param>
        /// <returns></returns>
        private string CreateMosaicFilename(InputArg inArg, DataIdentify dataIdentify, string projectionIdentify, float resolution, string station, string dayOrNight)
        {
            PrjEnvelopeItem item = inArg.MosaicInputArg.Envelope;

            return(string.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}.ldf",
                                 dataIdentify.Satellite,
                                 dataIdentify.Sensor,
                                 item.Name,
                                 projectionIdentify,
                                 "L1",
                                 dataIdentify.OrbitDateTime.ToString("yyyyMMdd"),
                                 string.IsNullOrWhiteSpace(inArg.OrbitIdentify) ? "0000" : inArg.OrbitIdentify,
                                 projectionIdentify == "GLL" ? GLLResolutionIdentify(resolution) : ResolutionIdentify(resolution),
                                 station,
                                 dayOrNight
                                 ));
        }
Ejemplo n.º 4
0
        public InputArg Copy()
        {
            InputArg arg = new InputArg();

            arg.InputFilename        = InputFilename;
            arg.ValidEnvelopes       = ValidEnvelopes;
            arg.Bands                = Bands;
            arg.OutputDir            = OutputDir;
            arg.ResolutionX          = ResolutionX;
            arg.ResolutionY          = ResolutionY;
            arg.Envelopes            = Envelopes;
            arg.ProjectionIdentify   = ProjectionIdentify;
            arg.IsOnlySaveMosaicFile = IsOnlySaveMosaicFile;
            arg.MosaicInputArg       = MosaicInputArg;
            arg.DayNight             = DayNight;
            arg.ExtArgs              = ExtArgs;
            return(arg);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            try
            {
                //ImportBlock s = new ImportBlock();
                //s.GetFeatures();

                string   xmlFile = args[0];
                InputArg arg     = InputArg.ParseXml(xmlFile);
                Console.WriteLine(arg.InputFilename);
                new Execute().Do(arg);

                //GenericFilename g = new GenericFilename();
                //string prjFilename = g.GenericPrjFilename("D:\\FY3A_MERSI_GBAL_L1_20120808_0000_1000M_MS.HDF", "GLL");
                //Console.WriteLine(prjFilename);
                //Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 6
0
        public static InputArg ParseXml(string argXml)
        {
            if (string.IsNullOrWhiteSpace(argXml))
            {
                throw new ArgumentNullException("argXml", "参数文件为空");
            }
            if (!File.Exists(argXml))
            {
                throw new FileNotFoundException("参数文件不存在" + argXml, argXml);
            }
            try
            {
                string            inputfilename;
                string            outputDir;
                PrjEnvelopeItem[] validEnvelopes     = null;
                string            projectionIdentify = null;
                string            bands       = null;
                string            resolutionX = "";
                string            resolutionY = "";
                PrjEnvelopeItem[] envelopes;
                MosaicInputArg    mosaicInputArg = null;
                string            dayNight       = "";

                XElement xml            = XElement.Load(argXml);
                XElement inputfilenameX = xml.Element("InputFilename");
                inputfilename = inputfilenameX.Value;
                XElement outputDirX = xml.Element("OutputDir");
                outputDir = outputDirX.Value;
                if (!Directory.Exists(outputDir))
                {
                    Directory.CreateDirectory(outputDir);
                }
                validEnvelopes = ParseEnvelopes(xml.Element("ValidEnvelopes"));
                XElement projectionIdentifyX = xml.Element("ProjectionIdentify");
                if (projectionIdentifyX != null)
                {
                    projectionIdentify = projectionIdentifyX.Value;
                }
                XElement bandsX = xml.Element("Bands");
                if (bandsX != null)
                {
                    bands = bandsX.Value;
                }
                XElement resolutionXX = xml.Element("ResolutionX");
                if (resolutionXX != null)
                {
                    resolutionX = resolutionXX.Value;
                }
                XElement resolutionYX = xml.Element("ResolutionY");
                if (resolutionYX != null)
                {
                    resolutionY = resolutionYX.Value;
                }
                envelopes      = ParseEnvelopes(xml.Element("Envelopes"));
                mosaicInputArg = ParseMosaic(xml.Element("Mosaic"));
                bool     isOnlySaveMosaicFile = (GetElementValue(xml, "IsOnlySaveMosaicFile") == "true");
                XElement dayNightX            = xml.Element("DayNight");
                if (dayNightX != null && !dayNightX.IsEmpty)
                {
                    dayNight = dayNightX.Value;
                }
                string[] extArgs  = null;
                XElement extArgsX = xml.Element("ExtArgs");
                if (extArgsX != null && !extArgsX.IsEmpty)
                {
                    extArgs = ParseExtArgs(extArgsX.Value);
                }

                InputArg arg = new InputArg();
                arg.InputFilename      = inputfilename;
                arg.OutputDir          = outputDir;
                arg.ValidEnvelopes     = validEnvelopes;
                arg.ProjectionIdentify = string.IsNullOrWhiteSpace(projectionIdentify) ? "GLL" : projectionIdentify;
                arg.Bands = ParseBands(bands);
                if (!string.IsNullOrWhiteSpace(resolutionX))
                {
                    arg.ResolutionX = float.Parse(resolutionX);
                }
                if (!string.IsNullOrWhiteSpace(resolutionY))
                {
                    arg.ResolutionY = float.Parse(resolutionY);
                }
                arg.PervObservationDate  = GetElementValue(xml, "PervObservationDate");
                arg.PervObservationTime  = GetElementValue(xml, "PervObservationTime");
                arg.OrbitIdentify        = GetElementValue(xml, "OrbitIdentify");
                arg.Envelopes            = envelopes;
                arg.MosaicInputArg       = mosaicInputArg;
                arg.IsOnlySaveMosaicFile = isOnlySaveMosaicFile;
                if (!string.IsNullOrWhiteSpace(dayNight))
                {
                    arg.DayNight = dayNight;
                }
                if (extArgs != null)
                {
                    arg.ExtArgs = extArgs;
                }
                return(arg);
            }
            catch (Exception ex)
            {
                throw new Exception("解析投影输入参数文件失败" + ex.Message, ex);
            }
        }
Ejemplo n.º 7
0
 public Mosaic(InputArg inArg, RSS.Core.DF.IRasterDataProvider infileRaster, Action <int, string> action)
 {
     this.inArg      = inArg;
     this.fileRaster = infileRaster;
     this.action     = action;
 }
Ejemplo n.º 8
0
        public void Do(InputArg inArg)
        {
            CheckAtg(inArg);
            string    projectionIdentify = inArg.ProjectionIdentify;
            OutputArg outArg             = new OutputArg();

            try
            {
                using (IRasterDataProvider inputRaster = GeoDataDriver.Open(inArg.InputFilename) as IRasterDataProvider)
                {
                    DataIdentify dataIdentify = inputRaster.DataIdentify;
                    outArg.OrbitFilename      = Path.GetFileName(inArg.InputFilename);
                    outArg.Satellite          = dataIdentify.Satellite;
                    outArg.Sensor             = dataIdentify.Sensor;
                    outArg.Level              = "L1";
                    outArg.ProjectionIdentify = projectionIdentify;
                    outArg.ObservationDate    = dataIdentify.OrbitDateTime.ToString("yyyyMMdd");
                    outArg.ObservationTime    = dataIdentify.OrbitDateTime.ToString("HHmm");
                    outArg.Station            = ParseStation(Path.GetFileName(inArg.InputFilename));
                    outArg.DayOrNight         = DayOrNight(inputRaster);
                    outArg.OrbitIdentify      = CalcOrbitIdentify(dataIdentify.OrbitDateTime, inArg.PervObservationDate, inArg.PervObservationTime, inArg.OrbitIdentify);
                    outArg.Length             = new FileInfo(inArg.InputFilename).Length;
                    string validEnvelopeMsg = "";
                    if (!string.IsNullOrWhiteSpace(inArg.DayNight))
                    {
                        if (inArg.DayNight != "daynight" && outArg.DayOrNight == "X")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "未设定处理白天和晚上数据,白天晚上标记未知:X";
                        }
                        else if (inArg.DayNight == "day" && outArg.DayOrNight != "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理白天数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "night" && outArg.DayOrNight != "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为只处理晚上数据,当前数据标记为白天";
                        }
                        else if (inArg.DayNight == "notnight" && outArg.DayOrNight == "N")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理晚上数据,当前数据标记为晚上";
                        }
                        else if (inArg.DayNight == "notday" && outArg.DayOrNight == "D")
                        {
                            outArg.LogLevel = "info";
                            outArg.LogInfo  = "设定为不处理白天数据,当前数据标记为白天";
                        }
                    }
                    if (inArg.ValidEnvelopes == null || inArg.ValidEnvelopes.Length == 0)
                    {
                        outArg.LogLevel = "error";
                        outArg.LogInfo  = "参数错误:未正确设置ValidEnvelopes";
                    }
                    else if (!ValidEnvelope(inputRaster, inArg.ValidEnvelopes, out validEnvelopeMsg))
                    {
                        outArg.LogLevel = "info";
                        outArg.LogInfo  = validEnvelopeMsg;
                    }
                    else
                    {
                        GenericFilename genFilenmae = new GenericFilename();
                        PrjOutArg       prjArg;
                        if (inArg.Envelopes == null || inArg.Envelopes.Length == 0)
                        {
                            prjArg = new PrjOutArg(projectionIdentify, null, inArg.ResolutionX, inArg.ResolutionY, inArg.OutputDir);
                        }
                        else
                        {
                            prjArg = new PrjOutArg(projectionIdentify, inArg.Envelopes, inArg.ResolutionX, inArg.ResolutionY, inArg.OutputDir);
                        }
                        //prjArg.Args = new string[] { "SolarZenith"};
                        if (inArg.Bands != null && inArg.Bands.Length != 0)
                        {
                            prjArg.SelectedBands = inArg.Bands;
                            Console.WriteLine("SelectedBands:" + string.Join(",", prjArg.SelectedBands));
                        }
                        //扩展参数
                        List <string> extArgs = new List <string>();
                        extArgs.Add("IsClearPrjCache");
                        if (inArg.ExtArgs != null)
                        {
                            extArgs.AddRange(inArg.ExtArgs);
                        }
                        prjArg.Args = extArgs.ToArray();
                        ProjectionFactory prjFactory = new ProjectionFactory();
                        string            retMessage = "";
                        string[]          files      = prjFactory.Project(inputRaster, prjArg, new Action <int, string>(OnProgress), out retMessage);
                        prjFactory = null;
                        //投影结束,执行拼接,如果有拼接节点
                        List <OutFileArg> fileArgs = new List <OutFileArg>();
                        for (int i = 0; i < files.Length; i++)
                        {
                            string file = files[i];
                            if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
                            {
                                continue;
                            }
                            OutFileArg    fileArg = new OutFileArg();
                            CoordEnvelope env     = null;
                            float         resolutionX;
                            float         resolutionY;
                            string        overViewFilename = "";
                            using (IRasterDataProvider outfileRaster = GeoDataDriver.Open(file) as IRasterDataProvider)
                            {
                                overViewFilename = OverViewHelper.OverView(outfileRaster, _prjPngSize);
                                env         = outfileRaster.CoordEnvelope;
                                resolutionX = outfileRaster.ResolutionX;
                                resolutionY = outfileRaster.ResolutionY;
                                TryMosaicFile(inArg, outfileRaster, dataIdentify, outArg.DayOrNight);
                            }
                            fileArg.OutputFilename = Path.GetFileName(file);
                            fileArg.Thumbnail      = (string.IsNullOrWhiteSpace(overViewFilename) && File.Exists(overViewFilename) ? "" : Path.GetFileName(overViewFilename));
                            string solarZenithFile    = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".SolarZenith.ldf");
                            string solarZenithHdrFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".SolarZenith.hdr");
                            fileArg.ExtendFiles = Path.ChangeExtension(Path.GetFileName(file), "hdr") +
                                                  (string.IsNullOrWhiteSpace(solarZenithFile) && File.Exists(solarZenithFile) ? "" : "," + Path.GetFileName(solarZenithFile)) +
                                                  (string.IsNullOrWhiteSpace(solarZenithHdrFile) && File.Exists(solarZenithHdrFile) ? "" : "," + Path.GetFileName(solarZenithHdrFile));
                            fileArg.Envelope    = new PrjEnvelopeItem("GBAL", env == null ? null : new RasterProject.PrjEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY));
                            fileArg.ResolutionX = resolutionX.ToString();
                            fileArg.ResolutionY = resolutionY.ToString();
                            fileArg.Length      = new FileInfo(file).Length;
                            fileArgs.Add(fileArg);
                            if (inArg.IsOnlySaveMosaicFile)
                            {
                                TryDeleteFile(file);
                            }
                        }
                        outArg.OutputFiles = fileArgs.ToArray();
                        outArg.LogLevel    = "info";
                        if (string.IsNullOrWhiteSpace(retMessage))
                        {
                            outArg.LogInfo = "投影成功";
                        }
                        else
                        {
                            outArg.LogInfo = retMessage;
                        }
                        if (string.IsNullOrWhiteSpace(validEnvelopeMsg))
                        {
                            outArg.LogInfo = outArg.LogInfo + validEnvelopeMsg;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                outArg.LogLevel = "error";
                outArg.LogInfo  = ex.Message;
                LogFactory.WriteLine(ex);
            }
            finally
            {
                string outXmlFilename = Path.Combine(inArg.OutputDir, Path.GetFileName(inArg.InputFilename) + ".xml");
                OutputArg.WriteXml(outArg, outXmlFilename);
            }
        }
Ejemplo n.º 9
0
        private void TryMosaicFile(InputArg inArg, IRasterDataProvider fileRaster, DataIdentify dataIdentify, 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.Satellite;
            outArg.Sensor             = dataIdentify.Sensor;
            outArg.Level              = "L1";
            outArg.ProjectionIdentify = projectionIdentify;
            outArg.ObservationDate    = dataIdentify.OrbitDateTime.ToString("yyyyMMdd");
            outArg.Station            = station;
            outArg.DayOrNight         = dayOrNight;
            IRasterDataProvider mosaicFileRaster = null;

            try
            {
                string mosaicFilename = CreateMosaicFilename(inArg, dataIdentify, 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);
            }
        }
Ejemplo n.º 10
0
 private string CalcOrbitIdentify(InputArg inArg)
 {
     throw new NotImplementedException();
 }