Exemplo n.º 1
0
        private static object[] WriteFiles(OutputArg arg)
        {
            if (arg == null || arg.OutputFiles == null || arg.OutputFiles.Length == 0)
            {
                return(null);
            }
            List <XElement> files = new List <XElement>();

            for (int i = 0; i < arg.OutputFiles.Length; i++)
            {
                OutFileArg file = arg.OutputFiles[i];
                files.Add(new XElement("File",
                                       new XElement("OutputFilename", file.OutputFilename),
                                       new XElement("Thumbnail", file.Thumbnail),
                                       new XElement("ExtendFiles", file.ExtendFiles),
                                       new XElement("Envelope",
                                                    new XAttribute("name", file.Envelope.Name),
                                                    new XAttribute("minx", file.Envelope.PrjEnvelope.MinX),
                                                    new XAttribute("maxx", file.Envelope.PrjEnvelope.MaxX),
                                                    new XAttribute("miny", file.Envelope.PrjEnvelope.MinY),
                                                    new XAttribute("maxy", file.Envelope.PrjEnvelope.MaxY)),
                                       new XElement("ResolutionX", file.ResolutionX),
                                       new XElement("ResolutionY", file.ResolutionY),
                                       new XElement("Length", file.Length)));
            }
            return(files.ToArray());
        }
Exemplo n.º 2
0
        public static void WriteXml(OutputArg arg, string argXml)
        {
            XElement xml = new XElement("xml",
                                        new XElement("OrbitFilename", arg.OrbitFilename),
                                        new XElement("Satellite", arg.Satellite),
                                        new XElement("Sensor", arg.Sensor),
                                        new XElement("Level", arg.Level),
                                        new XElement("ProjectionIdentify", arg.ProjectionIdentify),
                                        new XElement("ObservationDate", arg.ObservationDate),
                                        new XElement("ObservationTime", arg.ObservationTime),
                                        new XElement("Station", arg.Station),
                                        new XElement("DayOrNight", arg.DayOrNight),
                                        new XElement("Length", arg.Length),
                                        new XElement("OrbitIdentify", arg.OrbitIdentify),
                                        new XElement("OutputFiles",
                                                     WriteFiles(arg)),
                                        new XElement("log",
                                                     new XElement("loglevel", arg.LogLevel),
                                                     new XElement("loginfo", arg.LogInfo)));

            xml.Save(argXml);
        }
Exemplo n.º 3
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);
            }
        }