コード例 #1
0
ファイル: MOD06DataProject.cs プロジェクト: windygu/hispeed
        public static void Project(PrjEnvelopeItem prjItem, string dataSet, string locationFile, string dataFile, string outFilename, float outResolution)
        {
            IRasterDataProvider mainRaster     = null;
            IRasterDataProvider locationRaster = null;

            try
            {
                string[] openArgs = new string[] { "datasets=" + dataSet };
                mainRaster = RasterDataDriver.Open(dataFile, openArgs) as IRasterDataProvider;
                string[] locationArgs = new string[] { "datasets=" + "Latitude,Longitude", "geodatasets=" + "Latitude,Longitude" };
                locationRaster = RasterDataDriver.Open(locationFile, locationArgs) as IRasterDataProvider;
                if (locationRaster == null || locationRaster.BandCount == 0)
                {
                    return;
                }
                HDF4FilePrjSettings setting = new HDF4FilePrjSettings();
                setting.LocationFile   = locationRaster;
                setting.OutFormat      = "LDF";
                setting.OutResolutionX = setting.OutResolutionY = outResolution;
                Dictionary <string, double> exargs = new Dictionary <string, double>();
                double invalidValue;
                if (double.TryParse(GetDefaultNullValue(mainRaster.DataType), out invalidValue))
                {
                    exargs.Add("FillValue", invalidValue);
                    setting.ExtArgs = new object[] { exargs };
                }
                HDF4FileProjector projector = new HDF4FileProjector();
                GeoDo.RasterProject.PrjEnvelope mainPrj;
                projector.ComputeDstEnvelope(mainRaster, SpatialReference.GetDefault(), out mainPrj, null);
                GeoDo.RasterProject.PrjEnvelope dstmainPrj = GeoDo.RasterProject.PrjEnvelope.Intersect(prjItem.PrjEnvelope, mainPrj);
                if (dstmainPrj != null)
                {
                    setting.OutEnvelope        = dstmainPrj;
                    setting.OutPathAndFileName = outFilename;
                    projector.Project(mainRaster, setting, SpatialReference.GetDefault(), null);
                }
                else
                {
                    return;
                }
            }
            catch (System.Exception ex)
            {
                string fname = Path.GetFileName(dataFile);
                string label = null;
                if (fname.Contains("MOD"))
                {
                    label = "MOD06ProjectError";
                }
                else if (fname.Contains("MYD"))
                {
                    label = "MYD06ProjectError";
                }
                else
                {
                    label = "AIRSProjectError";
                }
                LogFactory.WriteLine(label, "投影失败!" + ";" + dataFile + ";" + dataSet + ";" + outResolution.ToString("f2") + ";" + outFilename + ";" + ex.Message);
            }
            finally
            {
                if (mainRaster != null)
                {
                    mainRaster.Dispose();
                    mainRaster = null;
                }
                if (locationRaster != null)
                {
                    locationRaster.Dispose();
                    locationRaster = null;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// mod06 云产品5公里数据投影
        /// </summary>
        /// <param name="file"></param>
        /// <param name="outdir"></param>
        /// <param name="dataset"></param>
        /// <param name="env"></param>
        /// <param name="res"></param>
        /// <param name="regionNam"></param>
        /// <param name="progressTracker"></param>
        /// <returns></returns>
        public string Projectmod06(string file, string outdir, string dataset, PrjEnvelope env, float res, string regionNam)
        {
            Action <int, string> progressTracker = null;
            IRasterDataProvider  mainRaster      = null;
            IRasterDataProvider  locationRaster  = null;
            string outfile = outdir + "\\" + Path.GetFileNameWithoutExtension(file) + "." + regionNam + "." + dataset + ".ldf";

            try
            {
                string[] openArgs = new string[] { "datasets=" + dataset };
                mainRaster = RasterDataDriver.Open(file, openArgs) as IRasterDataProvider;
                string[] locationArgs = new string[] { "datasets=" + "Latitude,Longitude", "geodatasets=" + "Latitude,Longitude" };
                locationRaster = RasterDataDriver.Open(file, locationArgs) as IRasterDataProvider;
                if (locationRaster == null || locationRaster.BandCount == 0)
                {
                    return(null);
                }
                HDF4FilePrjSettings setting = new HDF4FilePrjSettings();
                setting.LocationFile   = locationRaster;
                setting.OutFormat      = "LDF";
                setting.OutResolutionX = setting.OutResolutionY = res;
                Dictionary <string, double> exargs = new Dictionary <string, double>();
                if (dataset.Contains("Cloud_Top_Temperature"))
                {
                    exargs.Add("FillValue", -32768);
                }
                if (dataset.Contains("Cloud_Fraction"))
                {
                    exargs.Add("FillValue", 127);
                }
                setting.ExtArgs            = new object[] { exargs };
                setting.OutPathAndFileName = outfile;
                HDF4FileProjector projector = new HDF4FileProjector();
                GeoDo.RasterProject.PrjEnvelope dstmainPrj = env;
                if (dstmainPrj != null)
                {
                    setting.OutEnvelope = dstmainPrj;
                    projector.Project(mainRaster, setting, SpatialReference.GetDefault(), null);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (mainRaster != null)
                {
                    mainRaster.Dispose();
                    mainRaster = null;
                }
                if (locationRaster != null)
                {
                    locationRaster.Dispose();
                    locationRaster = null;
                }
            }
            return(outfile);
        }
コード例 #3
0
        public IExtractResult OutputLAI(IRasterDataProvider angleRaster, string L2LSRFile, bool isNeedPrj = true)
        {
            int outwidth = angleRaster.Width, outheight = angleRaster.Height;
            IRasterDataProvider mainRaster = null;

            try
            {
                #region 建立输出文件
                RasterIdentify datid = new RasterIdentify(Path.GetFileName(L2LSRFile));
                datid.ProductIdentify    = "VGT";
                datid.SubProductIdentify = "0LAI";
                float outResolution = 0.01f;
                if (datid.Resolution == "1000M")
                {
                    outResolution = 0.01f;
                }
                else if (datid.Resolution == "5000M")
                {
                    outResolution = 0.05f;
                }
                string            laiFileName = datid.ToWksFullFileName(".ldf");
                FileExtractResult result      = null;
                if (isNeedPrj)
                {
                    mainRaster = new ArrayRasterDataProvider <UInt16>("Array", output, outwidth, outheight);
                    HDF4FilePrjSettings setting = new HDF4FilePrjSettings();
                    setting.LocationFile   = angleRaster;
                    setting.OutFormat      = "LDF";
                    setting.OutResolutionX = setting.OutResolutionY = outResolution;
                    Dictionary <string, double> exargs = new Dictionary <string, double>();
                    exargs.Add("FillValue", laiFillVlue);
                    setting.ExtArgs = new object[] { exargs };
                    HDF4FileProjector projector             = new HDF4FileProjector();
                    GeoDo.RasterProject.PrjEnvelope mainPrj = null;
                    projector.ComputeDstEnvelope(angleRaster, GeoDo.Project.SpatialReference.GetDefault(), out mainPrj, null);
                    if (mainPrj != null)
                    {
                        setting.OutEnvelope        = mainPrj;
                        setting.OutPathAndFileName = laiFileName;
                        projector.Project(mainRaster, setting, GeoDo.Project.SpatialReference.GetDefault(), null);
                        if (_progressTracker != null)
                        {
                            _progressTracker(100, "LAI数据投影完成!");
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    if (!CreateRaster(laiFileName, 1, enumDataType.UInt16, angleRaster))
                    {
                        return(null);
                    }
                }
                string resultFile = Path.Combine(Path.GetDirectoryName(laiFileName), Path.GetFileNameWithoutExtension(laiFileName) + ".dat");
                if (File.Exists(laiFileName))
                {
                    if (File.Exists(resultFile))
                    {
                        File.Delete(resultFile);
                    }
                    File.Move(laiFileName, resultFile);
                    result = new FileExtractResult("0LAI", resultFile, true);
                }
                else
                {
                    result = new FileExtractResult("0LAI", laiFileName, true);
                }
                result.SetDispaly(true);
                return(result);

                #endregion
            }
            catch (System.Exception ex)
            {
                //_progressTracker(0, ex.Message);
                PrintInfo(ex.Message);
                return(null);
            }
            finally
            {
                if (mainRaster != null)
                {
                    mainRaster.Dispose();
                }
            }
        }