Ejemplo n.º 1
0
 private XElement MosaicArgToXmlValue(MosaicInputArg mosaicInputArg)
 {
     if (mosaicInputArg == null)
     {
         return(null);
     }
     return(new XElement("Mosaic",
                         new XElement("OutputDir", mosaicInputArg.OutputDir),
                         EnvelopeToXmlValue(mosaicInputArg.Envelope)));
 }
Ejemplo n.º 2
0
        private static MosaicInputArg ParseMosaic(XElement mosaic)
        {
            if (mosaic == null)
            {
                return(null);
            }
            string          outputdir = mosaic.Element("OutputDir").Value;
            PrjEnvelopeItem env       = ParseEnvelope(mosaic.Element("Envelope"));
            MosaicInputArg  mosaicArg = new MosaicInputArg();

            mosaicArg.OutputDir = outputdir;
            mosaicArg.Envelope  = env;
            return(mosaicArg);
        }
Ejemplo n.º 3
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.º 4
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);
            }
        }