Esempio 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 + "]");
     }
 }
Esempio n. 2
0
        private AbstractWarpDataset CreateMosaicFile(string mosaicFilename, InputArg inArg)
        {
            SpatialReference 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.ExportToProj4(),
                "MAPINFO={" + 1 + "," + 1 + "}:{" + env.MinX + "," + env.MaxY + "}:{" + fileRaster.ResolutionX + "," + fileRaster.ResolutionY + "}",
                //"BANDNAMES="+ bandNames
            };
            return(CreateOutFile(mosaicFilename, fileRaster.BandCount, outSize, DataType.GDT_UInt16, env, spatialRef, options));
        }
Esempio n. 3
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);
        }
Esempio n. 4
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, RasterDatasetInfo dataIdentify, DateTime dateTime,
                                            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.SatelliteID,
                                 dataIdentify.SensorID,
                                 item.Name,
                                 projectionIdentify,
                                 "L1",
                                 dateTime.ToString("yyyyMMdd"),
                                 string.IsNullOrWhiteSpace(inArg.OrbitIdentify) ? "0000" : inArg.OrbitIdentify,
                                 projectionIdentify == "GLL"
                    ? PrjFileName.GLLResolutionIdentify(resolution)
                    : PrjFileName.ResolutionIdentify(resolution),
                                 station,
                                 dayOrNight
                                 ));
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Ogr.RegisterAll();
            SpatialReference s = new SpatialReference("");

            s.ImportFromEPSG(4326);
            Proj4Projection p = new Proj4Projection(s.ExportToProj4());

            //UInt16[] buffer = new ushort[100*100];
            //string hdfPath = @"E:\RSDATA\FY4A_0724\FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20180724000000_20180724001459_0500M_V0001.HDF";
            //hdfPath = @"R:\FY4A\AGRI\L1\FDI\DISK\2018\20180804\FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20180804010000_20180804011459_0500M_V0001.HDF";
            //var ds = DatasetFactory.OpenDataset(hdfPath, OpenMode.ReadOnly);
            //IMultiDataset mDs = ds as IMultiDataset;
            //var rds =  mDs.GetDataset("NOMChannel02") as IRasterDataset;
            //Console.WriteLine($"Width: {rds.GetRasterXSize()} Height: {rds.GetRasterYSize()}");
            //var band = rds.GetRasterBand(0);

            //bool ok = band.Read(10000, 10000, 100, 100, buffer, 100, 100, PixelDataType.UInt16);
            //Console.WriteLine($"读取{ok}");

            try
            {
                //ImportBlock s = new ImportBlock();
                //s.GetFeatures();
                //string xmlFile = "投影输入";
                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);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("ProjectTool.Main()", ex);
            }
        }
Esempio n. 6
0
 public Mosaic(InputArg inArg, AbstractWarpDataset infileRaster, Action <int, string> action)
 {
     this.inArg      = inArg;
     this.fileRaster = infileRaster;
     this.action     = action;
 }
Esempio n. 7
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);
            }
        }
Esempio n. 8
0
        private void TryMosaicFile(InputArg inArg, AbstractWarpDataset fileRaster, RasterDatasetInfo dataIdentify,
                                   DateTime dateTime, 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.SatelliteID;
            outArg.Sensor             = dataIdentify.SensorID;
            outArg.Level              = "L1";
            outArg.ProjectionIdentify = projectionIdentify;
            outArg.ObservationDate    = dateTime.ToString("yyyyMMdd");
            outArg.Station            = station;
            outArg.DayOrNight         = dayOrNight;
            AbstractWarpDataset mosaicFileRaster = null;

            try
            {
                string mosaicFilename = CreateMosaicFilename(inArg, dataIdentify, dateTime, 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);
            }
        }
Esempio n. 9
0
 private string CalcOrbitIdentify(InputArg inArg)
 {
     throw new NotImplementedException();
 }
Esempio n. 10
0
        public void Do(InputArg inArg)
        {
            CheckAtg(inArg);
            string    projectionIdentify = inArg.ProjectionIdentify;
            OutputArg outArg             = new OutputArg();

            try
            {
                using (AbstractWarpDataset inputRaster = WarpDataset.Open(inArg.InputFilename))
                {
                    RasterDatasetInfo dsInfo =
                        mRasterSourceManager.GetInstance().GetRasterDatasetInfo(inArg.InputFilename);
                    DateTime?    dateTime     = mRasterSourceManager.GetInstance().GetImageTime(inArg.InputFilename);
                    DataIdentify dataIdentify = new DataIdentify();
                    outArg.OrbitFilename      = Path.GetFileName(inArg.InputFilename);
                    outArg.Satellite          = dsInfo.SatelliteID;
                    outArg.Sensor             = dsInfo.SensorID;
                    outArg.Level              = "L1";
                    outArg.ProjectionIdentify = projectionIdentify;
                    outArg.ObservationDate    = dateTime.HasValue ? dateTime.Value.ToString("yyyyMMdd") : "";
                    outArg.ObservationTime    = dateTime.HasValue ? dateTime.Value.ToString("HHmm") : "";
                    outArg.Station            = ParseStation(Path.GetFileName(inArg.InputFilename));
                    outArg.DayOrNight         = DayOrNight(inputRaster);
                    if (dateTime.HasValue)
                    {
                        outArg.OrbitIdentify = CalcOrbitIdentify(dateTime.Value, inArg.PervObservationDate,
                                                                 inArg.PervObservationTime, inArg.OrbitIdentify);
                    }
                    outArg.Length = new FileInfo(inArg.InputFilename).Length;
                    string validEnvelopeMsg = "";

                    #region 日夜检查

                    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  = "设定为不处理白天数据,当前数据标记为白天";
                        }
                    }

                    #endregion 日夜检查

                    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
                    {
                        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();
                            Envelope   env     = null;
                            float      resolutionX;
                            float      resolutionY;
                            string     overViewFilename = "";
                            using (AbstractWarpDataset outfileRaster = WarpDataset.Open(file))
                            {
                                Console.WriteLine("生成缩略图开始");
                                overViewFilename = OverViewHelper.OverView(outfileRaster, _prjPngSize);
                                Console.WriteLine("生成缩略图结束");
                                env         = outfileRaster.GetEnvelope();
                                resolutionX = outfileRaster.ResolutionX;
                                resolutionY = outfileRaster.ResolutionY;
                                var dt = dateTime.HasValue ? dateTime.Value : DateTime.Now;
                                TryMosaicFile(inArg, outfileRaster, dsInfo, dt, 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,
                                                                    SpatialReferenceFactory.CreateSpatialReference(4326)));
                            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";
                Console.WriteLine(ex.StackTrace);
                outArg.LogInfo = ex.Message + ex.StackTrace;
                Console.WriteLine("PIE.Meteo.ProjectTool.Execute()", ex);
            }
            finally
            {
                //输出参数文件重新命名
                string inputFileName = Path.GetFileName(inArg.InputFilename);

                System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"_\d{4}M");
                if (rex.IsMatch(inputFileName))
                {
                    string oldResStr = rex.Match(inputFileName).Groups[0].Value;
                    if (inArg.ProjectionIdentify == "GLL")
                    {
                        inputFileName = inputFileName.Replace(oldResStr,
                                                              $"_{PrjFileName.GLLResolutionIdentify(inArg.ResolutionX)}");
                    }
                    else
                    {
                        inputFileName = inputFileName.Replace(oldResStr,
                                                              $"_{PrjFileName.ResolutionIdentify(inArg.ResolutionX)}");
                    }
                }

                string outXmlFilename = Path.Combine(inArg.OutputDir, inputFileName + ".xml");
                OutputArg.WriteXml(outArg, outXmlFilename);
            }
        }