Ejemplo 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++)
            {
                FileArg 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());
        }
Ejemplo 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("OutputFiles",
                                                     WriteFiles(arg)),
                                        new XElement("log",
                                                     new XElement("loglevel", arg.LogLevel),
                                                     new XElement("loginfo", arg.LogInfo)));

            xml.Save(argXml);
        }
Ejemplo n.º 3
0
        public void Do(string xmlArg)
        {
            BlockArg inArg = BlockArg.ParseXml(xmlArg);

            string outDir = inArg.OutputDir;
            IRasterDataProvider inRaster = null;
            OutputArg           outArg   = new OutputArg();

            try
            {
                CheckArg(inArg);
                BlockDef[] blocks = GenericBlock(inArg);
                inRaster = GeoDataDriver.Open(inArg.InputFilename) as IRasterDataProvider;
                DataIdentify dataIdentify = inRaster.DataIdentify;
                outArg.OrbitFilename      = Path.GetFileName(inArg.InputFilename);
                outArg.Satellite          = dataIdentify.Satellite;
                outArg.Sensor             = dataIdentify.Sensor;
                outArg.Level              = "L1";
                outArg.ProjectionIdentify = ParseProjectionIdentify(Path.GetFileName(inArg.InputFilename));
                outArg.ObservationDate    = dataIdentify.OrbitDateTime.ToString("yyyyMMdd");
                outArg.ObservationTime    = dataIdentify.OrbitDateTime.ToString("HHmm");
                outArg.Station            = ParseStation(Path.GetFileName(inArg.InputFilename));
                List <FileArg> fileArgs   = new List <FileArg>();
                string         retMessage = "";
                for (int blockIndex = 0; blockIndex < blocks.Length; blockIndex++)
                {
                    BlockDef blockDef = blocks[blockIndex];
                    if (blocks == null)
                    {
                        continue;
                    }
                    CoordEnvelope       oEnvelope       = inRaster.CoordEnvelope;
                    CoordEnvelope       tEnvelope       = blockDef.ToEnvelope();
                    IRasterDataProvider outBlockRasters = null;
                    try
                    {
                        if (!IsInteractived(oEnvelope, tEnvelope))
                        {
                            continue;
                        }
                        double validPercent = 0;
                        outBlockRasters = _rasterClipProcess.Clip(inRaster, blockDef, 100, "LDF", outDir, new Action <int, string>(OnProgress), out validPercent);
                        if (outBlockRasters == null)
                        {
                            continue;
                        }
                        if (validPercent == 0)
                        {
                            string filename = outBlockRasters.fileName;
                            outBlockRasters.Dispose();
                            outBlockRasters = null;
                            TryDeleteLdfFiles(filename);
                            continue;
                        }
                        IRasterDataProvider outfileRaster = outBlockRasters;
                        string        overViewFilename    = OverViewHelper.OverView(outfileRaster, _blockPngSize);
                        FileArg       fileArg             = new FileArg();
                        CoordEnvelope env = null;
                        float         resolutionX;
                        float         resolutionY;
                        env                    = outfileRaster.CoordEnvelope;
                        resolutionX            = outfileRaster.ResolutionX;
                        resolutionY            = outfileRaster.ResolutionY;
                        fileArg.OutputFilename = Path.GetFileName(outfileRaster.fileName);
                        fileArg.Thumbnail      = (string.IsNullOrWhiteSpace(overViewFilename) ? "" : Path.GetFileName(overViewFilename));
                        fileArg.ExtendFiles    = Path.ChangeExtension(Path.GetFileName(outfileRaster.fileName), "hdr");
                        fileArg.Envelope       = new PrjEnvelopeItem(blockDef.Name, 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(outfileRaster.fileName).Length;
                        fileArgs.Add(fileArg);
                    }
                    catch (Exception ex)
                    {
                        retMessage += (ex.Message + " Block:" + blockDef.Name + tEnvelope == null ? "" : tEnvelope.ToString());
                    }
                    finally
                    {
                        if (outBlockRasters != null)
                        {
                            if (outBlockRasters != null)
                            {
                                outBlockRasters.Dispose();
                            }
                        }
                    }
                }
                outArg.OutputFiles = fileArgs.ToArray();
                outArg.LogLevel    = "info";
                if (string.IsNullOrWhiteSpace(retMessage))
                {
                    outArg.LogInfo = "分幅成功";
                }
                else
                {
                    outArg.LogInfo = retMessage;
                }
            }
            catch (Exception ex)
            {
                LogFactory.WriteLine(ex);
                outArg.LogLevel = "error";
                outArg.LogInfo  = ex.Message;
                Console.WriteLine(ex.Message);
            }
            finally
            {
                string outXmlFilename = Path.Combine(inArg.OutputDir, Path.GetFileName(inArg.InputFilename) + ".xml");
                OutputArg.WriteXml(outArg, outXmlFilename);
                if (inRaster != null)
                {
                    inRaster.Dispose();
                }
            }
        }