Beispiel #1
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
                                 ));
        }
        public override string GetFileType(AbstractWarpDataset file)
        {
            try
            {
                if (file == null)
                {
                    throw new Exception("文件为空");
                }
                RasterDatasetInfo info = mRasterSourceManager.GetInstance().GetRasterDatasetInfo(file.fileName);

                if (file.isMultiDs)
                {
                    if (info.SensorID == "VIRR")       //dataIdentify.Satellite == "FY3B"||"FY3A"
                    {
                        if (info.SatelliteID == "FY3C")
                        {
                            return("FY3C_VIRR_L1");
                        }
                        else
                        {
                            return("VIRR_L1");
                        }
                    }
                    else if (info.SensorID == "MERSI")
                    {
                        if (info.SatelliteID == "FY3C")
                        {
                            if (file.fileName.Contains("1000M"))
                            {
                                return("FY3C_MERSI_1KM_L1");
                            }
                            else if (file.fileName.Contains("0250M"))
                            {
                                return("FY3C_MERSI_QKM_L1");
                            }
                        }
                        else if (info.SatelliteID == "FY3D")
                        {
                            if (file.fileName.Contains("1000M"))
                            {
                                return("FY3D_MERSI_1KM_L1");
                            }
                            else if (file.fileName.Contains("0250M"))
                            {
                                return("FY3D_MERSI_QKM_L1");
                            }
                        }
                        else
                        {
                            if (file.fileName.Contains("1000M"))
                            {
                                return("MERSI_1KM_L1");
                            }
                            else if (file.fileName.Contains("0250M"))
                            {
                                return("MERSI_QKM_L1");
                            }
                        }
                    }
                    else if (modisSensor.Contains(info.SensorID) || modisSatellite.Contains(info.SatelliteID)) //info.SatelliteID == "EOST"||"EOST"//TERRA
                    {
                        if (file.fileName.Contains("MOD021KM") || file.fileName.Contains("MYD021KM"))          //MOD/MYD021KM)、MOD/MYD03GEO、
                        {
                            return("MODIS_1KM_L1");
                        }
                        else if (file.fileName.Contains("MOD02HKM") || file.fileName.Contains("MYD02HKM"))
                        {
                            return("MODIS_HKM_L1");
                        }
                        else if (file.fileName.Contains("MOD02QKM") || file.fileName.Contains("MYD02QKM"))
                        {
                            return("MODIS_QKM_L1");
                        }
                    }
                    else if ((info.SatelliteID == "FY1D" || info.SatelliteID == "FY1C") && info.SensorID == "AVHRR")
                    {
                        return("FY1X_1A5");
                    }
                    else if (info.SensorID == "AVHRR") //info.SatelliteID == "NOAA-18" &&
                    {
                        return("NOAA_1BD");
                    }
                    else if (info.SatelliteID == "NOAA" && info.SensorID == "AVHRR")
                    {
                        return("NOAA_1A5_L1");
                    }
                    else if (info.SensorID == "VISSR" || fy2Satellite.Contains(info.SatelliteID))
                    {
                        return("FY2NOM");
                    }
                    else if (info.SensorID == "AGRI" && info.SatelliteID == "FY4A")
                    {
                        switch (info.BandCol.FirstOrDefault().resolution)
                        {
                        case "500":
                            return("FY4A_AGRI_0500");

                        case "1000":
                            return("FY4A_AGRI_1000");

                        case "2000":
                            return("FY4A_AGRI_2000");

                        case "4000":
                            return("FY4A_AGRI_4000");
                        }
                    }
                    else if (info.SensorID == "VIIRS" && info.SatelliteID == "NPP")
                    {
                        return("NPP");
                    }
                }
                else if (info.SatelliteID == "H8")
                {
                    return("H8");
                }
                else if (info.SatelliteID == "NOAA")
                {
                    return("NOAA");
                }
                else if (file.SpatialRef != null)
                {
                    return("PROJECTED");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"FileChecker.GetFileType() {file.fileName}");
                throw new Exception($"未获得是轨道数据或者是已投影数据标识,无法确定正确的数据来源. {Path.GetFileName(file.fileName)}", ex.InnerException);
            }

            Console.WriteLine($"FileChecker.GetFileType() {file.fileName}");
            throw new Exception($"未获得是轨道数据或者是已投影数据标识,无法确定正确的数据来源. {Path.GetFileName(file.fileName)}");
        }
Beispiel #3
0
        /// <summary>
        /// 设置_rasterProjector与_srcGeoTrans
        /// </summary>
        /// <param name="srcRaster"></param>
        private void InitLocationArgs(AbstractWarpDataset srcRaster)
        {
            RasterDatasetInfo info       = mRasterSourceManager.GetInstance().GetRasterDatasetInfo(srcRaster.fileName);
            string            resolution = info.BandCol.FirstOrDefault().resolution;
            double            nReslution = 0;

            if (!double.TryParse(resolution, out nReslution))
            {
                throw new Exception("获取FY4A影像分辨率失败");
            }

            int    beginLineNum    = 0;
            var    attrsDic        = srcRaster.GetAttributes();
            string beginlineNumStr = string.Empty;

            if (attrsDic.ContainsKey("Begin Line Number"))
            {
                beginlineNumStr = attrsDic["Begin Line Number"];
            }
            if (string.IsNullOrEmpty(beginlineNumStr))
            {
                if (attrsDic.ContainsKey("geospatial lat lon extent begin line number"))
                {
                    beginlineNumStr = attrsDic["geospatial lat lon extent begin line number"];
                }
                if (string.IsNullOrEmpty(beginlineNumStr))
                {
                    beginLineNum = 183;
                }
            }

            if (!string.IsNullOrEmpty(beginlineNumStr))
            {
                StringBuilder sb = new StringBuilder();
                foreach (char c in beginlineNumStr)
                {
                    if ((c >= '0' && c <= '9') || c == ' ' || c == '-')
                    {
                        sb.Append(c);
                    }
                }

                bool result = int.TryParse(sb.ToString(), out beginLineNum);
            }

            double[] geoTransform = new double[6];
            geoTransform[0] = -5496000;
            geoTransform[1] = nReslution;
            geoTransform[2] = 0;
            geoTransform[3] = 5496000 - beginLineNum * nReslution;
            geoTransform[4] = 0;
            geoTransform[5] = -nReslution;

            //"+proj=geos +h=35785863 +a=6378137.0 +b=6356752.3 +lon_0=104.7 +no_defs"
            string proj =
                "+proj=geos +no_defs +a=6378137.0 +b=6356752.3"; // +h=35785863 +a=6378137.0 +b=6356752.3 +lon_0={0} ";

            if (string.IsNullOrEmpty(NOMCenterLon))
            {
                if (attrsDic.ContainsKey("NOMCenterLon"))
                {
                    proj += string.Format(" +lon_0={0}", attrsDic["NOMCenterLon"]);
                }
                else
                {
                    proj += string.Format(" +lon_0={0}", attrsDic["104.7"]);
                }
            }
            else
            {
                proj += string.Format(" +lon_0={0}", NOMCenterLon);
            }

            if (string.IsNullOrEmpty(NOMSatHeight))
            {
                if (attrsDic.ContainsKey("NOMSatHeight"))
                {
                    proj += string.Format(" +h={0}", attrsDic["NOMSatHeight"]);
                }
                else
                {
                    proj += string.Format(" +h={0}", "35785863");
                }
            }
            else
            {
                proj += string.Format(" +h={0}", NOMSatHeight);
            }

            _srcSpatialRef = new SpatialReference("");
            _srcSpatialRef.ImportFromProj4(proj);
            _srcGeoTrans = geoTransform;
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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);
            }
        }