Esempio n. 1
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();
                }
            }
        }