private Dictionary <string, double> StatArea(int[] aoi, Dictionary <string, Func <short, bool> > filters) { IRasterDrawing drawing = _activeViewer.Canvas.PrimaryDrawObject as IRasterDrawing; if (drawing == null) { return(null); } IRasterDataProvider prd = drawing.DataProvider; if (prd == null) { return(null); } RasterOperator <short> rs = new RasterOperator <short>(); if (_extractedPixels == null) { Dictionary <string, double> areas = rs.Area(prd, aoi, filters); return(areas); } else { double area = rs.Area(prd, _extractedPixels, aoi); Dictionary <string, double> areas = new Dictionary <string, double>(); areas.Add("判识面积", area); return(areas); } }
private IExtractResult TFRQAlgorithm(Action <int, string> progressTracker) { IRasterOperator <Int16> roper = new RasterOperator <Int16>(); IInterestedRaster <Int16> timeResult = null; string[] files = GetStringArray("SelectedPrimaryFiles"); if (files == null || files.Length == 0) { return(null); } RasterIdentify identify = new RasterIdentify(files); identify.SubProductIdentify = _subProductDef.Identify; int maxNum = 0; timeResult = roper.Times(files, identify, progressTracker, (dstValue, srcValue) => { dstValue += srcValue; if (maxNum < dstValue) { maxNum = dstValue; } return(dstValue); }); if (timeResult == null || maxNum == 0) { return(null); } double zoom = (double)_argumentProvider.GetArg("Zoom"); return(CalcTreq(timeResult, identify, maxNum, zoom)); }
private IExtractResult TFREAlgorithm(Action <int, string> progressTracker) { IRasterOperator <Int16> roper = new RasterOperator <Int16>(); IInterestedRaster <Int16> timeResult = null; string[] files = GetStringArray("SelectedPrimaryFiles"); if (files == null || files.Length == 0) { return(null); } RasterIdentify identify = new RasterIdentify(files); identify.SubProductIdentify = _subProductDef.Identify; timeResult = roper.Times(files, identify, progressTracker, (dstValue, srcValue) => { return((Int16)(dstValue + srcValue)); }); if (timeResult == null) { return(null); } timeResult.Dispose(); string workFilename = identify.ToWksFullFileName(".dat"); File.Copy(timeResult.FileName, workFilename, true); return(new FileExtractResult("FLD", workFilename, true)); }
private void button4_Click(object sender, EventArgs e) { string fname1 = "F:\\FIR_NDVI_FY3A_MERSI_250M_20120610164136_20120611164136.dat"; IRasterDataProvider prd = GeoDataDriver.Open(fname1) as IRasterDataProvider; IRasterOperator <float> oper = new RasterOperator <float>(); area = oper.Area(prd, null, (v) => { return(true); }); }
private void button2_Click(object sender, EventArgs e) { string fname1 = "F:\\FIR_NDVI_FY3A_MERSI_250M_20120610164136_20120611164136.dat"; string fname2 = "F:\\FIR_NDVI_FY3A_MERSI_250M_20120610164136_20120611164136 - 副本.dat"; IRasterOperator <float> oper = new RasterOperator <float>(); oper.Times(new string[] { fname1, fname2 }, new RasterIdentify(), (v1, v2) => { return(v1 + v2); }); }
/// <summary> /// 差值运算 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="aoi">感兴趣区域</param> /// <param name="fristFileName">被减数文件</param> /// <param name="secondFileName">减数文件</param> /// <param name="rasterIdentify">产品标识</param> /// <returns></returns> public static IExtractResult ChaZhi <T>(int[] aoi, string fristFileName, string secondFileName, RasterIdentify rasterIdentify) { IRasterOperator <float> rasterOperator = new RasterOperator <float>(); IInterestedRaster <float> resultRaster = rasterOperator.Compare(aoi, fristFileName, secondFileName, (beiJianShu, jianShu) => { return(beiJianShu - jianShu); }, rasterIdentify ); return(resultRaster); }
private StatResultItem[] AreaStat(object aoiObj, Func <Int16, bool> filter, string[] files) { if (files == null || files.Length == 0) { return(null); } IStatAnalysisEngine <Int16> exe = new StatAnalysisEngine <Int16>(); if (aoiObj as Dictionary <string, int[]> != null) { Dictionary <string, int[]> aoi = aoiObj as Dictionary <string, int[]>; List <StatResultItem> items = new List <StatResultItem>(); IRasterDataProvider prd = null; try { prd = GeoDataDriver.Open(files[0]) as IRasterDataProvider; if (aoi == null || aoi.Count == 0) { return(null); } StatResultItem[] item = exe.StatAreaCustom(prd, aoi, filter); if (item != null && item.Length > 0) { items.AddRange(item); } // RasterOperator <Int16> oper = new RasterOperator <Int16>(); int count = oper.Count(prd, null, filter); StatResultItem sri = new StatResultItem(); sri.Name = "整个湖区"; sri.Value = Math.Round(count * BAGStatisticHelper.CalPixelArea(prd.ResolutionX), 3); items.Add(sri); return(items.ToArray()); } catch { throw new ArgumentException("选择的文件:“" + Path.GetFileName(files[0]) + "”无法进行自定义面积统计。"); } finally { if (prd != null) { prd.Dispose(); prd = null; } } } else { return(null); } }
public static IExtractResult ComputeMinFile(string[] fnames, RasterIdentify rasterIdentify) { IRasterOperator <float> rasterOperator = new RasterOperator <float>(); IInterestedRaster <float> resultRaster = rasterOperator.Times(fnames, rasterIdentify, (value, valuei) => { if (valuei < value) { value = valuei; } return(value); } ); return(resultRaster); }
//计算亚像元面积 private double ComputeSecondPixelArea(int pixelIdx, ushort[] bandValues, out float pixelArea) { int row = pixelIdx / _width; pixelArea = (float)RasterOperator <UInt16> .ComputePixelArea(row, _maxLat, _res); PixelFeature fet = _features[pixelIdx]; float pvMidIfr = bandValues[_midIfrBandIdx] / _bandZoom; float pvFarIfr = bandValues[_farIfrBandIdx] / _bandZoom; double factor = 0; if (pvMidIfr < _maxMidIfrValue) { factor = 1.438833f * _midIfrCenterWaveNum / pvMidIfr * 10f; double n3Mix = (1.1910659 * Math.Pow(10, -5) * Math.Pow(_midIfrCenterWaveNum, 3)) / (Math.Pow(Math.E, factor) - 1f); factor = 1.438833f * _midIfrCenterWaveNum / _firComputeFactor; double n3bf = (1.1910659 * Math.Pow(10, -5) * Math.Pow(_midIfrCenterWaveNum, 3)) / (Math.Pow(Math.E, factor) - 1f); factor = 1.438833f * _midIfrCenterWaveNum / fet.MidIfrAvgValue * 10; double n3bt = (1.1910659 * Math.Pow(10, -5) * Math.Pow(_midIfrCenterWaveNum, 3)) / (Math.Pow(Math.E, factor) - 1f); return(pixelArea * (n3Mix - n3bt) / (n3bf - n3bt) * 100f); } else { if (pvFarIfr < fet.FarIfrAvgValue) { factor = 1.438833f * _farIfrCenterWaveNum / (fet.FarIfrAvgValue + 3) * 10f; } else { factor = 1.438833f * _farIfrCenterWaveNum / pvFarIfr * 10f; } double n4Mix = (1.1910659 * Math.Pow(10, -5) * Math.Pow(_farIfrCenterWaveNum, 3)) / (Math.Pow(Math.E, factor) - 1f); factor = 1.438833f * _farIfrCenterWaveNum / _firComputeFactor; double n4bf = (1.1910659 * Math.Pow(10, -5) * Math.Pow(_farIfrCenterWaveNum, 3)) / (Math.Pow(Math.E, factor) - 1f); factor = 1.438833f * _farIfrCenterWaveNum / fet.FarIfrAvgValue * 10f; double n4bt = (1.1910659 * Math.Pow(10, -5) * Math.Pow(_farIfrCenterWaveNum, 3)) / (Math.Pow(Math.E, factor) - 1f); if (n4Mix - n4bt < 0) { n4Mix = n4bt + 2f; } return(pixelArea * (n4Mix - n4bt) / (n4bf - n4bt) * 100f); } }
private double StatArea(int[] aoi) { IRasterDrawing drawing = _activeViewer.Canvas.PrimaryDrawObject as IRasterDrawing; if (drawing == null) { return(0); } IRasterDataProvider prd = drawing.DataProvider; if (prd == null) { return(0); } double retArea = 0; if (prd.CoordType == enumCoordType.GeoCoord) { Size size = new Size(prd.Width, prd.Height); int row = 0; double resX = prd.ResolutionX; double maxLat = prd.CoordEnvelope.MaxY; for (int i = 0; i < aoi.Length; i++) { row = aoi[i] / size.Width; retArea += RasterOperator <int> .ComputePixelArea(row, maxLat, resX); } } else if (prd.CoordType == enumCoordType.PrjCoord) { double pixelArea = prd.ResolutionX * prd.ResolutionY / 1000000;//平方公里 for (int i = 0; i < aoi.Length; i++) { retArea += pixelArea; } } else//raster pixelcount { retArea = aoi.Length; } return(retArea); }
private double CalcTotalArea(IRasterDataProvider dataProvider, int[] aoi, float minValue, float maxValue) { double convertArea = 0; IRasterOperator <Int16> rasterOper = new RasterOperator <Int16>(); int count = rasterOper.Count(dataProvider, aoi, (value) => { if (minValue < value && value <= maxValue) { return(true); } else { return(false); } }); convertArea = count * AreaCountHelper.CalcArea(dataProvider.ResolutionX, dataProvider.ResolutionY); return(convertArea / 1000000); }
/// <summary> /// 计算指定等级的总覆盖面积 /// 例如:重度(60%-100%) /// 比较条件为:minConvertDegree< x && x<= maxConvertDegree /// </summary> /// <param name="minConvertDegree"></param> /// <param name="maxConvertDegree"></param> /// <returns></returns> public double CalcTotalConvertArea(IRasterDataProvider dataProvider, float minCovertDegree, float maxCovertDegree, double pixelArea) { double convertArea = 0; IRasterOperator <float> rasterOper = new RasterOperator <float>(); int count = rasterOper.Count(dataProvider, null, (value) => { if (minCovertDegree < value && value <= maxCovertDegree) { return(true); } else { return(false); } }); convertArea = count * pixelArea; return(convertArea); }
/// <summary> /// 计算云覆盖面积 /// </summary> /// <returns></returns> public double CalcCloudConvertArea(IRasterDataProvider dataProvider, int[] aoi) { double cloudArea = 0; IRasterOperator <Int16> rasterOper = new RasterOperator <Int16>(); int count = rasterOper.Count(dataProvider, aoi, (value) => { if (value == 1) { return(true); } else { return(false); } }); double pixelArea = BAGStatisticHelper.CalPixelArea(dataProvider.ResolutionX); cloudArea = count * pixelArea; return(cloudArea); }
/// <summary> /// 计算指定等级的总覆盖面积 /// 例如:重度(60%-100%) /// 比较条件为:minConvertDegree< x && x<= maxConvertDegree /// </summary> /// <param name="minConvertDegree"></param> /// <param name="maxConvertDegree"></param> /// <returns></returns> public double CalcTotalConvertArea(IRasterDataProvider dataProvider, int[] aoi, float minCovertDegree, float maxCovertDegree) { double convertArea = 0; IRasterOperator <float> rasterOper = new RasterOperator <float>(); int count = rasterOper.Count(dataProvider, aoi, (value) => { if (minCovertDegree < value && value <= maxCovertDegree) { return(true); } else { return(false); } }); double pixelArea = BAGStatisticHelper.CalPixelArea(dataProvider.ResolutionX); convertArea = count * pixelArea; return(convertArea); }
/// <summary> /// 计算云覆盖度 /// </summary> /// <param name="dataProvider">云监测生成的判识结果文件</param> /// <param name="pixelCount">指定区域像素点个数(例如:太湖区域像素点总数)</param> /// <returns></returns> public float CalcCloudConvertDegree(IRasterDataProvider dataProvider, int[] aoi) { if (dataProvider == null || aoi.Count() == 0) { return(0); } long nCloud = 0; IRasterOperator <UInt16> rasterOper = new RasterOperator <UInt16>(); nCloud = rasterOper.Count(dataProvider, aoi, (value) => { if (value == 1) { return(true); } else { return(false); } }); return((float)nCloud / (float)aoi.Count()); }
/// <summary> /// 当期区域像素点频次统计(基于判识二值数据进行计算) /// </summary> /// <param name="productIdentify">产品标识</param> /// <param name="subProIdentify">子产品标识</param> /// <param name="invaild">无效值</param> public static void TimesStatAnalysisByPixel(string productIdentify, string subProIdentify, Int16 invaild) { IRasterOperator <Int16> roper = new RasterOperator <Int16>(); RasterIdentify identify = GetIdentify(productIdentify, subProIdentify); IInterestedRaster <Int16> timeResult = null; string[] files = GetFiles(); //频次统计 timeResult = roper.Times(files, identify, (dstValue, srcValue) => { if (srcValue != invaild) { return((Int16)(dstValue++)); } else { return(dstValue); } }); if (timeResult == null) { return; } }
private string GetSNWDegree(string[] files) { double pixelArea = 0; IInterestedRaster <Int16> timeResult = null; IRasterOperator <Int16> roper = new RasterOperator <Int16>(); DataIdentify di = GetDataIdentify(); string outFileIdentify = GetStringArgument("OutFileIdentify"); string extinfo = GetStringArgument("extinfo"); timeResult = roper.Times(files, CreatRasterIndetifyId(files, "SNW", outFileIdentify, di, null, extinfo), (dstValue, srcValue) => { if (srcValue == 0) { return(dstValue); } else { return(++dstValue); } }); IRasterDataProvider dataProvider = timeResult.HostDataProvider; if (dataProvider != null) { ArgumentProvider ap = new ArgumentProvider(dataProvider, null); RasterPixelsVisitor <Int16> visitor = new RasterPixelsVisitor <Int16>(ap); IPixelFeatureMapper <double> memresult = new MemPixelFeatureMapper <double>("0SDC", 1000, new Size(dataProvider.Width, dataProvider.Height), dataProvider.CoordEnvelope, dataProvider.SpatialRef); IInterestedRaster <double> iir = null; try { visitor.VisitPixel(new int[] { 1 }, (index, values) => { if (values[0] == 0) { memresult.Put(index, 0); } else { pixelArea = RasterOperator <Int16> .ComputePixelArea(index / dataProvider.Width, dataProvider.CoordEnvelope.MaxY, dataProvider.ResolutionY); memresult.Put(index, pixelArea * values[0]); } }); RasterIdentify id = new RasterIdentify(); id.ThemeIdentify = "CMA"; id.ProductIdentify = "SNW"; id.SubProductIdentify = "0SDC"; id.GenerateDateTime = DateTime.Now; iir = new InterestedRaster <double>(id, new Size(dataProvider.Width, dataProvider.Height), dataProvider.CoordEnvelope.Clone()); iir.Put(memresult); return(iir.FileName); } finally { if (iir != null) { iir.Dispose(); } if (visitor != null) { visitor.Dispose(); } if (timeResult != null) { timeResult.Dispose(); } if (File.Exists(timeResult.FileName)) { File.Delete(timeResult.FileName); } } } return(null); }
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(); } } }
private IExtractResult TFREAlgorithm(Action <int, string> progressTracker) { IRasterOperator <Int16> roper = new RasterOperator <Int16>(); string[] files = GetStringArray("SelectedPrimaryFiles"); if (files == null || files.Length == 0) { return(null); } //IInterestedRaster<Int16> timeResult = null; //RasterIdentify identify = new RasterIdentify(files); //identify.SubProductIdentify = _subProductDef.Identify; //timeResult = roper.Times(files, identify, progressTracker, (dstValue, srcValue) => // { // return (Int16)(srcValue == 0 ? dstValue : dstValue++); // }); //if (timeResult == null) // return null; //timeResult.Dispose(); //string workFilename = identify.ToWksFullFileName(".dat"); //File.Copy(timeResult.FileName, workFilename, true); //return new FileExtractResult("HAZ", workFilename, true); int bandNo = 1; List <RasterMaper> rms = new List <RasterMaper>(); try { for (int i = 0; i < files.Length; i++) { IRasterDataProvider inRaster = RasterDataDriver.Open(files[i]) as IRasterDataProvider; if (inRaster.BandCount < bandNo) { PrintInfo("请选择正确的数据进行最大值合成。"); return(null); } RasterMaper rm = new RasterMaper(inRaster, new int[] { bandNo }); rms.Add(rm); } //输出文件准备(作为输入栅格并集处理) RasterIdentify ri = GetRasterIdentifyID(files); 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); rfr.RegisterCalcModel(new RasterCalcHandler <Int16, Int16>((rvInVistor, rvOutVistor, aoi) => { int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX; for (int index = 0; index < dataLength; index++) { foreach (RasterVirtualVistor <Int16> rvs in rvInVistor) { if (rvs.RasterBandsData != null && rvs.RasterBandsData[0] != null && rvs.RasterBandsData[0][index] != 0) { rvOutVistor[0].RasterBandsData[0][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(); } } }
public override IExtractResult Make(Action <int, string> progressTracker) { if (_argumentProvider == null || _argumentProvider.GetArg("AlgorithmName") == null) { return(null); } if (_argumentProvider.GetArg("AlgorithmName").ToString() == "FLLS") { string[] files = GetStringArray("SelectedPrimaryFiles"); if (files == null || files.Count() == 0) { return(null); } foreach (string file in files) { if (!File.Exists(file)) { return(null); } } IRasterOperator <Int16> roper = new RasterOperator <Int16>(); IInterestedRaster <Int16> timeResult = null; DataIdentify di = GetDataIdentify(); timeResult = roper.Times(files, CreatRasterIndetifyId(files, "FLD", "FLLS", di, null, null), (dstValue, srcValue) => { //泛滥水体值==4 if (srcValue == 4) { return(++dstValue); } else { return(dstValue); } }); if (timeResult != null && !string.IsNullOrEmpty(timeResult.FileName) && File.Exists(timeResult.FileName)) { //发生[1,5)次 StatResultItem[] lowResults = null; //发生[5,10)次 StatResultItem[] midResults = null; //发生十次及十次以上 StatResultItem[] highResults = null; IStatAnalysisEngine <Int16> exe = new StatAnalysisEngine <Int16>(); using (IRasterDataProvider prd = timeResult.HostDataProvider) { lowResults = exe.StatArea(prd, "省级行政区+土地利用类型", (srcValue) => { if (srcValue >= 1 && srcValue < 5) { return(true); } else { return(false); } }); if (files.Count() >= 5) { midResults = exe.StatArea(prd, "省级行政区+土地利用类型", (srcValue) => { if (srcValue >= 5 && srcValue < 10) { return(true); } else { return(false); } }); } if (files.Count() >= 10) { highResults = exe.StatArea(prd, "省级行政区+土地利用类型", (srcValue) => { if (srcValue >= 10) { return(true); } else { return(false); } }); } } List <StatResultItem> resultList = new List <StatResultItem>(); if (lowResults != null && lowResults.Count() > 0) { foreach (StatResultItem item in lowResults) { item.Name += "_1-5次"; } resultList.AddRange(lowResults); } if (midResults != null && midResults.Count() > 0) { foreach (StatResultItem item in midResults) { item.Name += "_5-10次"; } resultList.AddRange(midResults); } if (highResults != null && highResults.Count() > 0) { foreach (StatResultItem item in midResults) { item.Name += "_10次以上"; } resultList.AddRange(highResults); } FileExtractResult fileResult = null; if (resultList != null && resultList.Count() > 0) { string filename = StatResultToFile(files, resultList.ToArray(), "FLD", "FLLS", "水情泛滥历时面积", null); fileResult = new FileExtractResult("FLLS", filename); } timeResult.Dispose(); File.Delete(timeResult.FileName); return(fileResult); } return(null); } return(null); }