コード例 #1
0
ファイル: SubProduct0SITICE.cs プロジェクト: windygu/hispeed
        private IRasterDataProvider CreateOutRaster(RasterMaper rm)
        {
            RasterIdentify ri = new RasterIdentify(rm.Raster.fileName);

            ri.ProductIdentify    = _subProductDef.ProductDef.Identify;
            ri.SubProductIdentify = _subProductDef.Identify;
            string             outFileName = ri.ToWksFullFileName(".dat");
            IRasterDataDriver  raster      = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            CoordEnvelope      outEnv      = rm.Raster.CoordEnvelope;
            string             mapInfo     = outEnv.ToMapInfoString(new Size(rm.Raster.Width, rm.Raster.Height));
            RasterDataProvider outRaster   = raster.Create(outFileName, rm.Raster.Width, rm.Raster.Height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
コード例 #2
0
ファイル: SubProductQIPCDST.cs プロジェクト: windygu/hispeed
        private IExtractResult ModisAlgorithm()
        {
            int             middleInfraredNo, farInfrared1No, farInfrared2No;
            IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;

            middleInfraredNo = TryGetBandNo(bandNameRaster, "MiddleInfrared");
            farInfrared1No   = TryGetBandNo(bandNameRaster, "FarInfrared1");
            farInfrared2No   = TryGetBandNo(bandNameRaster, "FarInfrared2");
            if (middleInfraredNo == -1 || farInfrared1No == -1 || farInfrared2No == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            int[] bandNos = new int[] { middleInfraredNo, farInfrared1No, farInfrared2No };
            if (_argumentProvider.GetArg("BinaryFile") == null)
            {
                PrintInfo("获取判识结果文件失败。");
                return(null);
            }
            string dblvFile = _argumentProvider.GetArg("BinaryFile").ToString();

            if (string.IsNullOrEmpty(dblvFile) || !File.Exists(dblvFile))
            {
                PrintInfo("获取判识结果文件失败。");
                return(null);
            }
            float mbtd = (float)_argumentProvider.GetArg("mbtd");
            float mbt  = (float)_argumentProvider.GetArg("mbt");

            int ntype = Int32.Parse(_argumentProvider.GetArg("ntype").ToString());
            //获取查找表参数
            LookupTableArgument argument = new LookupTableArgument();
            //进行光学厚度与沙尘粒子有效半径计算需要文件:1、原始影像数据;2、查算表数据
            List <RasterMaper> inputRms  = new List <RasterMaper>();
            List <RasterMaper> outputRms = new List <RasterMaper>();

            try
            {
                //当前影像(待判识文件)
                RasterMaper rm = new RasterMaper(_argumentProvider.DataProvider, bandNos);
                inputRms.Add(rm);
                IRasterDataProvider dblvPrd = GeoDataDriver.Open(dblvFile) as IRasterDataProvider;
                RasterMaper         dblvRm  = new RasterMaper(dblvPrd, new int[] { 1 });
                inputRms.Add(dblvRm);
                RasterIdentify ri = new RasterIdentify(_argumentProvider.DataProvider.fileName);
                ri.ProductIdentify       = "DST";
                ri.IsOutput2WorkspaceDir = true;
                IRasterDataProvider reRaster = CreateOutRaster(ri, dblvPrd, "0DRE");
                RasterMaper         reRm     = new RasterMaper(reRaster, new int[] { 1 });
                outputRms.Add(reRm);
                IRasterDataProvider optRaster = CreateOutRaster(ri, dblvPrd, "0OPT");
                RasterMaper         optRm     = new RasterMaper(optRaster, new int[] { 1 });
                outputRms.Add(optRm);
                IRasterDataProvider denRaster = CreateOutRaster(ri, dblvPrd, "DDEN");
                RasterMaper         denRm     = new RasterMaper(denRaster, new int[] { 1 });
                outputRms.Add(denRm);
                //栅格数据映射
                RasterMaper[] fileIns  = inputRms.ToArray();
                RasterMaper[] fileOuts = outputRms.ToArray();
                //创建处理模型
                RasterProcessModel <short, float> rfr = new RasterProcessModel <short, float>();
                rfr.SetRaster(fileIns, fileOuts);
                #region
                rfr.RegisterCalcModel(new RasterCalcHandler <short, float>((rvInVistor, rvOutVistor, aoi) =>
                {
                    int nindex;
                    double ocdiff      = 0, mindiff = 0, den = 0, gcon;
                    float den0, rpsize = 0, rpsize0, rpmin = 0.01f, rpmax = 100;
                    double sgma        = 2.0, sgdust = 2.5e-12;
                    double dr          = (Math.Log10(rpmax) - Math.Log10(rpmin)) / 100;
                    if (rvInVistor[0].RasterBandsData[0] != null)
                    {
                        int length = rvInVistor[0].RasterBandsData[0].Length;
                        for (int i = 0; i < length; i++)
                        {
                            if (rvInVistor[1].RasterBandsData[0][i] == 1)
                            {
                                float bt31    = rvInVistor[0].RasterBandsData[1][i] / 10f;
                                float btd3132 = (rvInVistor[0].RasterBandsData[1][i] - rvInVistor[0].RasterBandsData[2][i]) / 10f;
                                float btd2931 = (rvInVistor[0].RasterBandsData[0][i] - rvInVistor[0].RasterBandsData[1][i]) / 10f;
                                for (int m = 0; m < 50; m++)
                                {
                                    for (int n = 0; n < 29; n++)
                                    {
                                        ocdiff = Math.Pow(btd3132 - argument.Cbtd3132[m, n], 2) + Math.Pow((btd2931 - argument.Cbtd2931[m, n]), 2) * mbtd
                                                 + Math.Pow((bt31 - argument.Cbt31[m, n]), 2) * mbt;
                                        if (ocdiff < mindiff || (m == 0 && n == 0))
                                        {
                                            mindiff = ocdiff;
                                            rvOutVistor[0].RasterBandsData[0][i] = argument.Dref[n];
                                            rvOutVistor[1].RasterBandsData[0][i] = argument.Dopt[m];
                                        }
                                    }
                                }
                                //计算rvOutVistor[2].RasterBandsData[0][i]载沙量
                                if (rvOutVistor[0].RasterBandsData[0][i] <= 1)
                                {
                                    nindex = (int)(rvOutVistor[0].RasterBandsData[0][i] * 10);
                                }
                                else
                                {
                                    nindex = (int)(rvOutVistor[0].RasterBandsData[0][i]) + 9;
                                }
                                den0        = rvOutVistor[1].RasterBandsData[0][i] / argument.Ext55[nindex - 1];
                                double ravg = Calravg(rvOutVistor[1].RasterBandsData[0][i], sgma);
                                double tcv  = 0;
                                rpsize      = rpmin;
                                for (int j = 0; j < 100; j++)
                                {
                                    //源代码中未定义type为1,2所需变量初始值
                                    den     = DType(ntype, rpsize, 0, 0, 0, 0, 0, 0, 0, den0, ravg, sgma);
                                    rpsize0 = rpsize;
                                    rpsize  = (float)Math.Pow(10, (Math.Log10(rpsize) + dr));
                                    gcon    = 4f / 3 * Math.PI * Math.Pow(rpsize0, 3) * den * (rpsize - rpsize0);
                                    tcv    += gcon;
                                }
                                float value = (float)((tcv * sgdust * 1.0e+9 * 10));
                                rvOutVistor[2].RasterBandsData[0][i] = value > 50f ? 50f : value;
                            }
                        }
                    }
                }));
                #endregion
                rfr.Excute();
                FileExtractResult reResult = new FileExtractResult("0DRE", reRaster.fileName, true);
                reResult.SetDispaly(false);
                FileExtractResult optResult = new FileExtractResult("0OPT", optRaster.fileName, true);
                optResult.SetDispaly(false);
                FileExtractResult  denResult   = new FileExtractResult("DDEN", denRaster.fileName, true);
                ExtractResultArray resultArray = new ExtractResultArray(_subProductDef.Identify);
                resultArray.Add(reResult);
                resultArray.Add(optResult);
                //生成载沙量
                resultArray.Add(denResult);
                return(resultArray);
            }
            finally
            {
                for (int i = 1; i < inputRms.Count; i++)
                {
                    if (inputRms[i].Raster != null)
                    {
                        inputRms[i].Raster.Dispose();
                    }
                }
                foreach (RasterMaper rm in outputRms)
                {
                    if (rm.Raster != null)
                    {
                        rm.Raster.Dispose();
                    }
                }
            }
        }
コード例 #3
0
ファイル: LSTDataProcessor.cs プロジェクト: windygu/hispeed
        public static IExtractResult AVGProcessor(Action <int, string> progressTracker, IContextMessage contextMessage, bool add2Workspace,
                                                  string[] fileNames, int bandNo, string subProIdentify, UInt16[] cloudValues, UInt16[] waterValues, string outFileName)
        {
            List <RasterMaper> rms = new List <RasterMaper>();

            try
            {
                for (int i = 0; i < fileNames.Length; i++)
                {
                    IRasterDataProvider inRaster = RasterDataDriver.Open(fileNames[i]) as IRasterDataProvider;
                    if (inRaster.BandCount < bandNo)
                    {
                        PrintInfo(contextMessage, "请选择正确的数据进行平均值合成。");
                        return(null);
                    }
                    RasterMaper rm = new RasterMaper(inRaster, new int[] { bandNo });
                    rms.Add(rm);
                }
                //输出文件准备(作为输入栅格并集处理)
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <ushort, ushort> rfr = null;
                    rfr = new RasterProcessModel <ushort, ushort>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    rfr.RegisterCalcModel(new RasterCalcHandler <ushort, ushort>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength     = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        ushort[] sumData   = new ushort[dataLength];
                        ushort[] countData = new ushort[dataLength];
                        if (cloudValues != null && cloudValues.Length > 0)
                        {
                            foreach (RasterVirtualVistor <ushort> rv in rvInVistor)
                            {
                                if (rv.RasterBandsData == null)
                                {
                                    continue;
                                }
                                ushort[] dt = rv.RasterBandsData[0];
                                if (dt != null)
                                {
                                    for (int index = 0; index < dataLength; index++)
                                    {
                                        if (IsNanValue(dt[index], cloudValues) || IsNanValue(dt[index], waterValues))
                                        {
                                            sumData[index] = (sumData[index] == 0 && countData[index] == 0) ? dt[index] : sumData[index];
                                            continue;
                                        }
                                        else
                                        {
                                            if (IsNanValue(sumData[index], cloudValues) ||
                                                IsNanValue(dt[index], waterValues) && countData[index] == 0)
                                            {
                                                sumData[index] = 0;
                                            }
                                            if (dt[index] == 0)
                                            {
                                                continue;
                                            }
                                            sumData[index] += dt[index];
                                            countData[index]++;
                                        }
                                    }
                                }
                            }
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            if (countData[index] != 0)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (ushort)(sumData[index] / countData[index]);
                            }
                            else
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = sumData[index];
                            }
                        }
                    }));
                    //执行
                    rfr.Excute();
                    FileExtractResult res = new FileExtractResult(subProIdentify, outFileName, add2Workspace);
                    res.SetDispaly(false);
                    return(res);
                }
            }
            finally
            {
                foreach (RasterMaper rm in rms)
                {
                    rm.Raster.Dispose();
                }
            }
        }
コード例 #4
0
        private void ComputeFracFile(string sumFile, string file)
        {
            //"china_bares.dat"
            //"china_grass.dat";
            //"china_forest.dat";
            //"china_farmhand.dat"
            file = file.ToLower();
            string argFile    = null;
            string argFileDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ProductArgs\\SNW\\SnowArgFile");

            if (file.Contains("bares"))
            {
                argFile = Path.Combine(argFileDir, "china_bares.dat");
            }
            else
            {
                if (file.Contains("grass"))
                {
                    argFile = Path.Combine(argFileDir, "china_grass.dat");
                }
                else
                {
                    if (file.Contains("forest"))
                    {
                        argFile = Path.Combine(argFileDir, "china_forest.dat");
                    }
                    else
                    {
                        if (file.Contains("farmhand"))
                        {
                            argFile = Path.Combine(argFileDir, "china_farmhand.dat");
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
            List <RasterMaper>  rms       = null;
            IRasterDataProvider outRaster = null;

            try
            {
                IRasterDataProvider argPrd = GeoDataDriver.Open(argFile) as IRasterDataProvider;
                rms = new List <RasterMaper>();
                RasterMaper rmArg = new RasterMaper(argPrd, new int[] { 1 });
                rms.Add(rmArg);
                IRasterDataProvider sumPrd = GeoDataDriver.Open(sumFile) as IRasterDataProvider;
                RasterMaper         rmSum  = new RasterMaper(sumPrd, new int[] { 1 });
                rms.Add(rmSum);
                outRaster = CreateOutRaster(file, enumDataType.Int16, rms.ToArray(), argPrd.ResolutionX);
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                RasterProcessModel <double, Int16> rfr = new RasterProcessModel <double, Int16>();
                rfr.SetRaster(fileIns, fileOuts);
                rfr.RegisterCalcModel(new RasterCalcHandler <double, Int16>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData != null && rvInVistor[1].RasterBandsData[0] != null)
                    {
                        int dataLength = rvInVistor[0].SizeY * rvInVistor[0].SizeX;
                        for (int j = 0; j < dataLength; j++)
                        {
                            if (rvInVistor[1].RasterBandsData[0][j] == 0)
                            {
                                rvOutVistor[0].RasterBandsData[0][j] = 0;
                            }
                            else
                            {
                                rvOutVistor[0].RasterBandsData[0][j] = (Int16)(rvInVistor[0].RasterBandsData[0][j] / rvInVistor[1].RasterBandsData[0][j] * 10000);
                            }
                        }
                    }
                }));
                rfr.Excute();
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
コード例 #5
0
        private IFileExtractResult ComputeSnowSWE(string filenameDensity, string depthFileName)
        {
            List <RasterMaper>  rms                 = null;
            IRasterDataProvider outRaster           = null;
            RasterProcessModel <double, double> rfr = null;

            try
            {
                rms = new List <RasterMaper>();
                IRasterDataProvider inRaster1 = GeoDataDriver.Open(depthFileName) as IRasterDataProvider;
                RasterMaper         fileIn1   = new RasterMaper(inRaster1, new int[] { 1 });
                rms.Add(fileIn1);
                IRasterDataProvider inRaster2 = GeoDataDriver.Open(filenameDensity) as IRasterDataProvider;
                RasterMaper         fileIn2   = new RasterMaper(inRaster2, new int[] { 1 });
                rms.Add(fileIn2);

                string sweFileName = GetFileName(new string[] { depthFileName }, _subProductDef.ProductDef.Identify, "MSWE", ".dat", null);
                outRaster = CreateOutRaster(sweFileName, enumDataType.Double, rms.ToArray(), inRaster2.ResolutionX);
                RasterMaper   fileOut  = new RasterMaper(outRaster, new int[] { 1 });
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { fileOut };
                rfr = new RasterProcessModel <double, double>();
                rfr.SetRaster(fileIns, fileOuts);

                rfr.RegisterCalcModel(new RasterCalcHandler <double, double>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData[0] != null && rvInVistor[1].RasterBandsData[0] != null)
                    {
                        int dataLength  = rvInVistor[0].SizeY * rvInVistor[0].SizeX;
                        double[] swetmp = new double[dataLength];
                        for (int i = 0; i < dataLength; i++)
                        {
                            swetmp[i] = rvInVistor[0].RasterBandsData[0][i] * rvInVistor[1].RasterBandsData[0][i] * 10;
                            if (swetmp[i] < 0)
                            {
                                swetmp[i] = 0;
                            }
                            rvOutVistor[0].RasterBandsData[0][i] = swetmp[i];
                        }
                    }
                }));
                rfr.Excute();
                IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, sweFileName, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
コード例 #6
0
        private string GetArgSummaryFile(string fileNameBare, string filenameGrass, string filenameForest, string filenameFarmhand)
        {
            string outFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ProductArgs\\SNW\\SnowArgFile\\sum.dat");

            if (File.Exists(outFileName))
            {
                return(outFileName);
            }
            List <RasterMaper>  rms                 = null;
            IRasterDataProvider outRaster           = null;
            RasterProcessModel <double, double> rfr = null;

            try
            {
                IRasterDataProvider barePrd     = GeoDataDriver.Open(fileNameBare) as IRasterDataProvider;
                IRasterDataProvider grassPrd    = GeoDataDriver.Open(filenameGrass) as IRasterDataProvider;
                IRasterDataProvider forestPrd   = GeoDataDriver.Open(filenameForest) as IRasterDataProvider;
                IRasterDataProvider farmhandPrd = GeoDataDriver.Open(filenameFarmhand) as IRasterDataProvider;
                rms = new List <RasterMaper>();
                RasterMaper rmBare = new RasterMaper(barePrd, new int[] { 1 });
                rms.Add(rmBare);
                RasterMaper rmGrass = new RasterMaper(grassPrd, new int[] { 1 });
                rms.Add(rmGrass);
                RasterMaper rmForest = new RasterMaper(forestPrd, new int[] { 1 });
                rms.Add(rmForest);
                RasterMaper rmFarm = new RasterMaper(farmhandPrd, new int[] { 1 });
                rms.Add(rmFarm);
                outRaster = CreateOutRaster(outFileName, enumDataType.Double, rms.ToArray(), 0.1f);
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                rfr = new RasterProcessModel <double, double>();
                rfr.SetRaster(fileIns, fileOuts);
                rfr.RegisterCalcModel(new RasterCalcHandler <double, double>((rvInVistor, rvOutVistor, aoi) =>
                {
                    for (int i = 0; i < rvInVistor.Length; i++)
                    {
                        if (rvInVistor[i].RasterBandsData != null)
                        {
                            int dataLength = rvInVistor[0].SizeY * rvInVistor[0].SizeX;
                            for (int j = 0; j < dataLength; j++)
                            {
                                rvOutVistor[0].RasterBandsData[0][j] += rvInVistor[i].RasterBandsData[0][j];
                            }
                        }
                    }
                }));
                rfr.Excute();
                return(outFileName);
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: SubProduct0SITICE.cs プロジェクト: windygu/hispeed
        private IExtractResult IceThinknessAlgorithm(Action <int, string> progressTracker)
        {
            IRasterDataProvider dataPrd = _argumentProvider.DataProvider;

            if (dataPrd == null)
            {
                return(null);
            }
            if (_argumentProvider.GetArg("DBLVFile") == null)
            {
                return(null);
            }
            string dblvFile = _argumentProvider.GetArg("DBLVFile").ToString();

            if (string.IsNullOrEmpty(dblvFile) || !File.Exists(dblvFile))
            {
                return(null);
            }
            IRasterDataProvider dblvRaster = GeoDataDriver.Open(dblvFile) as IRasterDataProvider;
            float t1 = Obj2Float(_argumentProvider.GetArg("T1"));
            float t2 = Obj2Float(_argumentProvider.GetArg("T2"));
            float t3 = Obj2Float(_argumentProvider.GetArg("T3"));

            if (float.IsNaN(t1) || float.IsNaN(t2) || float.IsNaN(t3))
            {
                PrintInfo("获取计算参数失败。");
                return(null);
            }
            IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;
            int             bandNo         = TryGetBandNo(bandNameRaster, "FarInfrared");

            if (bandNo == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            string[] aois        = _argumentProvider.GetArg("AOITemplate") as string[];
            string   aoiTemplate = (aois == null || aois.Length == 0) ? null : aois[0];
            //输入文件准备
            List <RasterMaper> rms    = new List <RasterMaper>();
            RasterMaper        rm     = new RasterMaper(dataPrd, new int[] { bandNo });
            RasterMaper        dblvRm = new RasterMaper(dblvRaster, new int[] { 1 });

            rms.Add(rm);
            rms.Add(dblvRm);
            //创建结果数据
            using (IRasterDataProvider outRaster = CreateOutRaster(rm))
            {
                //栅格数据映射
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                //创建处理模型
                RasterProcessModel <short, short> rfr = null;
                rfr = new RasterProcessModel <short, short>(progressTracker);
                rfr.SetRaster(fileIns, fileOuts);
                rfr.SetTemplateAOI("vector:海陆模版_反");
                rfr.RegisterCalcModel(new RasterCalcHandler <short, short>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData[0] != null)
                    {
                        if (aoi != null && aoi.Length != 0)
                        {
                            int index;
                            for (int i = 0; i < aoi.Length; i++)
                            {
                                index = aoi[i];
                                if (rvInVistor[1].RasterBandsData[0][index] == 1)
                                {
                                    short value = rvInVistor[0].RasterBandsData[0][index];
                                    if (value > t1)
                                    {
                                        rvOutVistor[0].RasterBandsData[0][index] = -1;
                                    }
                                    else
                                    {
                                        if (value > t2)
                                        {
                                            rvOutVistor[0].RasterBandsData[0][index] = 1;
                                        }
                                        else if (value > t3)
                                        {
                                            rvOutVistor[0].RasterBandsData[0][index] = 5;
                                        }
                                        else
                                        {
                                            rvOutVistor[0].RasterBandsData[0][index] = 10;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }));
                //执行
                rfr.Excute(Int16.MinValue);
                FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outRaster.fileName, true);
                res.SetDispaly(false);
                return(res);
            }
        }
コード例 #8
0
ファイル: SubProductAVGLST.cs プロジェクト: windygu/hispeed
        public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage)
        {
            _contextMessage = contextMessage;
            if (_argumentProvider == null)
            {
                return(null);
            }
            if (_argumentProvider.GetArg("AlgorithmName") == null)
            {
                PrintInfo("参数\"AlgorithmName\"为空。");
                return(null);
            }
            string algorith = _argumentProvider.GetArg("AlgorithmName").ToString();

            if (algorith != "0AVG")
            {
                PrintInfo("指定的算法\"" + algorith + "\"没有实现。");
                return(null);
            }
            string[] fileNames = GetStringArray("SelectedPrimaryFiles");
            if (fileNames == null || fileNames.Count() == 0)
            {
                PrintInfo("请选择参与平均值合成的数据。");
                return(null);
            }
            foreach (string f in fileNames)
            {
                if (!File.Exists(f))
                {
                    PrintInfo("所选择的数据:\"" + f + "\"不存在。");
                    return(null);
                }
            }
            int bandNo = 1;
            //输入文件准备
            List <RasterMaper> rms = new List <RasterMaper>();

            try
            {
                for (int i = 0; i < fileNames.Length; i++)
                {
                    IRasterDataProvider inRaster = RasterDataDriver.Open(fileNames[i]) as IRasterDataProvider;
                    if (inRaster.BandCount < bandNo)
                    {
                        PrintInfo("请选择正确的数据进行平均值合成。");
                        return(null);
                    }
                    RasterMaper rm = new RasterMaper(inRaster, new int[] { bandNo });
                    rms.Add(rm);
                }
                //输出文件准备(作为输入栅格并集处理)
                RasterIdentify ri          = GetRasterIdentifyID(fileNames);
                string         outFileName = ri.ToWksFullFileName(".dat");
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <Int16, Int16> rfr = null;
                    rfr = new RasterProcessModel <Int16, Int16>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    Int16[] nanValues   = GetNanValues("CloudyValue");
                    Int16[] waterValues = GetNanValues("WaterValue");
                    rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength       = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        Int16[] sumData      = new Int16[dataLength];
                        Int16[] countData    = new Int16[dataLength];
                        Int16[] invailValues = GetNanValues("InvailValue");
                        if (nanValues != null && nanValues.Length > 0)
                        {
                            foreach (RasterVirtualVistor <Int16> rv in rvInVistor)
                            {
                                if (rv.RasterBandsData == null)
                                {
                                    continue;
                                }
                                Int16[] dt = rv.RasterBandsData[0];
                                if (dt != null)
                                {
                                    for (int index = 0; index < dataLength; index++)
                                    {
                                        if (invailValues.Contains(dt[index]))
                                        {
                                            continue;
                                        }
                                        if (IsNanValue(dt[index], nanValues) || IsNanValue(dt[index], waterValues))
                                        {
                                            //临时修改 用于符合李亚军数据生产
                                            if (IsNanValue(dt[index], nanValues))
                                            {
                                                countData[index] = 0;
                                            }
                                            else
                                            {
                                                sumData[index] = -1;
                                            }
                                            //
                                            //sumData[index] = (sumData[index] == 0 && countData[index] == 0) ? dt[index] : sumData[index];
                                            continue;
                                        }
                                        else
                                        {
                                            //临时修改 用于符合李亚军数据生产
                                            if (sumData[index] == -1)
                                            {
                                                countData[index] = 0;
                                                continue;
                                            }
                                            //

                                            if (IsNanValue(sumData[index], nanValues) ||
                                                IsNanValue(dt[index], waterValues) && countData[index] == 0)
                                            {
                                                sumData[index] = 0;
                                            }
                                            sumData[index] += dt[index];
                                            countData[index]++;
                                        }
                                    }
                                }
                            }
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            if (countData[index] != 0)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (Int16)(sumData[index] / countData[index]);
                            }
                            else
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = sumData[index];
                            }
                        }
                    }));
                    //执行
                    rfr.Excute();
                    FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                    res.SetDispaly(false);
                    return(res);
                }
            }
            finally
            {
                foreach (RasterMaper rm in rms)
                {
                    rm.Raster.Dispose();
                }
            }
        }
コード例 #9
0
ファイル: SubProductLTLRLST.cs プロジェクト: windygu/hispeed
        private IExtractResult LTLREAlgorithm(Action <int, string> progressTracker)
        {
            float  tempratureMin = (float)_argumentProvider.GetArg("TempratureMin");
            double lftrZoom      = (double)_argumentProvider.GetArg("LTFRZoom");
            bool   isChaz        = (bool)_argumentProvider.GetArg("isChaz");
            Int16  maxLst        = (Int16)((isChaz ? tempratureMin : (273 + tempratureMin)) * lftrZoom);

            string[] fileNames = GetStringArray("SelectedPrimaryFiles");
            if (fileNames == null || fileNames.Count() == 0)
            {
                PrintInfo("请选择参与低温天数统计的数据!");
                return(null);
            }
            foreach (string f in fileNames)
            {
                if (!File.Exists(f))
                {
                    PrintInfo("所选择的数据:\"" + f + "\"不存在。");
                    return(null);
                }
            }
            int bandNo = 1;
            //输出文件准备(作为输入栅格并集处理)
            RasterIdentify ri          = GetRasterIdentifyID(fileNames);
            string         outFileName = ri.ToWksFullFileName(".dat");
            //输入文件准备
            List <RasterMaper> rms = new List <RasterMaper>();

            try
            {
                for (int i = 0; i < fileNames.Length; i++)
                {
                    IRasterDataProvider inRaster = RasterDataDriver.Open(fileNames[i]) as IRasterDataProvider;
                    if (inRaster.BandCount < bandNo)
                    {
                        PrintInfo("请选择正确的数据进行低温天数统计。");
                        return(null);
                    }
                    RasterMaper rm = new RasterMaper(inRaster, new int[] { bandNo });
                    rms.Add(rm);
                }
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <Int16, Int16> rfr = null;
                    rfr = new RasterProcessModel <Int16, Int16>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    Int16[] nanValues     = GetNanValues("CloudyValue");
                    Int16[] waterValues   = GetNanValues("WaterValue");
                    Int16[] invailValues  = GetNanValues("InvailValue");
                    Int16   currTimeValue = 0;
                    rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength    = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        Int16[] timeValue = new Int16[dataLength];
                        for (int i = 0; i < dataLength; i++)
                        {
                            timeValue[i] = 0;
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            foreach (RasterVirtualVistor <Int16> rvs in rvInVistor)
                            {
                                Int16[] dt = rvs.RasterBandsData[0];
                                if (dt == null)
                                {
                                    continue;
                                }
                                if (invailValues.Contains(dt[index]))
                                {
                                    continue;
                                }
                                if (TimeValue(dt[index], nanValues, waterValues, invailValues, timeValue[index], maxLst, out currTimeValue))
                                {
                                    timeValue[index] = currTimeValue;
                                }
                            }
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            rvOutVistor[0].RasterBandsData[0][index] = timeValue[index];
                        }
                    }));
                    //执行
                    rfr.Excute(0);
                    FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                    res.SetDispaly(false);
                }
            }
            finally
            {
                foreach (RasterMaper rm in rms)
                {
                    rm.Raster.Dispose();
                }
            }

            _argumentProvider.SetArg("SelectedPrimaryFiles", new string[] { outFileName });
            string instanceIdentify = _argumentProvider.GetArg("OutFileIdentify") as string;

            if (string.IsNullOrWhiteSpace(instanceIdentify))
            {
                return(null);
            }
            SubProductInstanceDef instance = FindSubProductInstanceDefs(instanceIdentify);

            return(ThemeGraphyByInstance(instance));
        }
コード例 #10
0
        //生成亮温背景库算法
        //云水 怎么处理
        private IExtractResult BackBGFileAlg(Action <int, string> progressTracker)
        {
            //亮温数据放大倍数
            Int16 TBZoom   = Convert.ToInt16(_argumentProvider.GetArg("LBZoom"));
            int   LBBandCH = (int)_argumentProvider.GetArg("LBBand");
            //亮温数据生成的背景库放大倍数
            Int16 TBBackZoom = Convert.ToInt16(_argumentProvider.GetArg("OutLBBackZoom"));

            //亮温输入文件
            string[] tbfiles = GetStringArray("LBFile");

            //NDVI输出文件--根据输入文件信息输出
            string outtbbackfile = GetFileName(tbfiles, _subProductDef.ProductDef.Identify, _identify, ".ldf", null); //默认位置输出

            List <RasterMaper> rasterInputMaps = new List <RasterMaper>();                                            //从配置文件中读取需要待合成ldf数据,此处只有一个ldf文件

            foreach (string itemfile in tbfiles)
            {
                IRasterDataProvider inraster = RasterDataDriver.Open(itemfile) as IRasterDataProvider;
                rasterInputMaps.Add(new RasterMaper(inraster, new int[] { LBBandCH }));
            }
            IRasterDataProvider outLBbackRaster = null;

            try
            {
                //栅格数据映射
                RasterMaper[] fileIns = rasterInputMaps.ToArray();
                RasterMaper[] fileOuts;
                outLBbackRaster = CreateOutLDFRaster(outtbbackfile, rasterInputMaps.ToArray(), 5);
                fileOuts        = new RasterMaper[] { new RasterMaper(outLBbackRaster, new int[] { 1, 2, 3, 4, 5 }) };//输出为固定5个波段数据
                //创建处理模型
                RasterProcessModel <Int16, Int16> rfr = new RasterProcessModel <Int16, Int16>(progressTracker);
                rfr.SetRaster(fileIns, fileOuts);
                rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                {
                    int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;//输出长*宽

                    //初始化各波段原始数据
                    Int16 maxNDVI      = Int16.MinValue;
                    Int16 minNDVI      = Int16.MinValue;
                    Int16 secmaxNDVI   = Int16.MinValue;
                    Int16 secminNDVI   = Int16.MinValue;
                    double averageNDVI = Int16.MinValue;
                    for (int index = 0; index < dataLength; index++)
                    {
                        List <Int16> listtemp = new List <Int16>();
                        List <Int16> listavg  = new List <short>();
                        for (int fileindex = 0; fileindex < rvInVistor.Length; fileindex++)
                        {
                            listtemp.Add(rvInVistor[fileindex].RasterBandsData[0][index]);
                            listavg.Add(rvInVistor[fileindex].RasterBandsData[0][index]);
                        }
                        //调整排序
                        listtemp.Sort();                         //按照从小到大升序排列
                        listtemp = listtemp.Distinct().ToList(); //去重
                        if (listtemp.Count == 1 && listtemp[0] == 0)
                        {
                            maxNDVI     = 0;
                            minNDVI     = 0;
                            secmaxNDVI  = 0;
                            secminNDVI  = 0;
                            averageNDVI = 0;
                        }
                        else
                        {
                            ////这里是否需要考虑有效范围
                            maxNDVI    = listtemp[listtemp.Count - 1];                                                     //最大值 此处文件个数大于1
                            minNDVI    = listtemp[0];                                                                      //最小值 此处文件数大于1
                            secmaxNDVI = listtemp.Count > 1 ? listtemp[listtemp.Count - 2] : listtemp[listtemp.Count - 1]; //次大值
                            secminNDVI = listtemp.Count > 1 ? listtemp[1] : listtemp[0];                                   //次小值
                            //平均值
                            //去除 0
                            averageNDVI = listavg.Where(num => num != 0).Average(num => (int)(num));//平均值
                        }
                        //给输出Raster填值,此处为固定五个波段 并考虑放大倍数的处理
                        rvOutVistor[0].RasterBandsData[0][index] = (Int16)(maxNDVI * TBBackZoom / TBZoom);
                        rvOutVistor[0].RasterBandsData[1][index] = (Int16)(minNDVI * TBBackZoom / TBZoom);
                        rvOutVistor[0].RasterBandsData[2][index] = (Int16)(secmaxNDVI * TBBackZoom / TBZoom);
                        rvOutVistor[0].RasterBandsData[3][index] = (Int16)(secminNDVI * TBBackZoom / TBZoom);
                        rvOutVistor[0].RasterBandsData[4][index] = (Int16)(averageNDVI * TBBackZoom / TBZoom);
                    }
                }));
                rfr.Excute();
                FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outtbbackfile, true);
                res.SetDispaly(false);
                return(res);
            }
            catch (Exception ex)
            {
                PrintInfo("算法处理过程发生异常!\n" + ex.StackTrace);
                return(null);
            }

            finally
            {
                if (outLBbackRaster != null)
                {
                    outLBbackRaster.Dispose();
                }
                if (outLBbackRaster != null)
                {
                    outLBbackRaster.Dispose();
                }
            }
        }
コード例 #11
0
        public static bool DoElevationCorrections(TVDIUCArgs ucArgs, ref string error)
        {
            if (string.IsNullOrEmpty(ucArgs.LSTFile) || string.IsNullOrEmpty(ucArgs.DEMFile) || ucArgs.TVDIParas == null || ucArgs.TVDIParas.LstFile == null)
            {
                error = "陆表高温高程订正所需数据或参数设置不全.";
                return(false);
            }

            string lstFile = ucArgs.LSTFile;
            string demFile = ucArgs.DEMFile;
            float  lstZoom = ucArgs.TVDIParas.LstFile.Zoom;
            int    lstMin  = ucArgs.TVDIParas.LstFile.Min;
            int    lstMax  = ucArgs.TVDIParas.LstFile.Max;
            int    lstBand = ucArgs.TVDIParas.LstFile.Band;

            IRasterDataProvider lstPrd = null;
            IRasterDataProvider demPrd = null;

            try
            {
                List <RasterMaper> rms = new List <RasterMaper>();
                lstPrd = RasterDataDriver.Open(lstFile) as IRasterDataProvider;
                if (lstPrd.BandCount < lstBand)
                {
                    error = "选择的文件不正确,请重新选择。";
                    return(false);
                }
                RasterMaper lstRm = new RasterMaper(lstPrd, new int[] { lstBand });
                rms.Add(lstRm);

                demPrd = RasterDataDriver.Open(demFile) as IRasterDataProvider;
                if (demPrd.BandCount < 1)
                {
                    error = "选择的文件不正确,请重新选择。";
                    return(false);
                }
                RasterMaper demRm = new RasterMaper(demPrd, new int[] { 1 });
                rms.Add(demRm);

                //输出文件准备(作为输入栅格并集处理)
                string outFileName = CreatOutFileName(lstFile, demFile);
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <Int16, Int16> rfr = new RasterProcessModel <Int16, Int16>();
                    rfr.SetRaster(fileIns, fileOuts);
                    rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        int value0     = 0;
                        int value1     = 0;
                        if (rvInVistor[0].RasterBandsData == null || rvInVistor[1].RasterBandsData == null ||
                            rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1].RasterBandsData[0] == null)
                        {
                            return;
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            value0 = rvInVistor[0].RasterBandsData[0][index];
                            value1 = rvInVistor[1].RasterBandsData[0][index];
                            if (value1 == -9999)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = 9999;//海洋
                                continue;
                            }
                            if (value1 == -9000)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = 9000;//非中国区域陆地
                                continue;
                            }
                            if (value1 >= 6000)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = 0; //6000之内的LST数据
                                continue;
                            }
                            if (value0 == ucArgs.TVDIParas.LstFile.Cloudy)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = 9998; //云区
                                continue;
                            }
                            if (value0 == 12)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = 9997;//无数据区域
                                continue;
                            }
                            if (value0 == 0)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = 0;
                                continue;
                            }
                            if (value1 == 0)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = 0;
                                continue;
                            }
                            rvOutVistor[0].RasterBandsData[0][index] = (Int16)(((double)value0 / lstZoom - 273 + 0.006 * value1) * lstZoom);
                        }
                    }));
                    //执行
                    rfr.Excute();
                    //FileExtractResult res = new FileExtractResult("0LEC", outFileName, true);
                    //res.SetDispaly(false);
                }
                ucArgs.ECLstFile = outFileName;
                return(true);
            }
            finally
            {
                if (lstPrd != null)
                {
                    lstPrd.Dispose();
                }
                if (demPrd != null)
                {
                    demPrd.Dispose();
                }
            }
        }
コード例 #12
0
        private IExtractResult CalcVci(string algorithmName, Action <int, string> progressTracker)
        {
            if (_argumentProvider.GetArg("mainfiles") == null)
            {
                PrintInfo("请选择NDVI数据。");
                return(null);
            }
            string ndviFile = _argumentProvider.GetArg("mainfiles").ToString();

            if (!File.Exists(ndviFile))
            {
                PrintInfo("选择的数据\"" + ndviFile + "\"不存在。");
                return(null);
            }

            if (_argumentProvider.GetArg("NdviCH") == null)
            {
                PrintInfo("参数\"NdviCH\"为空。");
                return(null);
            }
            int ndviCH = (int)(_argumentProvider.GetArg("NdviCH"));

            if (_argumentProvider.GetArg("NdviMaxCH") == null)
            {
                PrintInfo("参数\"NdviMaxCH\"为空。");
                return(null);
            }
            int ndviMaxCH = (int)(_argumentProvider.GetArg("NdviMaxCH"));

            if (_argumentProvider.GetArg("NdviMinCH") == null)
            {
                PrintInfo("参数\"NdviMinCH\"为空。");
                return(null);
            }
            int ndviMinCH = (int)(_argumentProvider.GetArg("NdviMinCH"));

            if (ndviCH < 1 || ndviMaxCH < 1 || ndviMinCH < 1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            if (_argumentProvider.GetArg("resultZoom") == null)
            {
                PrintInfo("参数\"resultZoom\"为空。");
                return(null);
            }
            UInt16 resultZoom = Convert.ToUInt16(_argumentProvider.GetArg("resultZoom"));
            string backFile   = null;

            if (_argumentProvider.GetArg("BackFile") == null)
            {
                string defaultPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ndvi_0901.ldf");
                if (!File.Exists(defaultPath))
                {
                    return(null);
                }
                backFile = defaultPath;
            }
            else
            {
                backFile = _argumentProvider.GetArg("BackFile").ToString();
            }
            if (backFile == ndviFile)
            {
                PrintInfo("请选择正确的背景库数据!");
                return(null);
            }
            List <RasterMaper> rms = new List <RasterMaper>();

            try
            {
                IRasterDataProvider ndviRaster = RasterDataDriver.Open(ndviFile) as IRasterDataProvider;
                if (ndviRaster.BandCount < ndviCH)
                {
                    PrintInfo("");
                    return(null);
                }
                RasterMaper rm = new RasterMaper(ndviRaster, new int[] { ndviCH });
                rms.Add(rm);
                IRasterDataProvider backRaster = RasterDataDriver.Open(backFile) as IRasterDataProvider;
                if (backRaster.BandCount < ndviMinCH || backRaster.BandCount < ndviMaxCH)
                {
                    PrintInfo("背景库通道设置错误,大于实际数据通道数");
                    return(null);
                }
                RasterMaper bm = new RasterMaper(backRaster, new int[] { ndviMaxCH, ndviMinCH });
                rms.Add(bm);
                //输出文件准备(作为输入栅格并集处理)
                RasterIdentify ri = new RasterIdentify(ndviFile);
                ri.ProductIdentify    = _subProductDef.ProductDef.Identify;
                ri.SubProductIdentify = _identify;
                string outFileName = ri.ToWksFullFileName(".dat");
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <short, short> rfr = null;
                    rfr = new RasterProcessModel <short, short>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    //rfr.SetTemplateAOI(aoiTemplate);
                    rfr.RegisterCalcModel(
                        new RasterCalcHandler <short, short>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        if (rvInVistor[0].RasterBandsData[0] == null ||
                            rvInVistor[1].RasterBandsData[0] == null ||
                            rvInVistor[1].RasterBandsData[1] == null)
                        {
                            return;
                        }
                        int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        for (int index = 0; index < dataLength; index++)
                        {
                            short backMax = rvInVistor[1].RasterBandsData[0][index];
                            short backMin = rvInVistor[1].RasterBandsData[1][index];
                            int divi      = backMax - backMin;
                            if (divi == 0)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = 0;
                            }
                            else
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (short)((float)(rvInVistor[0].RasterBandsData[0][index] - rvInVistor[1].RasterBandsData[1][index]) / divi * resultZoom);
                            }
                        }
                    }));
                    //执行
                    rfr.Excute();
                    FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                    res.SetDispaly(false);
                    return(res);
                }
            }
            finally
            {
                foreach (RasterMaper rm in rms)
                {
                    rm.Raster.Dispose();
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// 计算雪水当量体积
        /// </summary>
        /// <param name="swefilename">输入文件名</param>
        /// <param name="sweVolFile">输出文件名</param>
        /// <returns></returns>
        private IFileExtractResult ComputeSnowSWEVOL(string swefilename, string sweVolFile)
        {
            List <RasterMaper>  rms               = null;
            IRasterDataProvider outRaster         = null;
            RasterProcessModel <float, float> rfr = null;

            try
            {
                rms = new List <RasterMaper>();
                IRasterDataProvider inRaster1 = GeoDataDriver.Open(swefilename) as IRasterDataProvider;
                //计算文件中每个像元的面积
                int         width   = inRaster1.Width;
                float       maxLat  = (float)inRaster1.CoordEnvelope.MaxY;
                float       res     = inRaster1.ResolutionX;
                int         row     = inRaster1.Height;
                RasterMaper fileIn1 = new RasterMaper(inRaster1, new int[] { 1 });
                rms.Add(fileIn1);
                outRaster = CreateOutRaster(sweVolFile, enumDataType.Float, rms.ToArray(), inRaster1.ResolutionX);
                RasterMaper   fileOut  = new RasterMaper(outRaster, new int[] { 1 });
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { fileOut };
                rfr = new RasterProcessModel <float, float>();
                rfr.SetRaster(fileIns, fileOuts);
                rfr.RegisterCalcModel(new RasterCalcHandler <float, float>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData[0] != null)
                    {
                        int dataLength    = rvInVistor[0].SizeY * rvInVistor[0].SizeX;
                        float[] swetmpVol = new float[dataLength];
                        for (int i = 0; i < dataLength; i++)
                        {
                            row        = (int)(i / rvInVistor[0].SizeX) + 1;
                            float area = ComputePixelArea(row, maxLat, res);
                            //面积由平方公里转换为平方米,雪水当量mm转换为m
                            //swetmpVol[i] = rvInVistor[0].RasterBandsData[0][i] * area * 1000000.0f * 0.001f;
                            if (rvInVistor[0].RasterBandsData[0][i] != -999.0f)
                            {
                                if (rvInVistor[0].RasterBandsData[0][i] < 5.0f && rvInVistor[0].RasterBandsData[0][i] > 0.00001f)
                                {
                                    rvInVistor[0].RasterBandsData[0][i] = 5.0f;
                                }
                                swetmpVol[i] = rvInVistor[0].RasterBandsData[0][i] * area * 1000.0f;
                            }
                            rvOutVistor[0].RasterBandsData[0][i] = swetmpVol[i];
                        }
                    }
                }));
                rfr.Excute();
                IFileExtractResult res1 = new FileExtractResult(_subProductDef.Identify, sweVolFile, true);
                res1.SetDispaly(false);
                return(res1);
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// 中值滤波
        /// </summary>
        /// <typeparam name="T">原始数据类型</typeparam>
        /// <param name="filename">原始数据名称</param>
        /// <param name="smoothwindow">平滑度:此处只能是5*5</param>
        /// <param name="savepath">另存文件名称</param>
        /// <returns></returns>
        private string ComputerMid <T>(string filename, Int16 smoothwindow, string savepath)
        {
            List <RasterMaper>        rms       = null;
            IRasterDataProvider       inRaster1 = null;
            IRasterDataProvider       outRaster = null;
            RasterProcessModel <T, T> rfr       = null;

            RasterMaper[] fileIns           = null;
            RasterMaper[] fileOuts          = null;
            RasterMaper   fileOut           = null;
            string        midFilterFileName = savepath;

            if (File.Exists(midFilterFileName))
            {
                return(midFilterFileName);
            }
            try
            {
                rms       = new List <RasterMaper>();
                inRaster1 = GeoDataDriver.Open(filename) as IRasterDataProvider;
                RasterMaper fileIn1 = new RasterMaper(inRaster1, new int[] { 1 });
                rms.Add(fileIn1);
                if (string.IsNullOrEmpty(midFilterFileName))
                {
                    return(null);
                }
                else
                {
                    outRaster = CreateOutRaster(midFilterFileName, inRaster1.DataType, rms.ToArray(), inRaster1.ResolutionX);
                }
                fileOut  = new RasterMaper(outRaster, new int[] { 1 });
                fileIns  = rms.ToArray();
                fileOuts = new RasterMaper[] { fileOut };
                rfr      = new RasterProcessModel <T, T>();
                rfr.SetRaster(fileIns, fileOuts);
                rfr.RegisterCalcModel(new RasterCalcHandler <T, T>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData[0] != null)
                    {
                        int dataLength = rvInVistor[0].SizeY * rvInVistor[0].SizeX;
                        T[] temp       = new T[smoothwindow * smoothwindow];
                        int col        = rvInVistor[0].SizeX;
                        if (smoothwindow == 5)
                        {
                            for (int i = 0; i < dataLength; i++)
                            {
                                if (i < 2 * col || i % col == 0 || (i - 1) % col == 0 || (i + 1) % col == 0 || (i + 2) % col == 0 || i > dataLength - 2 * col)
                                {
                                    if (rvInVistor[0].RasterBandsData[0][i].Equals(ConvertFloatToT <T>(0f)))
                                    {
                                        rvOutVistor[0].RasterBandsData[0][i] = ConvertFloatToT <T>(0f);
                                    }
                                    else
                                    {
                                        rvOutVistor[0].RasterBandsData[0][i] = rvInVistor[0].RasterBandsData[0][i];
                                    }
                                }
                                else
                                {
                                    if (rvInVistor[0].RasterBandsData[0][i].Equals(ConvertFloatToT <T>(0f)))
                                    {
                                        rvOutVistor[0].RasterBandsData[0][i] = ConvertFloatToT <T>(0f);
                                    }
                                    else
                                    {
                                        temp[0]   = rvInVistor[0].RasterBandsData[0][i - 2 * col - 2];
                                        temp[1]   = rvInVistor[0].RasterBandsData[0][i - 2 * col - 1];
                                        temp[2]   = rvInVistor[0].RasterBandsData[0][i - 2 * col];
                                        temp[3]   = rvInVistor[0].RasterBandsData[0][i - 2 * col + 1];
                                        temp[4]   = rvInVistor[0].RasterBandsData[0][i - 2 * col + 2];
                                        temp[5]   = rvInVistor[0].RasterBandsData[0][i - col - 2];
                                        temp[6]   = rvInVistor[0].RasterBandsData[0][i - col - 1];
                                        temp[7]   = rvInVistor[0].RasterBandsData[0][i - col];
                                        temp[8]   = rvInVistor[0].RasterBandsData[0][i - col + 1];
                                        temp[9]   = rvInVistor[0].RasterBandsData[0][i - col + 2];
                                        temp[10]  = rvInVistor[0].RasterBandsData[0][i - 2];
                                        temp[11]  = rvInVistor[0].RasterBandsData[0][i - 1];
                                        temp[12]  = rvInVistor[0].RasterBandsData[0][i];
                                        temp[13]  = rvInVistor[0].RasterBandsData[0][i + 1];
                                        temp[14]  = rvInVistor[0].RasterBandsData[0][i + 2];
                                        temp[15]  = rvInVistor[0].RasterBandsData[0][i + col - 2];
                                        temp[16]  = rvInVistor[0].RasterBandsData[0][i + col - 1];
                                        temp[17]  = rvInVistor[0].RasterBandsData[0][i + col];
                                        temp[18]  = rvInVistor[0].RasterBandsData[0][i + col + 1];
                                        temp[19]  = rvInVistor[0].RasterBandsData[0][i + col + 2];
                                        temp[20]  = rvInVistor[0].RasterBandsData[0][i + 2 * col - 2];
                                        temp[21]  = rvInVistor[0].RasterBandsData[0][i + 2 * col - 1];
                                        temp[22]  = rvInVistor[0].RasterBandsData[0][i + 2 * col];
                                        temp[23]  = rvInVistor[0].RasterBandsData[0][i + 2 * col + 1];
                                        temp[24]  = rvInVistor[0].RasterBandsData[0][i + 2 * col + 2];
                                        int count = 0;
                                        for (int n = 0; n < 25; n++)
                                        {
                                            if (temp[n].Equals(ConvertFloatToT <T>(0f)))
                                            {
                                                count++;
                                            }
                                        }
                                        Array.Sort(temp);
                                        if (count >= 12)
                                        {
                                            rvOutVistor[0].RasterBandsData[0][i] = rvInVistor[0].RasterBandsData[0][i];
                                        }
                                        else
                                        {
                                            rvOutVistor[0].RasterBandsData[0][i] = temp[temp.Length / 2];
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < dataLength; i++)
                            {
                                if (i < col || i % col == 0 || (i + 1) % col == 0 || i > dataLength - col)
                                {
                                    rvOutVistor[0].RasterBandsData[0][i] = rvInVistor[0].RasterBandsData[0][i];
                                }
                                else
                                {
                                    if (rvInVistor[0].RasterBandsData[0][i].Equals(ConvertFloatToT <T>(0f)))
                                    {
                                        rvOutVistor[0].RasterBandsData[0][i] = ConvertFloatToT <T>(0f);
                                    }
                                    else
                                    {
                                        temp[0]   = rvInVistor[0].RasterBandsData[0][i - col - 1];
                                        temp[1]   = rvInVistor[0].RasterBandsData[0][i - col];
                                        temp[2]   = rvInVistor[0].RasterBandsData[0][i - col + 1];
                                        temp[3]   = rvInVistor[0].RasterBandsData[0][i - 1];
                                        temp[4]   = rvInVistor[0].RasterBandsData[0][i];
                                        temp[5]   = rvInVistor[0].RasterBandsData[0][i + 1];
                                        temp[6]   = rvInVistor[0].RasterBandsData[0][i + col - 1];
                                        temp[7]   = rvInVistor[0].RasterBandsData[0][i + col];
                                        temp[8]   = rvInVistor[0].RasterBandsData[0][i + col + 1];
                                        int count = 0;
                                        for (int n = 0; n < 9; n++)
                                        {
                                            if (temp[n].Equals(ConvertFloatToT <T>(0f)))
                                            {
                                                count++;
                                            }
                                        }
                                        Array.Sort(temp);
                                        if (count >= 4)
                                        {
                                            rvOutVistor[0].RasterBandsData[0][i] = rvInVistor[0].RasterBandsData[0][i];
                                        }
                                        else
                                        {
                                            rvOutVistor[0].RasterBandsData[0][i] = temp[temp.Length / 2];
                                        }
                                    }
                                }
                            }
                        }
                    }
                }));
                rfr.Excute();
                return(midFilterFileName);
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                    fileOut = null;

                    fileOuts = null;
                }

                if (inRaster1 != null)
                {
                    inRaster1.Dispose();
                }

                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// 双线性插值方法提高原数据文件分辨率
        /// f(i+u,j+v)=(1-u)(1-v)*f(i,j) + (1-v)u*f(i,j+1) + v(1-u)*f(i+1,j) + uv*f(i+1,j+1)
        /// </summary>
        /// <typeparam name="T">原始文件数据类型</typeparam>
        /// <param name="srcFilename">原文件</param>
        /// <param name="zoom">分辨率提高比例如0.1度到0.01度,zoom = 10</param>
        /// <param name="savepathname">另存结果文件名称</param>
        /// <returns></returns>
        private string Bilinear <T>(string srcFilename, Int16 zoom, string savepathname)
        {
            List <RasterMaper>  rms       = new List <RasterMaper>();
            IRasterDataProvider outRaster = null;
            IRasterDataProvider inRaster1 = GeoDataDriver.Open(srcFilename) as IRasterDataProvider;
            RasterMaper         fileIn1   = new RasterMaper(inRaster1, new int[] { 1 });

            rms.Add(fileIn1);
            string fileBilname = savepathname;

            outRaster = CreateOutRaster(fileBilname, inRaster1.DataType, rms.ToArray(), inRaster1.ResolutionX / zoom, zoom);
            T[]         inRasterBuffer = new T[inRaster1.Width * inRaster1.Height];
            IRasterBand bandinRaster1  = inRaster1.GetRasterBand(1);

            T[] sd     = new T[inRaster1.Width * inRaster1.Height];
            T[] sdSnow = new T[outRaster.Width * outRaster.Height];//输出数组
            unsafe
            {
                GCHandle h   = GCHandle.Alloc(inRasterBuffer, GCHandleType.Pinned);
                IntPtr   ptr = h.AddrOfPinnedObject();

                bandinRaster1.Read(0, 0, inRaster1.Width, inRaster1.Height, ptr, inRaster1.DataType, inRaster1.Width, inRaster1.Height);
                for (int j = 0; j < inRaster1.Width * inRaster1.Height; j++)
                {
                    sd[j] = inRasterBuffer[j];
                }
            }
            Int32[] index = new Int32[zoom * zoom];
            try
            {
                for (int i = 0; i < inRaster1.Width * inRaster1.Height; i++)
                {
                    if ((i + 1) % inRaster1.Width == 0 || i % inRaster1.Width == 0 || i >= inRaster1.Width * inRaster1.Height - inRaster1.Width || i < inRaster1.Width) //插值后的高分格子落在原低分格子的最后一列或第一列,或最后一行,最后一列
                    {
                        for (int row = 0; row < zoom; row++)
                        {
                            for (int col = 0; col < zoom; col++)
                            {
                                index[col + row * zoom] = (i / inRaster1.Width * zoom * outRaster.Width + i % inRaster1.Width * zoom) + (row * outRaster.Width) + col;
                                //sdSnow[index[col + row * zoom]] = 0.000001f;
                                //sdSnow[index[col + row * zoom]] = -999.0f;
                                sdSnow[index[col + row * zoom]] = sd[i];
                            }
                        }
                    }
                    else
                    {
                        for (int row = 0; row < zoom; row++)
                        {
                            for (int col = 0; col < zoom; col++)
                            {
                                index[col + row * zoom] = (i / inRaster1.Width * zoom * outRaster.Width + i % inRaster1.Width * zoom) + (row * outRaster.Width) + col;
                                //(2)通过u,v所处的象限
                                int xCenter = zoom / 2;
                                int yCenter = zoom / 2;
                                if (col < xCenter && row < yCenter)                   //第二象限 高分格子所在象元f(i,j) 其余三个象元分别是f(i,j-1),f(i-1,j),f(i-1,j-1)
                                {
                                    float u      = 0.5f + (float)(col * 1.0f / zoom); //列
                                    float v      = 0.5f + (float)(row * 1.0f / zoom); //行
                                    float result = (1 - u) * (1 - v) * ConvertTtoFloat <T>(sd[i - inRaster1.Width - 1]) + (1 - v) * u * ConvertTtoFloat <T>(sd[i - inRaster1.Width]) + v * (1 - u) * ConvertTtoFloat <T>(sd[i - 1]) + u * v * ConvertTtoFloat <T>(sd[i]);
                                    sdSnow[index[col + row * zoom]] = ConvertFloatToT <T>(result);
                                }
                                if (col >= xCenter && row < yCenter)                  //第一象限 高分格子所在象元f(i,j) 其余三个象元分别是f(i-1,j),f(i-1,j+1),f(i,j+1)
                                {
                                    float u      = (float)(col * 1.0f / zoom) - 0.5f; //列  横向
                                    float v      = (float)(row * 1.0f / zoom) + 0.5f; //行 纵
                                    float result = (1 - u) * (1 - v) * ConvertTtoFloat <T>(sd[i - inRaster1.Width]) + (1 - v) * u * ConvertTtoFloat <T>(sd[i - inRaster1.Width + 1]) + v * (1 - u) * ConvertTtoFloat <T>(sd[i]) + u * v * ConvertTtoFloat <T>(sd[i + 1]);
                                    sdSnow[index[col + row * zoom]] = ConvertFloatToT <T>(result);
                                }
                                if (col < xCenter && row >= yCenter)                  //第三象限 高分格子所在象元f(i,j) 其余三个象元分别是f(i,j-1),f(i+1,j-1),f(i+1,j)
                                {
                                    float u      = 0.5f + (float)(col * 1.0f / zoom); //列
                                    float v      = (float)(row * 1.0f / zoom) - 0.5f; //行
                                    float result = (1 - u) * (1 - v) * ConvertTtoFloat <T>(sd[i - 1]) + (1 - v) * u * ConvertTtoFloat <T>(sd[i]) + v * (1 - u) * ConvertTtoFloat <T>(sd[i + inRaster1.Width - 1]) + v * u * ConvertTtoFloat <T>(sd[i + inRaster1.Width]);
                                    sdSnow[index[col + row * zoom]] = ConvertFloatToT <T>(result);
                                }
                                if (col >= xCenter && row >= yCenter)                 //第四象限 高分格子所在象元f(i,j) 其余三个象元分别是f(i,j+1),f(i+1,j),f(i+1,j+1)
                                {
                                    float u      = (float)(col * 1.0f / zoom) - 0.5f; //列
                                    float v      = (float)(row * 1.0f / zoom) - 0.5f; //行
                                    float result = (1 - u) * (1 - v) * ConvertTtoFloat <T>(sd[i]) + (1 - v) * u * ConvertTtoFloat <T>(sd[i + 1]) + v * (1 - u) * ConvertTtoFloat <T>(sd[i + inRaster1.Width]) + u * v * ConvertTtoFloat <T>(sd[i + inRaster1.Width + 1]);
                                    sdSnow[index[col + row * zoom]] = ConvertFloatToT <T>(result);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //PrintInfo(ex.Message);
            }
            try
            {
                unsafe
                {
                    GCHandle h = GCHandle.Alloc(sdSnow, GCHandleType.Pinned);
                    try
                    {
                        IntPtr      sdSnowPtr     = h.AddrOfPinnedObject();
                        IRasterBand bandoutRaster = outRaster.GetRasterBand(1);
                        bandoutRaster.Write(0, 0, outRaster.Width, outRaster.Height, sdSnowPtr, outRaster.DataType, outRaster.Width, outRaster.Height);
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        h.Free();
                    }
                }
                //IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, sdBilinearfilename, true);
                return(fileBilname);
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (inRaster1 != null)
                {
                    inRaster1.Dispose();
                    fileIn1.Raster.Dispose();
                }
                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
コード例 #16
0
        public static NdviList[] NDVIHistograms(TVDIUCArgs ucArgs)
        {
            string error = string.Empty;

            if (!CheckHistograms(ucArgs, ref error))
            {
                return(null);
            }
            string ndviFile = ucArgs.NDVIFile;
            int    ndviZoom = ucArgs.TVDIParas.NdviFile.Zoom;
            int    ndviMin  = ucArgs.TVDIParas.NdviFile.Min;
            int    ndviMax  = ucArgs.TVDIParas.NdviFile.Max;
            int    ndviBand = ucArgs.TVDIParas.NdviFile.Band;

            string lstFile = ucArgs.ECLstFile;
            int    lstZoom = ucArgs.TVDIParas.LstFile.Zoom;
            int    lstMin  = ucArgs.TVDIParas.LstFile.Min;
            int    lstMax  = ucArgs.TVDIParas.LstFile.Max;
            IRasterDataProvider ndviPrd = null;
            IRasterDataProvider lstPrd  = null;

            try
            {
                List <RasterMaper> rms = new List <RasterMaper>();
                ndviPrd = RasterDataDriver.Open(ndviFile) as IRasterDataProvider;
                if (ndviPrd.BandCount < ndviBand)
                {
                    return(null);
                }
                RasterMaper ndviRm = new RasterMaper(ndviPrd, new int[] { ndviBand });
                rms.Add(ndviRm);

                lstPrd = RasterDataDriver.Open(lstFile) as IRasterDataProvider;
                if (lstPrd.BandCount < 1)
                {
                    return(null);
                }
                RasterMaper lstRm = new RasterMaper(lstPrd, new int[] { 1 });
                rms.Add(lstRm);

                string outFileName = CreatOutFile();
                Int16  value0      = 0;
                Int16  value1      = 0;
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    int           start = -1000, end = 1000;
                    int           statLength = end - start + 1;
                    NdviList[]    results    = new NdviList[statLength];
                    RasterMaper[] fileIns    = rms.ToArray();
                    RasterMaper[] fileOuts   = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    RasterProcessModel <Int16, Int16> rfr = new RasterProcessModel <Int16, Int16>();
                    rfr.SetRaster(fileIns, fileOuts);
                    TVDIParaClass tvdiP = ucArgs.TVDIParas;
                    rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        if (rvInVistor[0].RasterBandsData == null || rvInVistor[1].RasterBandsData == null ||
                            rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1].RasterBandsData[0] == null)
                        {
                            return;
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            value0 = rvInVistor[0].RasterBandsData[0][index];
                            value1 = rvInVistor[1].RasterBandsData[0][index];
                            if (value0 < -1000 || value0 > 1000)
                            {
                                continue;
                            }
                            if (results[value0 - (-1000)] == null)
                            {
                                results[value0 - (-1000)] = new NdviList(value0);
                            }
                            results[value0 - (-1000)].Lst.Add(value1);
                        }
                    }));
                    rfr.Excute();
                    return(results);
                }
            }
            finally
            {
                if (ndviPrd != null)
                {
                    ndviPrd.Dispose();
                }
                if (lstPrd != null)
                {
                    lstPrd.Dispose();
                }
            }
        }
コード例 #17
0
ファイル: MosaicProcess.cs プロジェクト: windygu/hispeed
        /// <summary>
        /// 地理数据拼接:地理坐标,投影坐标
        /// 拼接输出ldf
        /// 支持按高度角数据拼接,高度角数据为后缀为".SolarZenith.ldf"的附加文件,值为扩大了100倍的short类型的高度角值。
        /// 本拼接程序会判断是否有高度角数据:“.SolarZenith.ldf”,如果有,则拼接时候会依据高度角的大小关系执行是否覆盖操作,如果没有,则按照有无数据执行拼接。
        /// </summary>
        /// <param name="rasterFiles"></param>
        /// <param name="outRasterFile"></param>
        /// <param name="geoHeader"></param>
        /// <param name="bandMaps"></param>
        /// <param name="progress"></param>
        public void Mosaic(string[] rasterFiles, string outRasterFile, GeoInfo geoHeader, string[] bandMaps, Action <int, string> progress)
        {
            int[] bandMap = null;
            if (!GetBandMap(bandMaps, out bandMap))
            {
                if (progress != null)
                {
                    progress(0, "输入参数错误,参数[要拼接的波段]不正确");
                }
                return;
            }
            if (bandMap == null || bandMap.Length == 0)
            {
                if (progress != null)
                {
                    progress(0, "输入参数错误,[要拼接的波段]为空或不正确");
                }
                return;
            }
            int bandCount = bandMap.Length;
            ISpatialReference spatialRef = TryFindSpatialRef(rasterFiles);

            using (IRasterDataProvider outraster = CreateMosaicRaster(outRasterFile, geoHeader, bandCount, spatialRef))
            {
                string filename                       = null;
                IRasterDataProvider raster            = null;
                string solarZenithFilename            = null;
                IRasterDataProvider solarZenithRaster = null;

                RasterMaper         outSolarZenithMap   = null;// new RasterMaper(solarZenithRaster, new int[] { 1 });
                string              outSolarZenithFile  = Path.ChangeExtension(outRasterFile, ".SolarZenith.ldf");
                IRasterDataProvider outSolarZenithRster = null;
                try
                {
                    for (int f = 0; f < rasterFiles.Length; f++)
                    {
                        filename            = rasterFiles[f];
                        solarZenithFilename = Path.ChangeExtension(filename, ".SolarZenith.ldf");
                        if (progress != null)
                        {
                            progress((int)((f + 1) * 100f / rasterFiles.Length), string.Format("{0}/{1}", f + 1, rasterFiles.Length));
                        }
                        try
                        {
                            raster = GeoDataDriver.Open(filename) as IRasterDataProvider;
                            if (raster == null)
                            {
                                continue;
                            }
                            //if (raster is ILdfDataProvider)
                            //{
                            //    Ldf1Header header = (raster as ILdfDataProvider).Header as Ldf1Header;
                            //    if (!header.IsDay)
                            //    {
                            //        Console.WriteLine("跳过晚上数据" + Path.GetFileName(filename));
                            //        continue;
                            //    }
                            //}
                            if (File.Exists(outSolarZenithFile))
                            {
                                outSolarZenithRster = GeoDataDriver.Open(outSolarZenithFile, enumDataProviderAccess.Update, null) as IRasterDataProvider;
                                outSolarZenithMap   = new RasterMaper(outSolarZenithRster, new int[] { 1 });
                            }

                            RasterMaper rmSz = null;
                            if (File.Exists(solarZenithFilename))
                            {
                                solarZenithRaster = GeoDataDriver.Open(solarZenithFilename) as IRasterDataProvider;
                                rmSz = new RasterMaper(solarZenithRaster, new int[] { 1 });
                            }
                            RasterMaper rmin  = new RasterMaper(raster, bandMap);
                            RasterMaper rmout = new RasterMaper(outraster, bandMap);
                            RasterProcessModel <short, short> rp = new RasterProcessModel <short, short>();
                            RasterMaper[] rmIns, rmOuts;
                            if (rmSz != null)
                            {
                                rmIns = new RasterMaper[] { rmin, rmSz }
                            }
                            ;
                            else
                            {
                                rmIns = new RasterMaper[] { rmin }
                            };
                            if (outSolarZenithMap != null)
                            {
                                rmOuts = new RasterMaper[] { rmout, outSolarZenithMap }
                            }
                            ;
                            else
                            {
                                rmOuts = new RasterMaper[] { rmout }
                            };
                            rp.SetRaster(rmIns, rmOuts);
                            rp.RegisterCalcModel(new RasterCalcHandlerFun <short, short>((rasterVistor, target, map) =>
                            {
                                if (rasterVistor[0] == null || rasterVistor[0].RasterBandsData.Length == 0)
                                {
                                    return(false);
                                }
                                if (target[0] == null || target[0].RasterBandsData[0].Length == 0)
                                {
                                    return(false);
                                }
                                if (rasterVistor[0].RasterBandsData[0] == null)
                                {
                                    return(false);
                                }
                                //目标角度数据存在,源角度数据不存在,不做拼接
                                if (target.Length != 1 && rasterVistor.Length == 1)
                                {
                                    return(false);
                                }
                                bool isUpdate = false;
                                //不使用天顶角数据,补数据
                                if (target.Length == 1 || rasterVistor.Length == 1)
                                {
                                    for (int i = 0; i < target[0].RasterBandsData[0].Length; i++)
                                    {
                                        if (rasterVistor[0].RasterBandsData[0][i] == 0)//空值
                                        {
                                            continue;
                                        }
                                        if (target[0].RasterBandsData[0][i] == 0)
                                        {
                                            isUpdate = true;
                                            for (int b = 0; b < bandCount; b++)
                                            {
                                                target[0].RasterBandsData[b][i] = rasterVistor[0].RasterBandsData[b][i];
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < target[0].RasterBandsData[0].Length; i++)
                                    {
                                        if (rasterVistor[0].RasterBandsData[0][i] == 0)//空值
                                        {
                                            continue;
                                        }

                                        /*
                                         * 太阳高度表示昼夜状态
                                         * 在晨昏线上的各地太阳高度为0 °,表示正经历昼夜更替;
                                         * 在昼半球上的各地太阳高度大于0°,表示白昼;
                                         * 在夜半球上的各地太阳高度小于0°,表示黑夜。
                                         * 日出、日落时,太阳高度为0
                                         * 即:
                                         * 0°附近在日落或日出
                                         * -90°和0°之间在晚上
                                         * 上午太阳高度逐渐增大,最大时为太阳上中天,即是正午,午后太阳高度又逐渐缩小。
                                         */
                                        //(高度角 = 90 - 天顶角)

                                        //高度角有效范围:
                                        //这里读取的是SolarZenith太阳天顶,有效范围0-180。
                                        //天顶角0-90为白天,小值为接近中午
                                        if (rasterVistor.Length == 1 || rasterVistor[1] == null || rasterVistor[1].RasterBandsData[0] == null ||
                                            target.Length == 1 || target[1] == null)
                                        {
                                            if (target[0].RasterBandsData[0][i] == 0)//如果没有角度数据,则采取补数据的方式(即不覆盖已有数据)
                                            {
                                                isUpdate = true;
                                                for (int b = 0; b < bandCount; b++)//拼接所有通道数据
                                                {
                                                    target[0].RasterBandsData[b][i] = rasterVistor[0].RasterBandsData[b][i];
                                                }
                                            }
                                        }
                                        else if (rasterVistor[1].RasterBandsData[0][i] > 9000 || rasterVistor[1].RasterBandsData[0][i] < 0)//原高度角为夜晚或者不合理
                                        {
                                            continue;
                                        }
                                        else if (target[1].RasterBandsData[0][i] == 0)
                                        {
                                            isUpdate = true;
                                            for (int b = 0; b < bandCount; b++)
                                            {
                                                target[0].RasterBandsData[b][i] = rasterVistor[0].RasterBandsData[b][i];
                                            }
                                            //更新目标高度角数据
                                            target[1].RasterBandsData[0][i] = rasterVistor[1].RasterBandsData[0][i];
                                        }
                                        else if (rasterVistor[1].RasterBandsData[0][i] < target[1].RasterBandsData[0][i])//取高度角小的
                                        {
                                            isUpdate = true;
                                            for (int b = 0; b < bandCount; b++)
                                            {
                                                target[0].RasterBandsData[b][i] = rasterVistor[0].RasterBandsData[b][i];
                                            }
                                            //更新目标高度角数据
                                            target[1].RasterBandsData[0][i] = rasterVistor[1].RasterBandsData[0][i];
                                        }
                                    }
                                }
                                if (isUpdate)
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                                                                                         ));
                            int rowCount = rp.CalcRowCount();
                            rp.Excute(0, rowCount);
                        }
                        finally
                        {
                            if (raster != null)
                            {
                                raster.Dispose();
                                raster = null;
                            }
                            if (outSolarZenithRster != null)
                            {
                                outSolarZenithRster.Dispose();
                                outSolarZenithRster = null;
                            }
                        }
                    }
                }
                finally
                {
                    if (outSolarZenithRster != null)
                    {
                        outSolarZenithRster.Dispose();
                        outSolarZenithRster = null;
                    }
                }
            }
        }
コード例 #18
0
        /// <summary>
        /// 读取时候,会按照srcs的第一个数据类型来读取数据
        /// </summary>
        /// <param name="srcs"></param>
        /// <param name="dst"></param>
        /// <returns></returns>
        public bool Mosaic(IRasterDataProvider[] srcs, IRasterDataProvider dst)
        {
            //Stopwatch sw = new Stopwatch();
            //sw.Start();
            try
            {
                int           bandCount = srcs[0].BandCount;
                RasterMaper[] fileIns   = new RasterMaper[srcs.Length];
                int[]         bandMap   = null;
                for (int i = 0; i < srcs.Length; i++)
                {
                    bandMap = new int[bandCount];
                    for (int b = 0; b < bandCount; b++)
                    {
                        bandMap[b] = b + 1;
                    }
                    fileIns[i] = new RasterMaper(srcs[i], bandMap);
                }
                RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(dst, bandMap) };
                enumDataType  datatype = srcs[0].DataType;
                switch (datatype)
                {
                case enumDataType.Byte:
                    return(Mosaic <byte>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Double:
                    return(Mosaic <double>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Float:
                    return(Mosaic <float>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Int16:
                    return(Mosaic <Int16>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Int32:
                    return(Mosaic <Int32>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Int64:
                    return(Mosaic <Int64>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.UInt16:
                    return(Mosaic <UInt16>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.UInt32:
                    return(Mosaic <UInt32>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.UInt64:
                    return(Mosaic <UInt64>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Unknow:
                    break;

                case enumDataType.Atypism:
                    break;

                case enumDataType.Bits:
                    break;

                default:
                    break;
                }
                return(true);
            }
            catch (Exception ex)
            {
                LogFactory.WriteLine(_sensor + "MosaicError", dst.fileName + "," + ex.Message);
                return(false);
            }
            finally
            {
                //sw.Stop();
                //LogFactory.WriteLine("拼接时间", sw.ElapsedMilliseconds + "秒");
            }
        }
コード例 #19
0
        /// <summary>
        /// 将源拼接至目标
        /// 目前默认实现为源和目标数据类型一致
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        /// <returns></returns>
        public bool Mosaic(IRasterDataProvider src, IRasterDataProvider dst)
        {
            //Stopwatch sw = new Stopwatch();
            //sw.Start();
            try
            {
                RasterMaper[] fileIns  = new RasterMaper[] { new RasterMaper(src, new int[] { 1 }) };
                RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(dst, new int[] { 1 }) };
                enumDataType  datatype = src.DataType;
                switch (datatype)
                {
                case enumDataType.Byte:
                    return(Mosaic <byte>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Double:
                    return(Mosaic <double>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Float:
                    return(Mosaic <float>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Int16:
                    return(Mosaic <Int16>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Int32:
                    return(Mosaic <Int32>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Int64:
                    return(Mosaic <Int64>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.UInt16:
                    return(Mosaic <UInt16>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.UInt32:
                    return(Mosaic <UInt32>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.UInt64:
                    return(Mosaic <UInt64>(fileIns, fileOuts, (a, b) => { return a == b; }));

                case enumDataType.Unknow:
                    break;

                case enumDataType.Atypism:
                    break;

                case enumDataType.Bits:
                    break;

                default:
                    break;
                }
                return(true);
            }
            catch (Exception ex)
            {
                LogFactory.WriteLine(_sensor + "MosaicError", src + "," + ex.Message);
                return(false);
            }
            finally
            {
                //sw.Stop();
                //LogFactory.WriteLine("拼接时间", sw.ElapsedMilliseconds + "秒");
            }
        }
コード例 #20
0
ファイル: SubProductVSWIDRT.cs プロジェクト: windygu/hispeed
        /// <summary>
        /// 算法主要计算过程
        /// </summary>
        /// <param name="progressTracker"></param>
        /// <returns>导出文件结果句柄</returns>
        private IExtractResult TNDVIAlgorithm_VSWI(Action <int, string> progressTracker)
        {
            #region 参数
            int NDVIBandCH = (int)_argumentProvider.GetArg("NDVIBand");
            if (NDVIBandCH == -1 || _argumentProvider.GetArg("NDVIFile") == null)
            {
                PrintInfo("NDVI生产所用文件或通道未设置完全,请检查!");
                return(null);
            }
            //NDVI文件
            string[] ndviFileNames = GetStringArray("NDVIFile");

            int TSBandCH = (int)_argumentProvider.GetArg("TSBand");
            if (TSBandCH == -1 || _argumentProvider.GetArg("TSFile") == null)
            {
                PrintInfo("TS生产所用文件或通道未设置完全,请检查!");
                return(null);
            }
            //地表温度文件
            string[] tsFileNames = GetStringArray("TSFile");
            if (ndviFileNames.Length <= 0 || tsFileNames.Length <= 0)
            {
                PrintInfo("未选择有效输入文件!");
                return(null);
            }
            if (!File.Exists(ndviFileNames[0]))
            {
                PrintInfo("NDVI文件不存在!");
                return(null);
            }
            if (!File.Exists(tsFileNames[0]))
            {
                PrintInfo("TS地表温度数据不存在!");
                return(null);
            }
            //NDVI缩放倍数
            double NDVIZoom = (double)_argumentProvider.GetArg("NDVIBand_Zoom");
            //地表温度缩放倍数
            double TSZoom = (double)_argumentProvider.GetArg("TSBand_Zoom");
            //生成结果放大倍数
            double  BandZoom    = (double)_argumentProvider.GetArg("BandZoom");
            Int16[] CloudValues = GetNanValues("CloudyValue");
            Int16   defCloudy   = (Int16)_argumentProvider.GetArg("defCloudy");

            Int16[] WaterValues = GetNanValues("WaterValue");
            Int16   defWater    = (Int16)_argumentProvider.GetArg("defCloudy");

            Int16[] NullValues = GetNanValues("NullValue");
            Int16   defNull    = (Int16)_argumentProvider.GetArg("defNullValue");
            #endregion

            //输入文件准备
            List <RasterMaper>  rasterInputMaps = new List <RasterMaper>();
            IRasterDataProvider ndviPrd         = null;
            IRasterDataProvider tsPrd           = null;
            try
            {
                ndviPrd = RasterDataDriver.Open(ndviFileNames[0]) as IRasterDataProvider;
                if (ndviPrd.BandCount < NDVIBandCH)
                {
                    PrintInfo("请选择正确的NDVI数据进行植被供水指数计算。");
                    return(null);
                }
                RasterMaper rmNdvi = new RasterMaper(ndviPrd, new int[] { NDVIBandCH });
                rasterInputMaps.Add(rmNdvi);
                tsPrd = RasterDataDriver.Open(tsFileNames[0]) as IRasterDataProvider;
                if (tsPrd.BandCount < NDVIBandCH)
                {
                    PrintInfo("请选择正确的Ts地表温度数据进行植被供水指数计算。");
                    return(null);
                }
                RasterMaper rmTs = new RasterMaper(tsPrd, new int[] { NDVIBandCH });
                rasterInputMaps.Add(rmTs);
                //输出文件准备(作为输入栅格并集处理)
                string outFileName            = GetFileName(tsFileNames, _subProductDef.ProductDef.Identify, _identify, ".dat", null);
                IRasterDataProvider outRaster = null;
                try
                {
                    outRaster = CreateOutRaster(outFileName, rasterInputMaps.ToArray());
                    //栅格数据映射
                    RasterMaper[] fileIns = rasterInputMaps.ToArray();
                    RasterMaper[] fileOuts;
                    fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <Int16, Int16> rfr = new RasterProcessModel <Int16, Int16>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        if (rvInVistor[0].RasterBandsData == null || rvInVistor[1].RasterBandsData == null ||
                            rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1].RasterBandsData[0] == null)
                        {
                            return;
                        }
                        int dataLength     = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        Int16[] ndviValues = rvInVistor[0].RasterBandsData[0];
                        Int16[] tValues    = rvInVistor[1].RasterBandsData[0];
                        for (int index = 0; index < dataLength; index++)
                        {
                            Int16 refValue = 0;
                            //检验输入的云水值
                            if (GetAndCheckRefValue(ndviValues[index], CloudValues, defCloudy, WaterValues, defWater, NullValues, defNull, out refValue) ||
                                GetAndCheckRefValue(tValues[index], CloudValues, defCloudy, WaterValues, defWater, out refValue))
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = refValue;
                            }
                            else if (ndviValues[index] == 0)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = defNull;
                            }
                            else
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (Int16)((float)(tValues[index] * NDVIZoom * BandZoom / ndviValues[index] / TSZoom));
                            }
                        }
                    }));
                    //执行
                    rfr.Excute();
                }
                finally
                {
                    if (outRaster != null)
                    {
                        outRaster.Dispose();
                    }
                }
                FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                res.SetDispaly(false);

                return(res);
            }
            finally
            {
                if (ndviPrd != null)
                {
                    ndviPrd.Dispose();
                }
            }
        }
コード例 #21
0
        private IExtractResult HFIIAlgorithmCompute(Action <int, string> progressTracker)
        {
            MemPixelFeatureMapper <UInt16> resultTemp = null;
            int    LstBandCH   = (int)_argumentProvider.GetArg("LstBand");
            double LstBandZoom = (double)_argumentProvider.GetArg("LstBand_Zoom");
            double HFIIZoom    = (double)_argumentProvider.GetArg("HFIIZoom");
            UInt16 defCloudy   = (UInt16)_argumentProvider.GetArg("defCloudy");
            UInt16 defWater    = (UInt16)_argumentProvider.GetArg("defWater");
            UInt16 minCount    = (UInt16)(_argumentProvider.GetArg("minCount"));

            UInt16[] nanValues   = GetNanValues("CloudyValue");
            UInt16[] waterValues = GetNanValues("WaterValue");
            float    LSTMin      = (float)((float.Parse(_argumentProvider.GetArg("VaildMin").ToString()) + 273) * LstBandZoom);
            float    LSTMax      = (float)((float.Parse(_argumentProvider.GetArg("VaildMax").ToString()) + 273) * LstBandZoom);
            string   lstFile     = GetStringArg("LSTFile");

            if (string.IsNullOrEmpty(lstFile) || !File.Exists(lstFile))
            {
                PrintInfo("获取数据失败,没有设定地表高温数据或数据不存在。");
                return(null);
            }
            Dictionary <UInt16, int> vaildLstList = new Dictionary <UInt16, int>();
            IRasterDataProvider      currPrd      = GeoDataDriver.Open(lstFile) as IRasterDataProvider;
            IRasterDataProvider      cloudPrd     = null;
            ArgumentProvider         ap           = new ArgumentProvider(currPrd, null);

            resultTemp = new MemPixelFeatureMapper <UInt16>("HFII", 1000, new Size(currPrd.Width, currPrd.Height), currPrd.CoordEnvelope, currPrd.SpatialRef);
            RasterPixelsVisitor <UInt16> rpVisitor = null;

            string cloudFile = GetStringArg("CloudFile");

            if (progressTracker != null)
            {
                progressTracker.Invoke(5, "开始计算热效应强度指数,请稍候...");
            }
            try
            {
                if (!string.IsNullOrEmpty(cloudFile) && File.Exists(cloudFile))
                {
                    if (progressTracker != null)
                    {
                        progressTracker.Invoke(15, "开始提取云信息,请稍候...");
                    }
                    cloudPrd = GeoDataDriver.Open(cloudFile) as IRasterDataProvider;
                    if (cloudPrd == null)
                    {
                        PrintInfo("请选择正确的云结果.");
                        return(null);
                    }
                    List <RasterMaper> rms = new List <RasterMaper>();
                    RasterMaper        brm = new RasterMaper(cloudPrd, new int[] { 1 });
                    rms.Add(brm);
                    RasterMaper rm = new RasterMaper(currPrd, new int[] { 1 });
                    rms.Add(rm);
                    //输出文件准备(作为输入栅格并集处理)
                    string outFileName = MifEnvironment.GetFullFileName(".dat");
                    using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                    {
                        //栅格数据映射
                        RasterMaper[] fileIns  = rms.ToArray();
                        RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                        //创建处理模型
                        RasterProcessModel <UInt16, UInt16> rfr = null;
                        rfr = new RasterProcessModel <UInt16, UInt16>();
                        rfr.SetRaster(fileIns, fileOuts);
                        int totalIndex = -1;
                        if (progressTracker != null)
                        {
                            progressTracker.Invoke(35, "开始处理云和地表温度信息,请稍候...");
                        }
                        rfr.RegisterCalcModel(new RasterCalcHandler <UInt16, UInt16>((rvInVistor, rvOutVistor, rfrAOI) =>
                        {
                            int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                            if (rvInVistor[0].RasterBandsData[0] != null && rvInVistor[1].RasterBandsData[0] != null)
                            {
                                for (int index = 0; index < dataLength; index++)
                                {
                                    totalIndex++;;
                                    UInt16 cloudData = rvInVistor[0].RasterBandsData[0][index];
                                    UInt16 valueData = rvInVistor[1].RasterBandsData[0][index];
                                    if (cloudData != 0 || nanValues.Contains(valueData))
                                    {
                                        resultTemp.Put(totalIndex, defCloudy);
                                    }
                                    else if (waterValues.Contains(valueData))
                                    {
                                        resultTemp.Put(totalIndex, defWater);
                                    }
                                    else if (valueData == 0)
                                    {
                                        resultTemp.Put(totalIndex, 0);
                                    }
                                    else
                                    {
                                        if (vaildLstList.ContainsKey(valueData))
                                        {
                                            vaildLstList[valueData]++;
                                        }
                                        else
                                        {
                                            vaildLstList.Add(valueData, 1);
                                        }
                                    }
                                }
                            }
                        }));
                        //执行
                        rfr.Excute();
                    }
                }
                else
                {
                    if (progressTracker != null)
                    {
                        progressTracker.Invoke(15, "开始提取地表温度信息,请稍候...");
                    }
                    rpVisitor = new RasterPixelsVisitor <UInt16>(ap);
                    rpVisitor.VisitPixel(new int[] { LstBandCH },
                                         (index, values) =>
                    {
                        if (nanValues.Contains(values[0]))
                        {
                            resultTemp.Put(index, defCloudy);
                        }
                        else if (waterValues.Contains(values[0]))
                        {
                            resultTemp.Put(index, defWater);
                        }
                        else if (values[0] == 0)
                        {
                            resultTemp.Put(index, 0);
                        }
                        else
                        {
                            if (vaildLstList.ContainsKey(values[0]))
                            {
                                vaildLstList[values[0]]++;
                            }
                            else
                            {
                                vaildLstList.Add(values[0], 1);
                            }
                        }
                    });
                }
                UInt16 minValue = 0;
                UInt16 maxValue = UInt16.MaxValue;
                GetMinMaxValue(vaildLstList, LSTMin, LSTMax, minCount, out minValue, out maxValue);
                if (maxValue == minValue)
                {
                    return(null);
                }
                UInt16 result = 0;
                if (rpVisitor == null)
                {
                    rpVisitor = new RasterPixelsVisitor <UInt16>(ap);
                }
                if (progressTracker != null)
                {
                    progressTracker.Invoke(65, "开始计算热效应强度信息,请稍候...");
                }
                int[]  tempIndexes = resultTemp.Indexes.ToArray();
                double resultHFII  = 0f;
                rpVisitor.VisitPixel(new int[] { LstBandCH },
                                     (index, values) =>
                {
                    if (!tempIndexes.Contains(index))
                    {
                        resultHFII = ((float)(values[0] - minValue)) / (maxValue - minValue) * HFIIZoom;
                        if (resultHFII <= 0)
                        {
                            result = (UInt16)1;
                        }
                        else
                        {
                            result = (UInt16)resultHFII;
                        }
                        resultTemp.Put(index, result);
                    }
                });
                if (progressTracker != null)
                {
                    progressTracker.Invoke(85, "开始保存热效应强度信息,请稍候...");
                }
                return(GenrateIInterested(resultTemp, currPrd, "HFII"));
            }
            finally
            {
                if (currPrd != null)
                {
                    currPrd.Dispose();
                }
                if (cloudPrd != null)
                {
                    cloudPrd.Dispose();
                }
            }
        }
コード例 #22
0
        private IExtractResult CalcAnmi(Action <int, string> progressTracker)
        {
            if (_argumentProvider.GetArg("NDVIFile") == null)
            {
                PrintInfo("请选择植被指数数据。");
                return(null);
            }
            string ndvi = _argumentProvider.GetArg("NDVIFile").ToString();

            if (!File.Exists(ndvi))
            {
                PrintInfo("所选择的数据:\"" + ndvi + "\"不存在。");
                return(null);
            }
            if (_argumentProvider.GetArg("NdviCH") == null)
            {
                PrintInfo("参数\"NdviCH\"为空。");
                return(null);
            }
            int ndviCh = (int)_argumentProvider.GetArg("NdviCH");

            if (_argumentProvider.GetArg("NDVIAvgFile") == null)
            {
                PrintInfo("请选择植被指数年均值数据。");
                return(null);
            }
            string avg = _argumentProvider.GetArg("NDVIAvgFile").ToString();

            if (!File.Exists(avg))
            {
                PrintInfo("所选择的数据:\"" + avg + "\"不存在。");
                return(null);
            }
            if (_argumentProvider.GetArg("NdviAvgCH") == null)
            {
                PrintInfo("参数\"NdviAvgCH\"为空。");
                return(null);
            }
            int avgCH = (int)_argumentProvider.GetArg("NdviAvgCH");

            if (ndviCh < 1 || avgCH < 1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            Int16 defCloudy           = (Int16)_argumentProvider.GetArg("defCloudy");
            Int16 cloudyInvaildResult = Int16.MinValue;
            //输入文件准备
            List <RasterMaper> rms = new List <RasterMaper>();

            try
            {
                IRasterDataProvider inRaster = RasterDataDriver.Open(ndvi) as IRasterDataProvider;
                if (inRaster.BandCount < ndviCh)
                {
                    PrintInfo("请选择正确的数据进行距平计算。");
                    return(null);
                }
                RasterMaper brm = new RasterMaper(inRaster, new int[] { ndviCh });
                rms.Add(brm);
                IRasterDataProvider iRaster = RasterDataDriver.Open(avg) as IRasterDataProvider;
                if (iRaster.BandCount < avgCH)
                {
                    PrintInfo("请选择正确的数据进行距平计算。");
                    return(null);
                }
                RasterMaper rm = new RasterMaper(iRaster, new int[] { avgCH });
                rms.Add(rm);
                string[] fileNames = new string[] { ndvi, avg };
                //输出文件准备(作为输入栅格并集处理)
                RasterIdentify ri          = GetRasterIdentifyID(fileNames);
                string         outFileName = ri.ToWksFullFileName(".dat");
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <short, short> rfr = null;
                    rfr = new RasterProcessModel <short, short>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    short[] nanValues   = GetNanValues("CloudyValue");
                    short[] waterValues = GetNanValues("WaterValue");
                    rfr.RegisterCalcModel(new RasterCalcHandler <short, short>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        if (rvInVistor[0].RasterBandsData == null || rvInVistor[1].RasterBandsData == null ||
                            rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1].RasterBandsData[0] == null)
                        {
                            return;
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            Int16 data1 = rvInVistor[0].RasterBandsData[0][index];
                            Int16 data2 = rvInVistor[1].RasterBandsData[0][index];
                            if (VaildRegionAndCloudyProcess.isNanValue(data1, nanValues) ||
                                VaildRegionAndCloudyProcess.isNanValue(data1, waterValues))
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = data1;
                                continue;
                            }
                            if (VaildRegionAndCloudyProcess.isNanValue(data2, nanValues) ||
                                VaildRegionAndCloudyProcess.isNanValue(data2, waterValues))
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = data2;
                                continue;
                            }
                            rvOutVistor[0].RasterBandsData[0][index] = (short)(data1 - data2);
                        }
                    }));
                    //执行
                    rfr.Excute(0);
                    FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                    res.SetDispaly(false);
                    return(res);
                }
            }
            finally
            {
                foreach (RasterMaper rm in rms)
                {
                    rm.Raster.Dispose();
                }
            }
        }
コード例 #23
0
        private IFileExtractResult ComputeDepthRaster(string currentRasterFile, string dblvFile, string roughnessFile, string angleFile, int visibleCH, int shortInfraredCH, string[] depthArgs)
        {
            float arg;
            float a0 = 0, a1 = 0, a2 = 0, a3 = 0, b0 = 0, b1 = 0, b2 = 0, b3 = 0;

            if (String2Float(depthArgs[1], out arg))
            {
                a0 = arg;
            }
            if (String2Float(depthArgs[2], out arg))
            {
                a1 = arg;
            }
            if (String2Float(depthArgs[3], out arg))
            {
                a2 = arg;
            }
            if (String2Float(depthArgs[4], out arg))
            {
                a3 = arg;
            }
            if (String2Float(depthArgs[5], out arg))
            {
                b0 = arg;
            }
            if (String2Float(depthArgs[6], out arg))
            {
                b1 = arg;
            }
            if (String2Float(depthArgs[7], out arg))
            {
                b2 = arg;
            }
            if (String2Float(depthArgs[8], out arg))
            {
                b3 = arg;
            }
            List <RasterMaper>  rms               = null;
            IRasterDataProvider outRaster         = null;
            RasterProcessModel <Int16, float> rfr = null;
            bool isCorrectAngle                   = false;

            try
            {
                rms = new List <RasterMaper>();
                IRasterDataProvider argRaster = GeoDataDriver.Open(roughnessFile) as IRasterDataProvider;
                RasterMaper         argRm     = new RasterMaper(argRaster, new int[] { 1 });
                rms.Add(argRm);
                IRasterDataProvider inRaster = GeoDataDriver.Open(currentRasterFile) as IRasterDataProvider;
                RasterMaper         fileIn   = new RasterMaper(inRaster, new int[] { visibleCH, shortInfraredCH });
                rms.Add(fileIn);
                IRasterDataProvider dblvRaster = GeoDataDriver.Open(dblvFile) as IRasterDataProvider;
                RasterMaper         dblvRm     = new RasterMaper(dblvRaster, new int[] { 1 });
                rms.Add(dblvRm);
                if (!string.IsNullOrEmpty(angleFile))
                {
                    IRasterDataProvider angleRaster = GeoDataDriver.Open(angleFile) as IRasterDataProvider;
                    RasterMaper         angleRm     = new RasterMaper(angleRaster, new int[] { 1 });
                    rms.Add(angleRm);
                    isCorrectAngle = true;
                }
                //string outFileId = _argumentProvider.GetArg("OutFileIdentify").ToString();
                string depthFileName = GetFileName(new string[] { currentRasterFile }, _subProductDef.ProductDef.Identify, "0SSD", ".dat", null);
                outRaster = CreateOutRaster(depthFileName, enumDataType.Float, rms.ToArray(), inRaster.ResolutionX);
                RasterMaper   fileOut  = new RasterMaper(outRaster, new int[] { 1 });
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { fileOut };
                rfr = new RasterProcessModel <Int16, float>();
                rfr.SetRaster(fileIns, fileOuts);
                rfr.RegisterCalcModel(new RasterCalcHandler <Int16, float>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[2].RasterBandsData[0] != null)
                    {
                        int length = rvInVistor[2].RasterBandsData[0].Length;
                        for (int i = 0; i < length; i++)
                        {
                            if (rvInVistor[2].RasterBandsData[0][i] == 1)
                            {
                                short roughValue = rvInVistor[0].RasterBandsData[0][i];
                                if (roughValue == -9999)
                                {
                                    rvOutVistor[0].RasterBandsData[0][i] = -9999f;
                                }
                                else
                                {
                                    float value;
                                    float ref1 = rvInVistor[1].RasterBandsData[0][i] / 10f;
                                    float ref6 = rvInVistor[1].RasterBandsData[1][i] / 10f;

                                    if (isCorrectAngle)
                                    {
                                        float angle = rvInVistor[3].RasterBandsData[0][i] / 100f;
                                        ref1        = CorrectBandValue(angle, ref1);
                                        ref6        = CorrectBandValue(angle, ref6);
                                    }
                                    if (roughValue <= 2000)
                                    {
                                        value = a0 + a1 * ref1 + a2 * ref1 / ref6 + a3 * (ref1 - ref6);
                                        value = value <= 0 ? 0.1f : (value > 50 ? 50 : value);
                                        rvOutVistor[0].RasterBandsData[0][i] = value;
                                    }
                                    else
                                    {
                                        value = b0 + b1 * ref1 + b2 * ref1 / ref6 + b3 * (ref1 - ref6);
                                        value = value <= 0 ? 0.1f : (value > 50 ? 50 : value);
                                        rvOutVistor[0].RasterBandsData[0][i] = value;
                                    }
                                }
                            }
                        }
                    }
                }));
                rfr.Excute();
                IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, depthFileName, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
コード例 #24
0
        /// <summary>
        /// 单文件计算其NDVI
        /// </summary>
        /// <param name="inputFile"></param>
        /// <param name="bandNos"></param>
        /// <param name="zoom"></param>
        /// <param name="aoiTemplate"></param>
        /// <param name="progressTracker"></param>
        /// <returns></returns>
        private IExtractResult CalcNDVI(string inputFile, int[] bandNos, float zoom, double[] CloudyZoom, float[] cloudyArgs, Int16 defCloudy, bool isFitterCloud, bool isAppCloud, string aoiTemplate, Action <int, string> progressTracker)
        {
            //查找输入文件对应的云判识结果文件
            RasterProcessModel <ushort, short> rfr = null;
            List <RasterMaper> fileIns             = new List <RasterMaper>();

            RasterMaper[]       fileOuts = null;
            IRasterDataProvider clmPrd   = null;

            try
            {
                //输入数据(LDF)
                IRasterDataProvider inRaster = RasterDataDriver.Open(inputFile) as IRasterDataProvider;
                if (inRaster == null)
                {
                    PrintInfo("读取栅格文件失败:" + inRaster);
                    return(null);
                }
                //输出数据(NDVI)
                string            outFileName = GetFileName(new string[] { inRaster.fileName }, _subProductDef.ProductDef.Identify, _identify, ".dat", null);
                IRasterDataDriver dd          = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                string            mapInfo     = inRaster.CoordEnvelope.ToMapInfoString(new Size(inRaster.Width, inRaster.Height));
                string[]          opts        = new string[] {
                    "INTERLEAVE=BSQ",
                    "VERSION=MEM",
                    "WITHHDR=TRUE",
                    "SPATIALREF=" + inRaster.SpatialRef.ToProj4String(),
                    mapInfo
                };

                RasterDataProvider outRaster = dd.Create(outFileName, inRaster.Width, inRaster.Height, 1, enumDataType.Int16, opts) as RasterDataProvider;
                outRaster.GetRasterBand(1).Fill(Int16.MinValue);
                string clmFile = GetClmFile(inputFile);
                int    cloudCH = GetCloudCHNO();
                //栅格数据映射
                fileIns.Add(new RasterMaper(inRaster, bandNos));
                if (isAppCloud)
                {
                    if (!string.IsNullOrEmpty(clmFile) && File.Exists(clmFile))
                    {
                        clmPrd = GeoDataDriver.Open(clmFile) as IRasterDataProvider;
                        if (clmPrd.BandCount < cloudCH)
                        {
                            PrintInfo("请选择正确的云数据通道进行计算.");
                            isAppCloud = false;
                        }
                        else
                        {
                            fileIns.Add(new RasterMaper(clmPrd, new int[] { cloudCH }));
                        }
                    }
                    else
                    {
                        isAppCloud = false;
                    }
                }
                RasterMaper fileOut = new RasterMaper(outRaster, new int[] { 1 });
                //创建处理模型
                fileOuts = new RasterMaper[] { fileOut };
                rfr      = new RasterProcessModel <ushort, short>(progressTracker);
                rfr.SetRaster(fileIns.ToArray(), fileOuts);
                rfr.SetTemplateAOI(aoiTemplate);
                rfr.RegisterCalcModel(new RasterCalcHandler <ushort, short>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData != null)
                    {
                        if (rvInVistor == null)
                        {
                            return;
                        }
                        ushort[] inBand0  = rvInVistor[0].RasterBandsData[0];                     //第1个输入文件的第1个波段的各像素值
                        ushort[] inBand1  = rvInVistor[0].RasterBandsData[1];                     //第1个输入文件的第2个波段的各像素值
                        ushort[] inBand2  = rvInVistor[0].RasterBandsData[2];                     //第1个输入文件的第3个波段的各像素值
                        ushort[] inBand3  = rvInVistor[0].RasterBandsData[3];                     //第1个输入文件的第4个波段的各像素值
                        ushort[] inBand12 = isAppCloud ? rvInVistor[1].RasterBandsData[0] : null; //第2个输入文件的第1个波段的各像素值
                        short[] ndvi      = new short[inBand0.Length];
                        if (aoi == null || aoi.Length == 0)
                        {
                            for (int index = 0; index < inBand0.Length; index++)
                            {
                                if ((inBand12 != null && inBand12[index] != 0) || (isFitterCloud && inBand1[index] / CloudyZoom[0] > cloudyArgs[0] && inBand3[index] / CloudyZoom[2] < cloudyArgs[1] && Math.Abs(inBand2[index] / CloudyZoom[1] - inBand3[index] / CloudyZoom[2]) > cloudyArgs[2]))
                                {
                                    rvOutVistor[0].RasterBandsData[0][index] = defCloudy;
                                    continue;
                                }
                                //第1个输出文件的第1个波段存储NDVI值
                                rvOutVistor[0].RasterBandsData[0][index] = (short)((inBand1[index] - inBand0[index]) * zoom / (inBand1[index] + inBand0[index]));
                            }
                        }
                        else if (aoi != null && aoi.Length != 0)
                        {
                            int index;
                            for (int i = 0; i < aoi.Length; i++)
                            {
                                index = aoi[i];
                                if ((inBand12 != null && inBand12[index] != 0) || (isFitterCloud && inBand1[index] / CloudyZoom[0] > cloudyArgs[0] && inBand3[index] / CloudyZoom[2] < cloudyArgs[1] && Math.Abs(inBand2[index] / CloudyZoom[1] - inBand3[index] / CloudyZoom[2]) > cloudyArgs[2]))
                                {
                                    rvOutVistor[0].RasterBandsData[0][index] = defCloudy;
                                    continue;
                                }
                                //第1个输出文件的第1个波段存储NDVI值
                                rvOutVistor[0].RasterBandsData[0][index] = (short)((inBand1[index] - inBand0[index]) * zoom / (inBand1[index] + inBand0[index]));
                            }
                        }
                    }
                }));
                //执行
                rfr.Excute();
                FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (fileIns != null)
                {
                    for (int i = 0; i < fileIns.Count; i++)
                    {
                        fileIns[i].Raster.Dispose();
                    }
                }
                if (fileOuts != null)
                {
                    for (int i = 0; i < fileOuts.Length; i++)
                    {
                        fileOuts[i].Raster.Dispose();
                    }
                }
                if (clmPrd != null)
                {
                    clmPrd.Dispose();
                }
            }
        }
コード例 #25
0
        private IFileExtractResult ComputeSnowDepth(string inputFileName, int[] bandNos, string[] argFiles, double[] sdParas)
        {
            List <RasterMaper>  rms                = null;
            IRasterDataProvider outRaster          = null;
            RasterProcessModel <Int16, double> rfr = null;

            try
            {
                rms = new List <RasterMaper>();
                IRasterDataProvider inRaster = GeoDataDriver.Open(inputFileName) as IRasterDataProvider;
                RasterMaper         fileIn   = new RasterMaper(inRaster, bandNos);
                rms.Add(fileIn);
                foreach (string file in argFiles)
                {
                    IRasterDataProvider argRaster = GeoDataDriver.Open(file) as IRasterDataProvider;
                    RasterMaper         argRm     = new RasterMaper(argRaster, new int[] { 1 });
                    rms.Add(argRm);
                }
                string depthFileName = GetFileName(new string[] { inputFileName }, _subProductDef.ProductDef.Identify, "MWSD", ".dat", null);
                outRaster = CreateOutRaster(depthFileName, enumDataType.Double, rms.ToArray(), inRaster.ResolutionX);
                RasterMaper   fileOut  = new RasterMaper(outRaster, new int[] { 1 });
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { fileOut };
                rfr = new RasterProcessModel <Int16, double>();
                rfr.SetRaster(fileIns, fileOuts);
                rfr.RegisterCalcModel(new RasterCalcHandler <Int16, double>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData[0] != null && rvInVistor[1].RasterBandsData[0] != null &&
                        rvInVistor[2].RasterBandsData[0] != null && rvInVistor[3].RasterBandsData[0] != null &&
                        rvInVistor[4].RasterBandsData[0] != null)
                    {
                        int dataLength = rvInVistor[0].RasterBandsData[0].Length;
                        int[] type     = new int[dataLength];
                        double[] sdtmp = new double[dataLength];
                        for (int i = 0; i < dataLength; i++)
                        {
                            //type
                            type[i]      = NO_SCATTER;
                            double ch10v = btValue(rvInVistor[0].RasterBandsData[0][i]);
                            double ch10h = btValue(rvInVistor[0].RasterBandsData[1][i]);
                            double ch18v = btValue(rvInVistor[0].RasterBandsData[2][i]);
                            double ch18h = btValue(rvInVistor[0].RasterBandsData[3][i]);
                            double ch23v = btValue(rvInVistor[0].RasterBandsData[4][i]);
                            double ch23h = btValue(rvInVistor[0].RasterBandsData[5][i]);
                            double ch36v = btValue(rvInVistor[0].RasterBandsData[6][i]);
                            double ch36h = btValue(rvInVistor[0].RasterBandsData[7][i]);
                            double ch89v = btValue(rvInVistor[0].RasterBandsData[8][i]);
                            double ch89h = btValue(rvInVistor[0].RasterBandsData[9][i]);
                            double si1   = ch23v - ch89v;
                            double si2   = ch18v - ch36v;
                            if (si1 >= 5 || si2 >= 5)
                            {
                                if (ch23v <= 260)
                                {
                                    if (ch18v - ch36v >= 20)
                                    {
                                        if (si1 - si2 >= WET_FACTOR)
                                        {
                                            type[i] = THICK_DRY_SNOW;
                                        }
                                        else
                                        {
                                            type[i] = THICK_WET_SNOW;
                                        }
                                    }
                                    else
                                    {
                                        if (si1 - si2 >= 8)
                                        {
                                            type[i] = THIN_DRY_SNOW;
                                        }
                                        else
                                        {
                                            if (si1 - si2 <= WET_FACTOR1)
                                            {
                                                type[i] = VERY_THICK_WET_SNOW;
                                            }
                                            else
                                            {
                                                if (ch18v - ch18h <= 6 && ch18v - ch36v >= 10)
                                                {
                                                    type[i] = THIN_WET_SNOW_OR_FOREST_SNOW;
                                                }
                                                else
                                                {
                                                    type[i] = NO_SNOW;
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    type[i] = NO_SNOW;
                                }
                            }
                            else
                            {
                                type[i] = NO_SNOW;
                            }
                            //sdtmp
                            double sdFarmland = sdParas[0] + sdParas[1] * (ch18v - ch36h) + sdParas[2] * (ch89v - ch89h);
                            double sdGrass    = sdParas[3] + sdParas[4] * (ch18h - ch36h) - sdParas[5] * (ch18v - ch18h) + sdParas[6] * (ch10v - ch89h) - sdParas[7] * (ch18v - ch89h);
                            double sdBaren    = sdParas[8] + sdParas[9] * (ch36h - ch89h) - sdParas[10] * (ch10v - ch89v);
                            double sdForest   = sdParas[11] + sdParas[12] * (ch18h - ch36v) - sdParas[13] * (ch18v - ch18h) + sdParas[14] * (ch89v - ch89h);
                            sdtmp[i]          = (rvInVistor[1].RasterBandsData[0][i] * sdBaren +
                                                 rvInVistor[2].RasterBandsData[0][i] * sdGrass +
                                                 rvInVistor[3].RasterBandsData[0][i] * sdForest +
                                                 rvInVistor[4].RasterBandsData[0][i] * sdFarmland) / 10000; //原地类百分比文件扩大了10000倍
                            //设置输出数据值
                            if (type[i] == NO_SNOW || type[i] == THICK_WET_SNOW || type[i] == THIN_WET_SNOW_OR_FOREST_SNOW || type[i] == VERY_THICK_WET_SNOW)
                            {
                                sdtmp[i] = 0.0;
                            }
                            if (sdtmp[i] < 0)
                            {
                                sdtmp[i] = 0;
                            }
                            else
                            {
                                sdtmp[i] = sdtmp[i];
                            }
                            rvOutVistor[0].RasterBandsData[0][i] = sdtmp[i];
                        }
                    }
                    //输出
                }));
                rfr.Excute();
                IFileExtractResult res = new FileExtractResult(_subProductDef.Identify, depthFileName, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
                if (rms != null && rms.Count > 0)
                {
                    foreach (RasterMaper rm in rms)
                    {
                        if (rm.Raster != null)
                        {
                            rm.Raster.Dispose();
                        }
                    }
                }
            }
        }
コード例 #26
0
        private string ProcessCloud(string srcFilename, int bandNo)
        {
            string cloudFile = GetClmFile(srcFilename);

            if (string.IsNullOrEmpty(cloudFile) || !File.Exists(cloudFile))
            {
                return(srcFilename);
            }
            Int16 defCloudy              = (Int16)_argumentProvider.GetArg("defCloudy");
            List <RasterMaper>  rms      = new List <RasterMaper>();
            IRasterDataProvider snwPrd   = GeoDataDriver.Open(srcFilename) as RasterDataProvider;
            IRasterDataProvider cloudPrd = GeoDataDriver.Open(cloudFile) as RasterDataProvider;

            try
            {
                RasterMaper snwRm = new RasterMaper(snwPrd, new int[] { bandNo });
                rms.Add(snwRm);

                RasterMaper cloudRm = new RasterMaper(cloudPrd, new int[] { GetCloudCHNO() });
                rms.Add(cloudRm);

                MifConfig mifConfig   = new MifConfig();
                string    outFileName = mifConfig.GetConfigValue("TEMP") + "\\" + Guid.NewGuid() + ".dat";
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <Int16, Int16> rfr = null;
                    rfr = new RasterProcessModel <Int16, Int16>();
                    rfr.SetRaster(fileIns, fileOuts);
                    rfr.SetFeatureAOI(_argumentProvider.AOIs);
                    rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        if (rvInVistor[0].RasterBandsData == null || rvInVistor[1].RasterBandsData == null ||
                            rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1].RasterBandsData[0] == null)
                        {
                            return;
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            if (rvInVistor[1].RasterBandsData[0][index] == 1 && rvInVistor[0].RasterBandsData[0][index] == 0)
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = defCloudy;
                            }
                            else
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = rvInVistor[0].RasterBandsData[0][index];
                            }
                        }
                    }));
                    //执行
                    rfr.Excute();
                    return(outFileName);
                }
            }
            finally
            {
                snwPrd.Dispose();
                cloudPrd.Dispose();
            }
        }
コード例 #27
0
        private IExtractResult LAODAlgorithm(Action <int, string> progressTracker)
        {
            IRasterOperator <Int16> roper = new RasterOperator <Int16>();

            string[] files = GetStringArray("SelectedPrimaryFiles");
            if (files == null || files.Length == 0)
            {
                return(null);
            }
            string[] argFileArg  = _argumentProvider.GetArg("RegionFileName") as string[];
            string   argFileName = argFileArg[0];

            if (string.IsNullOrEmpty(argFileName))
            {
                PrintInfo("请设置等级参数文件!");
                return(null);
            }
            SortedDictionary <float, float[]> levelRegions = GetArgFileRegion(argFileName);

            if (levelRegions == null || levelRegions.Count == 0)
            {
                return(null);
            }
            string AODFile = Convert.ToString(_argumentProvider.GetArg("AODFile"));

            if (string.IsNullOrWhiteSpace(AODFile))
            {
                return(null);
            }
            string[] aodFiles = AODFile.Split(new char[] { ',' });
            if (aodFiles.Length != 2)
            {
                return(null);
            }
            string             aodFile        = aodFiles[0];
            int                bandNo         = 1;
            IBandNameRaster    bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;
            int                aodNo          = TryGetBandNo(bandNameRaster, "AODNO");
            List <RasterMaper> rms            = new List <RasterMaper>();

            try
            {
                IRasterDataProvider dblv   = RasterDataDriver.Open(files[0]) as IRasterDataProvider;
                RasterMaper         rmDBLV = new RasterMaper(dblv, new int[] { bandNo });
                rms.Add(rmDBLV);
                IRasterDataProvider aod = RasterDataDriver.Open(aodFile) as IRasterDataProvider;
                if (aod.BandCount < bandNo)
                {
                    PrintInfo("请选择正确的AOD数据进行定量产品计算。");
                    return(null);
                }
                RasterMaper rmAOD = new RasterMaper(aod, new int[] { aodNo });
                rms.Add(rmAOD);
                //输出文件准备(作为输入栅格并集处理)
                RasterIdentify ri          = GetRasterIdentifyID(files);
                string         outFileName = MifEnvironment.GetTempDir() + "\\" + ri.ToWksFileName(".dat");
                bool           isVaild     = false;
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <Int16, Int16> rfr = null;
                    rfr = new RasterProcessModel <Int16, Int16>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        for (int index = 0; index < dataLength; index++)
                        {
                            if (rvInVistor[0].RasterBandsData != null && rvInVistor[0].RasterBandsData[0] != null &&
                                rvInVistor[0].RasterBandsData[0][index] != 0)
                            {
                                if (rvInVistor[1].RasterBandsData != null && rvInVistor[1].RasterBandsData[0] != null)
                                {
                                    foreach (float minValue in levelRegions.Keys)
                                    {
                                        if (rvInVistor[1].RasterBandsData[0][index] >= minValue && rvInVistor[1].RasterBandsData[0][index] < levelRegions[minValue][0])
                                        {
                                            rvOutVistor[0].RasterBandsData[0][index] = (Int16)levelRegions[minValue][1];
                                            isVaild = true;
                                        }
                                    }
                                    if (!isVaild)
                                    {
                                        rvOutVistor[0].RasterBandsData[0][index] = (Int16)1;
                                    }
                                    isVaild = false;
                                }
                            }
                        }
                    }));
                    //执行
                    rfr.Excute();
                    if (File.Exists(outFileName))
                    {
                        string dstFilename = ri.ToWksFullFileName(".dat");
                        CopyFileToDstDir(outFileName, dstFilename);
                        FileExtractResult res = new FileExtractResult(_subProductDef.Identify, dstFilename, true);
                        res.SetDispaly(false);
                        CreateThemegrahic(dstFilename);
                        return(res);
                    }
                    return(null);
                }
            }
            finally
            {
                foreach (RasterMaper rm in rms)
                {
                    rm.Raster.Dispose();
                }
            }
        }
コード例 #28
0
        private IExtractResult FRDSAlgorithm(Action <int, string> progressTracker)
        {
            string[] fileNames = GetStringArray("SelectedPrimaryFiles");
            if (fileNames == null || fileNames.Count() == 0)
            {
                PrintInfo("请选择参与积雪天数统计的数据!");
                return(null);
            }
            foreach (string f in fileNames)
            {
                if (!File.Exists(f))
                {
                    PrintInfo("所选择的数据:\"" + f + "\"不存在。");
                    return(null);
                }
            }
            int bandNo = 1;
            ExtractResultArray array = new ExtractResultArray("SNW");
            //输出文件准备(作为输入栅格并集处理)
            RasterIdentify ri          = GetRasterIdentifyID(ref fileNames);
            string         outFileName = ri.ToWksFullFileName(".dat");
            //输入文件准备
            List <RasterMaper> rms = new List <RasterMaper>();
            string             tempFilename;

            try
            {
                for (int i = 0; i < fileNames.Length; i++)
                {
                    tempFilename = ProcessCloud(fileNames[i], bandNo);
                    IRasterDataProvider inRaster = RasterDataDriver.Open(tempFilename) as IRasterDataProvider;
                    if (inRaster.BandCount < bandNo)
                    {
                        PrintInfo("请选择正确的数据进行积雪天数统计。");
                        return(null);
                    }
                    RasterMaper rm = new RasterMaper(inRaster, new int[] { tempFilename == fileNames[i] ? bandNo : 1 });
                    rms.Add(rm);
                }
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <Int16, Int16> rfr = null;
                    rfr = new RasterProcessModel <Int16, Int16>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    Int16[] nanValues     = GetNanValues("CloudyValue");
                    Int16[] waterValues   = GetNanValues("WaterValue");
                    Int16[] invailValues  = GetNanValues("InvailValue");
                    Int16   currTimeValue = 0;
                    rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength         = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        Int16[] timeValue      = new Int16[dataLength];
                        List <Int16> tempValue = new List <Int16>();
                        for (int i = 0; i < dataLength; i++)
                        {
                            timeValue[i] = 0;
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            foreach (RasterVirtualVistor <Int16> rvs in rvInVistor)
                            {
                                Int16[] dt = rvs.RasterBandsData[0];
                                if (dt == null)
                                {
                                    continue;
                                }
                                tempValue.Add(dt[index]);
                            }

                            if (tempValue.Count == 0)
                            {
                                continue;
                            }
                            if (TimeValue(tempValue.ToArray(), nanValues, invailValues, waterValues, out currTimeValue))
                            {
                                timeValue[index] = currTimeValue;
                            }
                            tempValue.Clear();
                        }
                        for (int index = 0; index < dataLength; index++)
                        {
                            rvOutVistor[0].RasterBandsData[0][index] = timeValue[index];
                        }
                    }));
                    //执行
                    rfr.Excute(0);
                    FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                    array.Add(res);
                    res.SetDispaly(false);
                }
            }
            finally
            {
                foreach (RasterMaper rm in rms)
                {
                    rm.Raster.Dispose();
                }
            }

            _argumentProvider.SetArg("SelectedPrimaryFiles", new string[] { outFileName });
            string instanceIdentify = _argumentProvider.GetArg("OutFileIdentify") as string;

            if (string.IsNullOrWhiteSpace(instanceIdentify))
            {
                return(array);
            }
            SubProductInstanceDef instance = FindSubProductInstanceDefs(instanceIdentify);
            IExtractResult        ress     = ThemeGraphyByInstance(instance);

            if (ress != null)
            {
                array.Add(ress as IFileExtractResult);
            }
            return(array);
        }
コード例 #29
0
        /// <summary>
        /// 判识结果保存事件
        /// </summary>
        /// <param name="piexd">判识结果</param>
        /// <param name="progressTracker"></param>
        /// <returns></returns>
        /// 原始影像和判识结果读取到一个结果集中,分为输入输出两个,输出的就是需要保存的结果
        public override IExtractResult MakeExtProduct(IPixelIndexMapper piexd, Action <int, string> progressTracker)
        {
            //生成判识结果文件
            IInterestedRaster <UInt16> iir = null;
            RasterIdentify             id  = new RasterIdentify(_argumentProvider.DataProvider.fileName);

            id.ThemeIdentify      = "CMA";
            id.ProductIdentify    = "FOG";
            id.SubProductIdentify = _identify;
            id.GenerateDateTime   = DateTime.Now;
            iir = new InterestedRaster <UInt16>(id, piexd.Size, piexd.CoordEnvelope);
            int[] idxs = piexd.Indexes.ToArray();
            iir.Put(idxs, 1);
            //原始影像raster
            IRasterDataProvider sourceraster = _argumentProvider.DataProvider as IRasterDataProvider;
            List <RasterMaper>  listRaster   = new List <RasterMaper>();
            RasterMaper         rmsoure      = new RasterMaper(sourceraster, GetBandArray(sourceraster.BandCount));
            RasterMaper         rmpiexd      = new RasterMaper(iir.HostDataProvider, new int[] { 1 });
            int totalbandcount = sourceraster.BandCount;

            listRaster.Add(rmpiexd);
            listRaster.Add(rmsoure);
            try
            {
                string outFileName = GetFileName(new string[] { _argumentProvider.DataProvider.fileName }, _subProductDef.ProductDef.Identify, "SRDA", ".ldf", null);
                using (IRasterDataProvider outRaster = CreateOutM_BandRaster(outFileName, listRaster.ToArray(), totalbandcount))
                {
                    //波段总数

                    RasterMaper[] fileIns  = listRaster.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, GetBandArray(totalbandcount)) };
                    //创建处理模型
                    RasterProcessModel <UInt16, UInt16> rfr = null;
                    rfr = new RasterProcessModel <UInt16, UInt16>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    rfr.SetFeatureAOI(_argumentProvider.AOIs);
                    rfr.RegisterCalcModel(new RasterCalcHandler <UInt16, UInt16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        if (rvInVistor[0].RasterBandsData == null || rvInVistor[1].RasterBandsData == null ||
                            rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1].RasterBandsData[0] == null)
                        {
                            return;
                        }
                        // if (_argumentProvider.AOIs == null)
                        for (int index = 0; index < dataLength; index++)
                        {
                            if (rvInVistor[0].RasterBandsData[0][index] == 1)
                            {
                                for (int i = 0; i < totalbandcount; i++)
                                {
                                    rvOutVistor[0].RasterBandsData[i][index] = rvInVistor[1].RasterBandsData[i][index];
                                }
                            }
                        }
                    }
                                                                                 ));
                    //执行
                    rfr.Excute(0);
                }
                string dstfilename = outFileName.Replace(".ldf", ".dat");
                if (File.Exists(dstfilename))
                {
                    File.Delete(dstfilename);
                }
                File.Move(outFileName, dstfilename);
                FileExtractResult res = new FileExtractResult("FOG", dstfilename, true);

                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                iir.Dispose();
                if (File.Exists(iir.FileName))
                {
                    File.Delete(iir.FileName);
                }
            }
        }
コード例 #30
0
ファイル: SubProductQIPCDST.cs プロジェクト: windygu/hispeed
        private IExtractResult VirrAlgorithm()
        {
            int             farInfraredNo1, farInfraredNo2;
            IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;

            farInfraredNo1 = TryGetBandNo(bandNameRaster, "FarInfrared1");
            farInfraredNo2 = TryGetBandNo(bandNameRaster, "FarInfrared2");
            if (farInfraredNo1 == -1 || farInfraredNo2 == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            int[] bandNos = new int[] { farInfraredNo1, farInfraredNo2 };
            if (_argumentProvider.GetArg("BinaryFile") == null)
            {
                PrintInfo("获取判识结果文件失败。");
                return(null);
            }
            string dblvFile = _argumentProvider.GetArg("BinaryFile").ToString();

            if (string.IsNullOrEmpty(dblvFile) || !File.Exists(dblvFile))
            {
                PrintInfo("获取判识结果文件失败。");
                return(null);
            }
            string angleFile = _argumentProvider.GetArg("AngleFile").ToString();

            if (string.IsNullOrEmpty(angleFile) || !File.Exists(angleFile))
            {
                PrintInfo("获取太阳天顶角文件失败。");
                return(null);
            }
            //参数检查与获取
            string landTypeFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ProductArgs\\DST\\GlobleLandCover.dat");

            if (!File.Exists(landTypeFile))
            {
                PrintInfo("土地类型文件不存在!");
                return(null);
            }
            string tempFile = _argumentProvider.GetArg("TemperatureFile").ToString();

            if (string.IsNullOrEmpty(tempFile) || !File.Exists(tempFile))
            {
                PrintInfo("获取温度场文件失败。");
                return(null);
            }
            string pressureFile = _argumentProvider.GetArg("PressureFile").ToString();

            if (string.IsNullOrEmpty(pressureFile) || !File.Exists(pressureFile))
            {
                PrintInfo("获取气压场文件失败。");
                return(null);
            }
            //进行光学厚度与沙尘粒子有效半径计算需要文件:1、原始影像数据;2、查算表数据;3、太阳高度角数据
            List <RasterMaper> inputRms  = new List <RasterMaper>();
            List <RasterMaper> outputRms = new List <RasterMaper>();

            try
            {
                //当前影像(待判识文件)
                RasterMaper rm = new RasterMaper(_argumentProvider.DataProvider, bandNos);
                inputRms.Add(rm);
                //判识结果文件
                IRasterDataProvider dblvPrd = GeoDataDriver.Open(dblvFile) as IRasterDataProvider;
                RasterMaper         dblvRm  = new RasterMaper(dblvPrd, new int[] { 1 });
                inputRms.Add(dblvRm);
                //太阳天顶角文件
                IRasterDataProvider angleDataPrd = GeoDataDriver.Open(angleFile) as IRasterDataProvider;
                RasterMaper         anglerm      = new RasterMaper(angleDataPrd, new int[] { 1 });
                inputRms.Add(anglerm);
                //土地类型文件
                IRasterDataProvider landTypeDataPrd = GeoDataDriver.Open(landTypeFile) as IRasterDataProvider;
                RasterMaper         landTypeRm      = new RasterMaper(landTypeDataPrd, new int[] { 1 });
                inputRms.Add(landTypeRm);
                //温度场文件
                IRasterDataProvider tempDataPrd = GeoDataDriver.Open(landTypeFile) as IRasterDataProvider;
                RasterMaper         tempRm      = new RasterMaper(tempDataPrd, new int[] { 1 });
                inputRms.Add(tempRm);
                //气压场文件
                IRasterDataProvider pressureDataPrd = GeoDataDriver.Open(pressureFile) as IRasterDataProvider;
                RasterMaper         pressureRm      = new RasterMaper(tempDataPrd, new int[] { 1 });
                inputRms.Add(pressureRm);
                RasterIdentify ri = new RasterIdentify(_argumentProvider.DataProvider.fileName);
                ri.ProductIdentify       = "DST";
                ri.IsOutput2WorkspaceDir = true;
                IRasterDataProvider htRaster = CreateOutRaster(ri, dblvPrd, "0DHT");
                RasterMaper         htRm     = new RasterMaper(htRaster, new int[] { 1 });
                outputRms.Add(htRm);
                IRasterDataProvider optRaster = CreateOutRaster(ri, dblvPrd, "0OPT");
                RasterMaper         optRm     = new RasterMaper(optRaster, new int[] { 1 });
                outputRms.Add(optRm);
                //栅格数据映射
                RasterMaper[] fileIns  = inputRms.ToArray();
                RasterMaper[] fileOuts = outputRms.ToArray();
                //创建处理模型
                RasterProcessModel <short, float> rfr = new RasterProcessModel <short, float>();
                rfr.SetRaster(fileIns, fileOuts);
                #region
                rfr.RegisterCalcModel(new RasterCalcHandler <short, float>((rvInVistor, rvOutVistor, aoi) =>
                {
                    int landType;
                    float t1 = 0, t2 = 0;
                    if (rvInVistor[0].RasterBandsData[0] != null)
                    {
                        int length = rvInVistor[0].RasterBandsData[0].Length;
                        for (int i = 0; i < length; i++)
                        {
                            if (rvInVistor[1].RasterBandsData[0][i] == 1)
                            {
                                if (rvInVistor[4].RasterBandsData[0][i] > 263)
                                {
                                    t1 = rvInVistor[4].RasterBandsData[0][i] - 3;
                                    t2 = rvInVistor[4].RasterBandsData[0][i] + 3;
                                }
                                if (rvInVistor[4].RasterBandsData[0][i] < rvInVistor[0].RasterBandsData[0][i])
                                {
                                    t1 = rvInVistor[0].RasterBandsData[0][i];
                                    t2 = rvInVistor[0].RasterBandsData[0][i] + 5;
                                }
                                //for(int m=0;m<)
                                landType = rvInVistor[3].RasterBandsData[0][i];
                                //water
                                if (landType == 0 || landType >= 17)
                                {
                                }
                                //desert
                                else if (landType == 16)
                                {
                                }
                                else
                                {
                                }
                            }
                        }
                    }
                }));
                #endregion
                rfr.Excute();
                FileExtractResult htResult = new FileExtractResult("0DHT", htRaster.fileName, true);
                htResult.SetDispaly(false);
                FileExtractResult optResult = new FileExtractResult("0OPT", optRaster.fileName, true);
                optResult.SetDispaly(false);
                ExtractResultArray resultArray = new ExtractResultArray(_subProductDef.Identify);
                resultArray.Add(htResult);
                resultArray.Add(optResult);
                return(resultArray);
            }
            finally
            {
                for (int i = 1; i < inputRms.Count; i++)
                {
                    if (inputRms[i].Raster != null)
                    {
                        inputRms[i].Raster.Dispose();
                    }
                }
                foreach (RasterMaper rm in outputRms)
                {
                    if (rm.Raster != null)
                    {
                        rm.Raster.Dispose();
                    }
                }
            }
        }