Example #1
0
        private IExtractResult CompareDATFile(string backWaterPath, string binWater)
        {
            Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();

            filePrdMap.Add("backWaterPath", new FilePrdMap(backWaterPath, 1, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { 1 }));
            filePrdMap.Add("binWater", new FilePrdMap(binWater, 1, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { 1 }));
            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            IVirtualRasterDataProvider vrd     = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);

            if (vrd == null)
            {
                PrintInfo("数据间无相交部分,无法进行泛滥缩小水体计算!");
                if (filePrdMap != null && filePrdMap.Count > 0)
                {
                    foreach (FilePrdMap value in filePrdMap.Values)
                    {
                        if (value.Prd != null)
                        {
                            value.Prd.Dispose();
                        }
                    }
                }
                return(null);
            }
            try
            {
                ArgumentProvider            ap        = new ArgumentProvider(vrd, null);
                RasterPixelsVisitor <float> rpVisitor = new RasterPixelsVisitor <float>(ap);
                IPixelFeatureMapper <Int16> result    = new MemPixelFeatureMapper <Int16>("FLOD", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
                rpVisitor.VisitPixel(new int[] { filePrdMap["backWaterPath"].StartBand,
                                                 filePrdMap["binWater"].StartBand },
                                     (idx, values) =>
                {
                    if (values[0] == 1 && values[1] == 1)
                    {
                        result.Put(idx, 1);
                    }
                    else if (values[0] == 1 && values[1] == 0)
                    {
                        result.Put(idx, 5);
                    }
                    else if (values[0] == 0 && values[1] == 1)
                    {
                        result.Put(idx, 4);
                    }
                });
                RasterIdentify rid = new RasterIdentify(new string[] { backWaterPath, binWater });
                rid.ProductIdentify       = _subProductDef.ProductDef.Identify;
                rid.SubProductIdentify    = _identify;
                rid.IsOutput2WorkspaceDir = true;
                IInterestedRaster <Int16> iir = new InterestedRaster <Int16>(rid, result.Size, result.CoordEnvelope, result.SpatialRef);
                iir.Put(result);
                iir.Dispose();
                return(new FileExtractResult("扩大缩小水体", iir.FileName));
            }
            finally
            {
                vrd.Dispose();
            }
        }
Example #2
0
        private unsafe void button5_Click(object sender, EventArgs e)
        {
            //先生成全文件NDVI文件
            string fname = @"E:\数据文件\蓝藻\th_2012_05_05_02_44_GZ.ld2";
            IRasterDataProvider         dataProvider = GeoDataDriver.Open(fname) as IRasterDataProvider;
            IPixelFeatureMapper <float> ndvi         = new MemPixelFeatureMapper <float>("NDVI_Temp", 1000, new Size(dataProvider.Width, dataProvider.Height), dataProvider.CoordEnvelope, dataProvider.SpatialRef);
            IArgumentProvider           argprdNDVI   = new ArgumentProvider(dataProvider, null);
            //argprdNDVI.AOI = idxs;
            string expressNDVI = "(band2 - band1) / (float)(band2 + band1)";

            int[] bandNos = new int[] { 1, 2 };
            //构造栅格计算判识器
            IRasterExtracter <UInt16, float> extracterNDVI = new SimpleRasterExtracter <UInt16, float>();

            extracterNDVI.Reset(argprdNDVI, bandNos, expressNDVI);
            //判识
            extracterNDVI.Extract(ndvi);
            //NDVI结果永久保存
            RasterIdentify idNDVI = new RasterIdentify();

            idNDVI.ThemeIdentify      = "CMA";
            idNDVI.ProductIdentify    = "BAG";
            idNDVI.SubProductIdentify = "NDVITemp";
            idNDVI.OrbitDateTime      = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
            idNDVI.GenerateDateTime   = DateTime.Now;
            //NDVISetValue setValue = new NDVISetValue(0.17f, 0.8f);
            //int size = sizeof(NDVISetValue);
            IInterestedRaster <float> iirNDVI = new InterestedRaster <float>(idNDVI, new Size(dataProvider.Width, dataProvider.Height), dataProvider.CoordEnvelope.Clone(), dataProvider.SpatialRef);

            //iirNDVI.SetExtHeader(setValue);
            iirNDVI.Put(ndvi);
            iirNDVI.Dispose();
        }
Example #3
0
 private Dictionary <int, BagFeature> GetDisplayInfo(IPixelIndexMapper result, int visiBandNo, int niBandNo)
 {
     if (_argumentProvider.DataProvider == null)
     {
         return(null);
     }
     try
     {
         Dictionary <int, BagFeature> features   = new Dictionary <int, BagFeature>();
         BagFeature                  tempFeature = null;
         ArgumentProvider            ap          = new ArgumentProvider(_argumentProvider.DataProvider, null);
         RasterPixelsVisitor <Int16> visitor     = new RasterPixelsVisitor <Int16>(ap);
         visitor.VisitPixel(new int[] { visiBandNo, niBandNo },
                            (index, values) =>
         {
             tempFeature      = new BagFeature();
             tempFeature.Ndvi = GetOnePixelNDVI(values[0], values[1]);
             features.Add(index, tempFeature);
         });
         return(features);
     }
     finally
     {
     }
 }
Example #4
0
        /// <summary>
        /// execute indicator
        /// </summary>
        /// <param name="argument"></param>
        /// <returns></returns>
        public bool?Indicate(ArgumentProvider argument)
        {
            var actual   = argument.Format(Actual);
            var expected = Expected.Select(x => argument.Format(x));

            var match = expected.Any(x => string.Equals(actual, x, StringComparison.CurrentCultureIgnoreCase));

            if (Not)
            {
                match = !match;
            }

            if (match)
            {
                if (IsSuccess)
                {
                    return(true);
                }
                else if (IsFail)
                {
                    return(false);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Example #5
0
        /// <summary>
        /// execute
        /// </summary>
        /// <param name="actionSetting"></param>
        /// <param name="argument"></param>
        /// <returns></returns>
        public Task <ActionExecuteResult> Execute(string actionSetting, ArgumentProvider argument)
        {
            var setting = JsonConvert.DeserializeObject <PeekListActionSetting>(actionSetting);

            var listJson = argument.Format(setting.Source);

            try
            {
                var list    = JsonHelper.GetArray(listJson, setting.Source);
                var results = new List <JToken>();
                foreach (var listItem in list)
                {
                    var tmpArgument = new ArgumentProvider(argument.WorkingArguments.Copy());
                    tmpArgument.ClearKey("sourceItem");
                    tmpArgument.PutPrivate("sourceItem", listItem.ToString());
                    if (setting?.Where?.Any() != true || setting?.Where?.Any(x => x.Indicate(tmpArgument) ?? false) == true)
                    {
                        string targetValue = tmpArgument.Format(setting.Target, true);
                        if (setting.AsString)
                        {
                            results.Add(targetValue);
                        }
                        else
                        {
                            var valueObj = JsonHelper.TryGetObject(targetValue, setting.Target);
                            if (valueObj == null)
                            {
                                results.Add(targetValue);
                            }
                            else
                            {
                                targetValue = JsonConvert.SerializeObject(valueObj);
                                results.Add(valueObj);
                            }
                        }
                    }
                }

                var resultStr = JsonConvert.SerializeObject(results);
                return(Task.FromResult(new ActionExecuteResult
                {
                    Success = true,
                    Output = new Dictionary <string, string> {
                        { "result", resultStr }
                    },
                    Data = resultStr
                }));
            }
            catch (Exception ex)
            {
                return(Task.FromResult(new ActionExecuteResult
                {
                    Fail = true,
                    Message = ex.Message,
                    Output = new Dictionary <string, string> {
                    },
                    Data = string.Empty
                }));
            }
        }
Example #6
0
 private IExtractResult CalcOPTDByOneFile(Dictionary <string, FilePrdMap> filePrdMap, IVirtualRasterDataProvider vrd, float extinctionCoefficient, int visibleCH, double visibleZoom, double OptdZoom)
 {
     try
     {
         ArgumentProvider            ap        = new ArgumentProvider(vrd, null);
         RasterPixelsVisitor <float> rpVisitor = new RasterPixelsVisitor <float>(ap);
         IPixelFeatureMapper <Int16> curOPTD   = new MemPixelFeatureMapper <Int16>("OPTD", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
         float upRef = 0f;
         rpVisitor.VisitPixel(new int[] { filePrdMap["CurrentRasterFile"].StartBand,
                                          filePrdMap["csrFile"].StartBand,
                                          filePrdMap["dvlbFile"].StartBand },
                              (index, values) =>
         {
             if (values[2] == 1f)
             {
                 upRef = values[0] - Convert.ToSingle(values[1] * Math.Pow((1 - (values[0] / visibleZoom)), 2));
                 curOPTD.Put(index, (Int16)(upRef * (1 / extinctionCoefficient) / ((visibleZoom - upRef) * 3) * OptdZoom));
             }
             else
             {
                 curOPTD.Put(index, 0);
             }
         });
         return(curOPTD);
     }
     finally
     {
         vrd.Dispose();
     }
 }
Example #7
0
        /// <summary>
        /// 全球火点LDF转换Dat
        /// </summary>
        public void writeGFR()
        {
            IRasterDataProvider dp = RasterDataDriver.Open(@"L:\新演示数据\01_火情\全球火点\FIR_FREQ_FY3B_VIRR_1D_GBAL_PXXX_1000KM_201304250941.ldf") as IRasterDataProvider;
            Size size = new Size(dp.Width, dp.Height);
            IPixelFeatureMapper <Int16> result = new MemPixelFeatureMapper <Int16>("FIR", dp.Width * dp.Height, size, dp.CoordEnvelope, dp.SpatialRef);
            RasterIdentify id = new RasterIdentify(dp.fileName);

            id.ThemeIdentify         = "CMA";
            id.ProductIdentify       = "FIR";
            id.SubProductIdentify    = "GFRF";
            id.IsOutput2WorkspaceDir = true;
            IArgumentProvider            ap      = new ArgumentProvider(dp, null);
            RasterPixelsVisitor <UInt16> visitor = new RasterPixelsVisitor <UInt16>(ap);

            visitor.VisitPixel(new int[] { 1 },
                               (index, values) =>
            {
                result.Put(index, (Int16)values[0]);
            });
            using (IInterestedRaster <Int16> iir = new InterestedRaster <Int16>(id, size, dp.CoordEnvelope.Clone(), dp.SpatialRef))
            {
                iir.Put(result);
                string filename = iir.FileName;
            }
        }
Example #8
0
        /// <summary>
        /// 计算总覆盖度
        /// 总覆盖度=(有蓝藻的像元面积)/(指定区域面积,例如太湖);
        /// </summary>
        /// <returns>覆盖度(0-1)</returns>
        public float StatTotalConvertDegree(IRasterDataProvider dataProvider, int[] aoi)
        {
            int convertedCount = 0;

            bool[]                      convertedPixels = new bool[aoi.Length];
            int                         i       = 0;
            Size                        size    = new Size(dataProvider.Width, dataProvider.Height);
            Rectangle                   rect    = AOIHelper.ComputeAOIRect(aoi, size);
            ArgumentProvider            ap      = new ArgumentProvider(dataProvider, null);
            RasterPixelsVisitor <float> visitor = new RasterPixelsVisitor <float>(ap);

            visitor.VisitPixel(rect, aoi, new int[] { 1 }, (index, values) =>
            {
                if (values[0] >= 0f && values[0] <= 1f)
                {
                    convertedPixels[i] = true;
                    i++;
                }
            });
            foreach (bool isConverted in convertedPixels)
            {
                if (isConverted)
                {
                    convertedCount++;
                }
            }
            return((float)convertedCount / (float)convertedPixels.Length);
        }
Example #9
0
        public void btnGetInfos_Click(object sender, EventArgs e)
        {
            if (_arp != null)
            {
                double lstBandRoom      = (double)_arp.GetArg("lstband_Zoom");
                IRasterDataProvider prd = _arp.DataProvider;
                if (prd == null)
                {
                    return;
                }
                IBandNameRaster bandNameRaster = prd as IBandNameRaster;
                int             lstbandNo      = TryGetBandNo(bandNameRaster, "lstband");
                if (lstbandNo == -1 || lstBandRoom == -1)
                {
                    return;
                }
                ArgumentProvider ap   = new ArgumentProvider(prd, null);
                Size             size = new Size(prd.Width, prd.Height);
                if (_arp.AOIs != null && _arp.AOIs.Length != 0)
                {
                    txtIdenfiy.Text = GetInfoExt(_arp.AOIs);
                }
                Rectangle rect = AOIHelper.ComputeAOIRect(_arp.AOI, size);
                Dictionary <string, Dictionary <string, float> > anlysis = new Dictionary <string, Dictionary <string, float> >();
                InitAnlysisInfo(anlysis);
                int     count         = 0;
                Int16[] cloudValues   = GetNanValues("CloudyValue");
                Int16[] waterValues   = GetNanValues("WaterValue");
                Int16[] invaildValues = GetNanValues("InvailValue");
                using (RasterPixelsVisitor <Int16> visitor = new RasterPixelsVisitor <Int16>(ap))
                {
                    visitor.VisitPixel(rect, _arp.AOI, new int[] { lstbandNo },
                                       (index, values) =>
                    {
                        if (IsNanValue(values[0], cloudValues) || IsNanValue(values[0], waterValues) || IsNanValue(values[0], invaildValues))
                        {
                            return;
                        }
                        AnlysisValues(anlysis, "地表温度", values[0]);
                        count++;
                    });
                }
                anlysis["地表温度"]["avg"] = (float)Math.Round(anlysis["地表温度"]["avg"] / count, 4);
                using (RasterPixelsVisitor <Int16> visitor = new RasterPixelsVisitor <Int16>(ap))
                {
                    visitor.VisitPixel(rect, _arp.AOI, new int[] { lstbandNo },
                                       (index, values) =>
                    {
                        anlysis["地表温度"]["pc"] += (float)Math.Pow(values[0] - anlysis["地表温度"]["avg"], 2);
                    });
                }
                anlysis["地表温度"]["pc"] = (float)Math.Round(Math.Sqrt(anlysis["地表温度"]["pc"]) / count, 4);

                StringBuilder sb = new StringBuilder();
                sb.Append(string.Format("地表温度:\n  最小值:{0}\n  最大值:{1}\n  平均值:{2}\n  偏差值:{3}\n", anlysis["地表温度"]["min"], anlysis["地表温度"]["max"], anlysis["地表温度"]["avg"], anlysis["地表温度"]["pc"]));
                txtInfos.Text = sb.ToString();
            }
        }
Example #10
0
 private string ParseSentenceForArgs(string text)
 {
     for (int i = 1; text.Contains("%" + i + "%"); i++)
     {
         ArgumentProvider argProv = _caller.GetComponent <ArgumentProvider>();
         text = text.Replace("%" + i + "%", argProv.GetArgument(i));
     }
     return(text);
 }
Example #11
0
        //public override void SetExtHeader(IExtHeaderSetter setter, object header)
        //{
        //    if (setter == null || header == null)
        //        return;
        //    setter.SetExtHeader<NDVISetValue>((NDVISetValue)header);
        //}

        private IPixelFeatureMapper <float> ComputeNDVIResult(IRasterDataProvider orbitDataProvider, IPixelIndexMapper result, int visiBandNo, int niBandNo)
        {
            //生成判识结果文件
            IRasterDataProvider        batDataProvider = null;
            IInterestedRaster <UInt16> iir             = null;

            try
            {
                RasterIdentify id = new RasterIdentify();
                id.ThemeIdentify      = "CMA";
                id.ProductIdentify    = "BAG";
                id.SubProductIdentify = "DBLV";
                id.Sensor             = orbitDataProvider.DataIdentify.Sensor;
                id.Satellite          = orbitDataProvider.DataIdentify.Satellite;
                id.OrbitDateTime      = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
                id.GenerateDateTime   = DateTime.Now;
                iir = new InterestedRaster <UInt16>(id, new Size(orbitDataProvider.Width, orbitDataProvider.Height), orbitDataProvider.CoordEnvelope.Clone());
                int[] idxs = result.Indexes.ToArray();
                iir.Put(idxs, 1);
                batDataProvider = iir.HostDataProvider;
                //内存结果
                IPixelFeatureMapper <float> memresult = new MemPixelFeatureMapper <float>("NDVI", 1000, new Size(batDataProvider.Width, batDataProvider.Height), batDataProvider.CoordEnvelope, batDataProvider.SpatialRef);
                //虚拟文件
                //转换IRasterDataProvider!!!!!
                IVirtualRasterDataProvider  vrd     = new VirtualRasterDataProvider(new IRasterDataProvider[] { batDataProvider, orbitDataProvider });
                ArgumentProvider            ap      = new ArgumentProvider(vrd, null);
                RasterPixelsVisitor <Int16> visitor = new RasterPixelsVisitor <Int16>(ap);
                visitor.VisitPixel(new int[] { 1, visiBandNo + 1, niBandNo + 1 },
                                   (index, values) =>
                {
                    if (values[0] == 0)
                    {
                        memresult.Put(index, -9999);
                    }
                    else
                    {
                        memresult.Put(index, GetOnePixelNDVI(values[1], values[2]));
                    }
                });
                iir.Dispose();
                return(memresult);
            }
            finally
            {
                if (batDataProvider != null)
                {
                    batDataProvider.Dispose();
                }
                if (File.Exists(iir.FileName))
                {
                    File.Delete(iir.FileName);
                }
            }
        }
Example #12
0
 private void button4_Click(object sender, EventArgs e)
 {
     string fname               = @"f:\\FY3A_Mersi_2010_06_24_10_00_1000M_L1B_PRJ_Whole.LDF";
     IRasterDataProvider prd    = GeoDataDriver.Open(fname) as IRasterDataProvider;
     ArgumentProvider    argPrd = new ArgumentProvider(prd, null);
     //ThresholdExtracter<UInt16> ext = new ThresholdExtracter<ushort>(argPrd);
     //Stopwatch sw = new Stopwatch();
     //sw.Start();
     //ext.Extract(new int[] { 1, 2, 3 }, new Action<int, UInt16[]>(Extract));
     //sw.Stop();
     //Text = sw.ElapsedMilliseconds.ToString();
 }
Example #13
0
        private IStatResult STATAlgorithm(string filename)
        {
            string[] files = new string[] { filename };
            if (files == null || files.Length == 0)
            {
                return(null);
            }
            string mixFile = files[0].Replace("_DBLV_", "_0MIX_").Replace("_FLOD_", "_0MIX_");
            Dictionary <int, Int16> mixDic = new Dictionary <int, short>();

            if (File.Exists(mixFile))
            {
                using (IRasterDataProvider rd = GeoDataDriver.Open(mixFile) as IRasterDataProvider)
                {
                    ArgumentProvider            ap        = new ArgumentProvider(rd, null);
                    RasterPixelsVisitor <Int16> rpVisitor = new RasterPixelsVisitor <Int16>(ap);
                    rpVisitor.VisitPixel(new int[] { 1 },
                                         (idx, values) =>
                    {
                        if (values[0] != 0)
                        {
                            mixDic.Add(idx, values[0]);
                        }
                    });
                }
            }
            if (mixDic.Count == 0)
            {
                return(AreaStatResultToStatResult <Int16>(filename, "水情", "FLD", (v) => { return v == 1; }));
            }
            else
            {
                return(AreaStatResultToStatResult <Int16>(filename, "水情", "FLD", (v, idx) =>
                {
                    if (v == 1)
                    {
                        if (mixDic.ContainsKey(idx))
                        {
                            return mixDic[idx];
                        }
                        else
                        {
                            return 100;
                        }
                    }
                    else
                    {
                        return 0;
                    }
                }, 100));
            }
        }
Example #14
0
        private void button13_Click(object sender, EventArgs e)
        {
            //构造参数提供者
            string fname = @"f:\\FY3A_Mersi_2010_06_24_10_00_1000M_L1B_PRJ_Whole.LDF";

            fname = @"F:\MERSI\评审火情用\EI2040714.ldf";
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("a", 315);
            IRasterDataProvider prd    = GeoDataDriver.Open(fname) as IRasterDataProvider;
            ArgumentProvider    argprd = new ArgumentProvider(prd, args);
            //构造判识表达式
            string express = "(band3 / 10f > var_a)";

            int[] bandNos = new int[] { 3 };
            //构造基于阈值的判识器
            IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();

            extracter.Reset(argprd, bandNos, express);
            //判识
            //result = PixelIndexMapperFactory.CreatePixelIndexMapper("Fire",prd.Width,prd.Height);
            //Stopwatch sw = new Stopwatch();
            //sw.Start();
            //extracter.Extract(result);
            //idxs = result.Indexes.ToArray();
            //sw.Stop();
            //Text = sw.ElapsedMilliseconds.ToString();
            //判识结果生成二值位图
            IBinaryBitmapBuilder builder = new BinaryBitmapBuilder();
            Size   bmSize = new Size(prd.Width, prd.Height);
            Bitmap bitmap = builder.CreateBinaryBitmap(bmSize, Color.Red, Color.Transparent);

            builder.Fill(idxs, new Size(prd.Width, prd.Height), ref bitmap);
            bitmap.Save("f:\\1.png", ImageFormat.Png);
            //判识结果永久保存
            RasterIdentify id = new RasterIdentify();

            id.ThemeIdentify      = "CMA";
            id.ProductIdentify    = "FIR";
            id.SubProductIdentify = "2VAL";
            id.Satellite          = "FY3A";
            id.Sensor             = "MERSI";
            id.Resolution         = "250M";
            id.OrbitDateTime      = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
            id.GenerateDateTime   = DateTime.Now;
            IInterestedRaster <UInt16> iir = new InterestedRaster <UInt16>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone());

            iir.Put(idxs, 1);
            iir.Dispose();
            //sw.Stop();
            //Text = sw.ElapsedMilliseconds.ToString();
        }
Example #15
0
        private void button11_Click(object sender, EventArgs e)
        {
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("a", 300);
            args.Add("b", 230);
            ArgumentProvider argPrd  = new ArgumentProvider(null, args);
            string           express = "(band1 > var_a) && (band2 > var_b)";

            int[] visitBandNos = new int[] { 6, 2, 1 };
            IExtractFuncProvider <UInt16> funprd = ExtractFuncProviderFactory.CreateExtractFuncProvider <UInt16>(visitBandNos, express, argPrd);
            Func <int, UInt16[], bool>    f      = funprd.GetBoolFunc();
        }
Example #16
0
        private IExtractResult CalcOPTDByOneFile(IRasterDataProvider prd, double lwpa, double lwpb, int optdCH, double OptdZoom, double lwpZoom)
        {
            ArgumentProvider            ap        = new ArgumentProvider(prd, null);
            RasterPixelsVisitor <Int16> rpVisitor = new RasterPixelsVisitor <Int16>(ap);
            IPixelFeatureMapper <Int16> curLWP    = new MemPixelFeatureMapper <Int16>("0LWP", 1000, new Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef);

            rpVisitor.VisitPixel(new int[] { optdCH },
                                 (index, values) =>
            {
                curLWP.Put(index, (Int16)Convert.ToSingle(Math.Pow(10, Math.Exp((Math.Log10(values[0] / OptdZoom - lwpa) / lwpb))) * lwpZoom));
            });
            return(curLWP);
        }
Example #17
0
        private IExtractResult CalcOPTDByOneFile(IVirtualRasterDataProvider vrd, IRasterDataProvider optdPrd, int optdCH, double OptdZoom, int lwpCH, double lwpZoom)
        {
            ArgumentProvider            ap        = new ArgumentProvider(vrd, null);
            RasterPixelsVisitor <Int16> rpVisitor = new RasterPixelsVisitor <Int16>(ap);
            IPixelFeatureMapper <Int16> curERAD   = new MemPixelFeatureMapper <Int16>("ERAD", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);

            rpVisitor.VisitPixel(new int[] { optdCH, optdPrd.BandCount + lwpCH },
                                 (index, values) =>
            {
                curERAD.Put(index, (Int16)(3 / 2 * ((values[1] / lwpZoom) / 1 * (values[0] / OptdZoom))));
            });
            return(curERAD);
        }
Example #18
0
        private void button14_Click(object sender, EventArgs e)
        {
            //构造参数提供者
            string fname               = @"f:\\FY3A_Mersi_2010_06_24_10_00_1000M_L1B_PRJ_Whole.LDF";
            IRasterDataProvider prd    = GeoDataDriver.Open(fname) as IRasterDataProvider;
            ArgumentProvider    argprd = new ArgumentProvider(prd, null);
            //构造判识表达式
            //string express = "(band4 + band3) == 0? 0f : (band4 - band3) / (float)(band4 + band3)";
            string express = "NDVI(band4,band3)";

            int[] bandNos = new int[] { 4, 3 };
            //构造栅格计算判识器
            IRasterExtracter <UInt16, float> extracter = new SimpleRasterExtracter <UInt16, float>();

            extracter.Reset(argprd, bandNos, express);
            //判识
            resultNDVI = new MemPixelFeatureMapper <float>("NDVI", 1000, new Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            extracter.Extract(resultNDVI);
            //sw.Stop();
            //Text = sw.ElapsedMilliseconds.ToString();
            //判识结果生成二值位图
            //IBinaryBitmapBuilder builder = new BinaryBitmapBuilder();
            //Size bmSize = new Size(prd.Width / 2, prd.Height / 2);
            //Bitmap bitmap = builder.CreateBinaryBitmap(bmSize, Color.Red, Color.Transparent);
            //builder.Fill(idxs, new Size(prd.Width, prd.Height), ref bitmap);
            //bitmap.Save("f:\\1.png", ImageFormat.Png);
            //判识结果永久保存
            RasterIdentify id = new RasterIdentify();

            id.ThemeIdentify      = "CMA";
            id.ProductIdentify    = "FIR";
            id.SubProductIdentify = "NDVI";
            id.Satellite          = "FY3A";
            id.Sensor             = "MERSI";
            id.Resolution         = "250M";
            id.OrbitDateTime      = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
            id.GenerateDateTime   = DateTime.Now;
            IInterestedRaster <float> iir = new InterestedRaster <float>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone());

            iir.Put(resultNDVI);
            iir.Dispose();
            sw.Stop();
            Text = sw.ElapsedMilliseconds.ToString();

            int count = iir.Count(aoi, (v) => { return(v == 1); });

            iir.Count(aoi, (v) => { return((int)v); });
        }
Example #19
0
        public static Dictionary <float, List <float> > NDVIHistograms(TVDIUCArgs ucArgs)
        {
            string error = string.Empty;

            if (!CheckHistograms(ucArgs, ref error))
            {
                return(null);
            }
            Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();

            filePrdMap.Add("NDVIFile", new FilePrdMap(ucArgs.NDVIFile, ucArgs.TVDIParas.NdviFile.Zoom, new VaildPra(ucArgs.TVDIParas.NdviFile.Min, ucArgs.TVDIParas.NdviFile.Max), new int[] { ucArgs.TVDIParas.NdviFile.Band }));
            filePrdMap.Add("LSTFile", new FilePrdMap(ucArgs.ECLstFile, ucArgs.TVDIParas.LstFile.Zoom, new VaildPra(ucArgs.TVDIParas.LstFile.Min, ucArgs.TVDIParas.LstFile.Max), new int[] { 1 }));

            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            IVirtualRasterDataProvider vrd     = null;

            try
            {
                vrd = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);
                if (vrd == null)
                {
                    throw new Exception("数据间无相交部分,无法创建虚拟数据提供者!");
                }
                Dictionary <float, List <float> > result = new Dictionary <float, List <float> >();
                ArgumentProvider            ap           = new ArgumentProvider(vrd, null);
                RasterPixelsVisitor <float> rpVisitor    = new RasterPixelsVisitor <float>(ap);
                TVDIParaClass tvdiP = ucArgs.TVDIParas;
                IPixelFeatureMapper <float> _result = new MemPixelFeatureMapper <float>("0DWE", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
                float ndvizoom = tvdiP.NdviFile.Zoom;
                float lstZoom  = tvdiP.LstFile.Zoom;
                rpVisitor.VisitPixel(new int[] { filePrdMap["NDVIFile"].StartBand,
                                                 filePrdMap["LSTFile"].StartBand },
                                     (index, values) =>
                {
                    if (values[1] >= tvdiP.LstFile.Min / lstZoom && values[1] <= tvdiP.LstFile.Max / lstZoom &&
                        values[0] >= tvdiP.NdviFile.Min / ndvizoom && values[0] <= tvdiP.NdviFile.Max / ndvizoom)
                    {
                        if (!result.ContainsKey(values[0]))
                        {
                            result.Add(values[0], new List <float>());
                        }
                        result[values[0]].Add(values[1]);
                    }
                });
                return(result.Count == 0 ? null : result);
            }
            finally
            {
                vrd.Dispose();
            }
        }
Example #20
0
        public void TestEventBody()
        {
            WorkingArguments workingArguments = new WorkingArguments();
            ArgumentProvider argProvider      = new ArgumentProvider(workingArguments);

            argProvider.PutPrivate("lastCheckResult", "{\"data\":null,\"success\":false,\"code\":null,\"message\":\"Cannot get any products by style number: [20200122].\",\"exception\":null}");
            argProvider.PutPrivate("now", "2019/12/11T09:00:00.000Z");
            argProvider.PutPrivate("input.merchantOrderId", "merchantOrderId");
            var targetStr = "{\"message\":\"{\\\"name\\\":\\\"InvalidOrder\\\",\\\"time\\\":\\\"2019/12/11T09:00:00.000Z\\\",\\\"data\\\":{\\\"orderId\\\":\\\"merchantOrderId\\\",\\\"messages\\\":{\\\"data\\\":null,\\\"success\\\":false,\\\"code\\\":null,\\\"message\\\":\\\"Cannot get any products by style number: [20200122].\\\",\\\"exception\\\":null}}}\"}";

            var setProcessor = new SetValueProcessor();
            var setSetting1  = new SetValueActionSetting
            {
                Set = new Dictionary <string, string> {
                    { "orderId", "{{input.merchantOrderId}}" },
                    { "messages", "{{lastCheckResult}}" }
                }
            };
            var res1 = setProcessor.Execute(JsonConvert.SerializeObject(setSetting1), argProvider).Result;

            argProvider.PutPrivate("event_msg_data", res1.Data);

            var setSetting2 = new SetValueActionSetting
            {
                Set = new Dictionary <string, string> {
                    { "name", "InvalidOrder" },
                    { "time", "{{now}}" },
                    { "data", "{{event_msg_data}}" }
                }
            };
            var res2 = setProcessor.Execute(JsonConvert.SerializeObject(setSetting2), argProvider).Result;

            argProvider.PutPrivate("event_msg", res2.Data);

            var setSetting3 = new SetValueActionSetting
            {
                Set = new Dictionary <string, string> {
                    { "message", "{{event_msg}}" }
                },
                AsString = true
            };
            var res3 = setProcessor.Execute(JsonConvert.SerializeObject(setSetting3), argProvider).Result;

            argProvider.PutPrivate("event_body", res3.Data);


            var resultStr = argProvider.Format("{{event_body}}");

            Assert.AreEqual(targetStr, resultStr);
        }
 public override IExtractResult Make(Action <int, string> progressTracker)
 {
     if (_argumentProvider == null || _argumentProvider.DataProvider == null)
     {
         return(null);
     }
     if (_argumentProvider.GetArg("AlgorithmName") == null)
     {
         return(null);
     }
     if (_argumentProvider.GetArg("AlgorithmName").ToString() == "0MIX")
     {
         float    fldValue      = 0;
         float    landValue     = 0;
         string[] nearInfValues = _argumentProvider.GetArg("NearInfraredValues") as string[];
         if (nearInfValues == null || nearInfValues.Count() != 2)
         {
             return(null);
         }
         if (!float.TryParse(nearInfValues[0], out fldValue) || !float.TryParse(nearInfValues[1], out landValue))
         {
             return(null);
         }
         int    bandNo                        = (int)_argumentProvider.GetArg("NearInfrared");
         double nearInfraredZoom              = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
         IRasterDataProvider          prd     = _argumentProvider.DataProvider;
         IPixelFeatureMapper <UInt16> result  = new MemPixelFeatureMapper <UInt16>("0MIX", prd.Width * prd.Height, new Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef);
         ArgumentProvider             ap      = new ArgumentProvider(prd, null);
         RasterPixelsVisitor <Int16>  visitor = new RasterPixelsVisitor <Int16>(ap);
         if (fldValue == landValue)
         {
             visitor.VisitPixel(new int[] { bandNo },
                                (index, values) =>
             {
                 result.Put(index, 0);
             });
             return(result);
         }
         visitor.VisitPixel(new int[] { bandNo },
                            (index, values) =>
         {
             UInt16 percentValue = (UInt16)GetMixPixelPercent(values[0], fldValue, landValue);
             result.Put(index, percentValue);
         });
         return(result);
     }
     return(null);
 }
Example #22
0
        //通过读取历史判识文件获取AOI
        private void 能见度计算file_Click(object sender, EventArgs e)
        {
            InitExIdentify();
            _exPro.SubProductIdentify = "VISY";
            _sub             = _pro.GetSubProductDefByIdentify("VISY");
            _exAlg.Satellite = "FY3A";
            _exAlg.Sensor    = "VIRR";
            AlgorithmDef      visiAlg = _sub.GetAlgorithmDefByIdentify("Visibility");
            IArgumentProvider visiArg = MonitoringThemeFactory.GetArgumentProvider(_exPro, _exAlg);

            IRasterDataProvider          prd    = GetRasterDataProviderBinaryFile();
            Dictionary <string, object>  args   = new Dictionary <string, object>();
            IArgumentProvider            argPrd = new ArgumentProvider(prd, args);
            RasterPixelsVisitor <UInt16> raster = new RasterPixelsVisitor <UInt16>(argPrd);
            List <int> idxs = new List <int>();

            raster.VisitPixel(new int[] { 1 }, (index, value) =>
            {
                if (value[0] != 0)
                {
                    idxs.Add(index);
                }
            });

            visiArg.DataProvider = GetRasterDataProviderVIRR();
            visiArg.AOI          = idxs.ToArray();
            visiArg.SetArg("Visibility", visiAlg);
            SubProductRasterDst          subraster    = new SubProductRasterDst(_sub);
            IPixelFeatureMapper <UInt16> rasterResult = subraster.Make(null) as IPixelFeatureMapper <UInt16>;

            //
            RasterIdentify id = new RasterIdentify();

            id.ThemeIdentify      = "CMA";
            id.ProductIdentify    = "SAND";
            id.SubProductIdentify = "VISIBILITY";
            id.Satellite          = "FY3A";
            id.Sensor             = "VIRRX";
            id.Resolution         = "1000M";
            id.OrbitDateTime      = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
            id.GenerateDateTime   = DateTime.Now;
            IInterestedRaster <UInt16> iir = new InterestedRaster <UInt16>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone());

            iir.Put(rasterResult);
            iir.Dispose();

            MessageBox.Show("能见度计算完成!");
        }
Example #23
0
        /// <summary>
        /// execute
        /// </summary>
        /// <param name="actionSetting"></param>
        /// <param name="argument"></param>
        /// <returns></returns>
        public Task <ActionExecuteResult> Execute(string actionSetting, ArgumentProvider argument)
        {
            var setting = JsonConvert.DeserializeObject <MapListActionSetting>(actionSetting);

            var listJson = argument.Format(setting.Source);

            try
            {
                var list    = JsonHelper.GetArray(listJson, setting.Source);
                var results = new List <Dictionary <string, string> >();
                foreach (var listItem in list)
                {
                    var tmpArgument = new ArgumentProvider(argument.WorkingArguments.Copy());
                    tmpArgument.ClearKey("mapItem");
                    tmpArgument.PutPrivate("mapItem", listItem.ToString());
                    if (setting?.Where?.Any() != true || setting?.Where?.Any(x => x.Indicate(tmpArgument) ?? false) == true)
                    {
                        Dictionary <string, string> result = new Dictionary <string, string>();
                        foreach (var rule in setting.Output)
                        {
                            result.Add(rule.Key, tmpArgument.Format(rule.Value, true));
                        }
                        results.Add(result);
                    }
                }

                var resultStr = JsonConvert.SerializeObject(results);
                return(Task.FromResult(new ActionExecuteResult
                {
                    Success = true,
                    Output = new Dictionary <string, string> {
                        { "result", resultStr }
                    },
                    Data = resultStr
                }));
            }
            catch (Exception ex)
            {
                return(Task.FromResult(new ActionExecuteResult
                {
                    Fail = true,
                    Message = ex.Message,
                    Output = new Dictionary <string, string> {
                    },
                    Data = string.Empty
                }));
            }
        }
        public override void Execute(ArgumentProvider provider)
        {
            var version = GetVersion();
            var name    = "Migration" + version;

            var content = File.ReadAllText(MigrationTemplate);

            content = string.Format(content, version, name);

            var file = File.Create(MigrationDirectory + name + FileExtension);

            file.Write(Encoding.ASCII.GetBytes(content));
            file.Flush();

            Console.WriteLine($"Migration {version} was generated.");
        }
Example #25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkflowLogger" /> class.
        /// </summary>
        /// <param name="workflow">The value for the <see cref="WorkflowLogger.Workflow" /> property.</param>
        /// <param name="argProvider">The value for the <see cref="WorkflowLogger.ProviderOfArguments" /> property.</param>
        /// <param name="isThreadSafe">Object is thread safe or not.</param>
        /// <param name="syncRoot">The unique object for sync operations.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="workflow" />, <paramref name="argProvider" /> and/or <paramref name="syncRoot" /> are <see langword="null" />.
        /// </exception>
        public WorkflowLogger(IWorkflow workflow, ArgumentProvider argProvider, bool isThreadSafe, object syncRoot)
            : base(isThreadSafe, syncRoot)
        {
            if (workflow == null)
            {
                throw new ArgumentNullException("workflow");
            }

            if (argProvider == null)
            {
                throw new ArgumentNullException("argProvider");
            }

            this._WORKFLOW = workflow;
            this._PROVIDER_OF_ARGUMENTS = argProvider;
        }
Example #26
0
        private void button5_Click(object sender, EventArgs e)
        {
            string fname = @"f:\\FY3A_Mersi_2010_06_24_10_00_1000M_L1B_PRJ_Whole.LDF";
            //fname = @"f:\\FY3A_MERSI_2010_06_24_10_00_1000M_L1B - 副本.HDF";
            IRasterDataProvider          prd    = GeoDataDriver.Open(fname) as IRasterDataProvider;
            ArgumentProvider             argPrd = new ArgumentProvider(prd, null);
            RasterPixelsVisitor <UInt16> ext    = new RasterPixelsVisitor <ushort>(argPrd);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            ext.VisitPixelWnd(new int[] { 1 }, new int[] { 5 },
                              3, 9, new Func <int, int, ushort[], ushort[][], bool>(IsNeedIncWndSize),
                              new Action <int, int, ushort[], ushort[][]>(Extract));
            sw.Stop();
            Text = sw.ElapsedMilliseconds.ToString();
        }
Example #27
0
        private double CompuCurPixel(string rasterFileName)
        {
            IRasterDataProvider         inRaster = RasterDataDriver.Open(rasterFileName) as IRasterDataProvider;
            ArgumentProvider            ap       = new ArgumentProvider(inRaster, null);
            RasterPixelsVisitor <float> visitor  = new RasterPixelsVisitor <float>(ap);
            double result = 0;

            visitor.VisitPixel(new int[] { 1 }, (index, values) =>
            {
                if (values[0] > 0)
                {
                    result += values[0];
                }
            });
            return(result);
        }
Example #28
0
        private string CombineCloudAndWater(string cloudFile, string waterFile)
        {
            IInterestedRaster <Int16> iir      = null;
            IRasterDataProvider       waterPrd = null;
            IRasterDataProvider       cloudPrd = null;

            try
            {
                RasterIdentify id = new RasterIdentify(waterFile);
                waterPrd = GeoDataDriver.Open(waterFile) as IRasterDataProvider;
                cloudPrd = GeoDataDriver.Open(cloudFile) as IRasterDataProvider;
                iir      = new InterestedRaster <Int16>(id, new Size(waterPrd.Width, waterPrd.Height), waterPrd.CoordEnvelope.Clone());
                //虚拟文件
                //转换IRasterDataProvider!!!!!
                IVirtualRasterDataProvider  vrd     = new VirtualRasterDataProvider(new IRasterDataProvider[] { waterPrd, cloudPrd });
                ArgumentProvider            ap      = new ArgumentProvider(vrd, null);
                RasterPixelsVisitor <Int16> visitor = new RasterPixelsVisitor <Int16>(ap);
                visitor.VisitPixel(new int[] { 1, 2 },
                                   (index, values) =>
                {
                    if (values[0] == 1)
                    {
                        iir.Put(index, 1);
                    }
                    else if (values[1] == 1)
                    {
                        iir.Put(index, -9999);
                    }
                });
                return(iir.FileName);
            }
            finally
            {
                if (iir != null)
                {
                    iir.Dispose();
                }
                if (waterPrd != null)
                {
                    waterPrd.Dispose();
                }
                if (cloudPrd != null)
                {
                    cloudPrd.Dispose();
                }
            }
        }
Example #29
0
        public void btnGetAOIIndex(object sender, EventArgs e)
        {
            this.AOIIndexs = _arp.AOI;

            //根据选定的AOI区域进行自动计算水体NDVI最小值
            IRasterDataProvider prd = _arp.DataProvider;
            int bandNI            = (int)_arp.GetArg("NearInfrared");
            int bandVI            = (int)_arp.GetArg("Visible");
            ArgumentProvider ap   = new ArgumentProvider(prd, null);
            Size             size = new Size(prd.Width, prd.Height);
            Rectangle        rect = AOIHelper.ComputeAOIRect(this.AOIIndexs, size);

            using (RasterPixelsVisitor <UInt16> visitor = new RasterPixelsVisitor <UInt16>(ap))
            {
                List <double> ndvis = new List <double>();
                visitor.VisitPixel(rect, this.AOIIndexs, new int[] { bandVI, bandNI },
                                   (index, values) =>
                {
                    if (values[1] + values[0] != 0)    //是判断两个值都不等0的意思?
                    {
                        ndvis.Add(Math.Round((float)(values[1] - values[0]) / (values[1] + values[0]), 4));
                    }
                });
                if (ndvis.Count >= 0)
                {
                    //设置界面值
                    float a = float.Parse(txta.Text);
                    float b = float.Parse(txtb.Text);
                    ndvis.Sort();                                    //从小到大排列
                    ndvis.RemoveRange(0, (int)(0.01 * ndvis.Count)); //去除百分之一最小值
                    float avgndvi = (float)ndvis.Min();
                    float MinNDVI = a * avgndvi + b;
                    this.txtNDVI.Text    = avgndvi.ToString();
                    this.txtminndvi.Text = MinNDVI.ToString();
                    this.txtndvimin.Text = MinNDVI.ToString();
                    this.NDVIMultiBar.SetValues(new double[] { this.txtndvimin.Value, this.txtndvimax.Value });
                }
            }
            this.ckbaoi.Checked = false;//重置状态
            //设置完成之后自动生成
            if (_handler != null)
            {
                _handler(GetArgumentValue());
                return;
            }
        }
        public override IExtractResult Make(Action <int, string> progressTracker)
        {
            if (_argumentProvider == null)
            {
                return(null);
            }
            string algname   = _argumentProvider.GetArg("AlgorithmName").ToString();
            string ndviFName = _argumentProvider.GetArg("mainfiles").ToString();

            if (string.IsNullOrEmpty(algname) || string.IsNullOrEmpty(ndviFName) || !File.Exists(ndviFName))
            {
                return(null);
            }
            if (algname == "BPCD")
            {
                //NDVI结果文件
                using (IRasterDataProvider ndviDataProvider = GeoDataDriver.Open(ndviFName) as IRasterDataProvider)
                {
                    NDVISetValue setValue = (ndviDataProvider as MemoryRasterDataProvider).GetExtHeader <NDVISetValue>();
                    double       minNDVI  = setValue.MinNDVI;
                    double       maxNDVI  = setValue.MaxNDVI;
                    double       dst      = maxNDVI - minNDVI;
                    IPixelFeatureMapper <float> memResult = new MemPixelFeatureMapper <float>("BPCD", 1000, new Size(ndviDataProvider.Width, ndviDataProvider.Height), ndviDataProvider.CoordEnvelope.Clone(), ndviDataProvider.SpatialRef);
                    ArgumentProvider            ap        = new ArgumentProvider(ndviDataProvider, null);
                    RasterPixelsVisitor <float> visitor   = new RasterPixelsVisitor <float>(ap);
                    visitor.VisitPixel(new int[] { 1 }, (index, values) =>
                    {
                        if (values[0] == -9999f)
                        {
                            memResult.Put(index, -9999);
                        }
                        else if (dst == 0)
                        {
                            memResult.Put(index, -9999);
                        }
                        else
                        {
                            memResult.Put(index, (float)((values[0] - minNDVI) / dst));
                        }
                    });
                    return(memResult);
                }
            }
            return(null);
        }