private IPixelFeatureMapper <T> MakeCompareRaster <T1, T>(string productIdentify, string fstFileName, string sedFileName, Func <T1, T1, T> function) { Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>(); filePrdMap.Add("backWaterPath", new FilePrdMap(fstFileName, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 })); filePrdMap.Add("binWater", new FilePrdMap(sedFileName, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 })); ITryCreateVirtualPrd tryVPrd = new TryCreateVirtualPrdByMultiFile(); IVirtualRasterDataProvider vrd = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap); if (vrd == null) { throw new Exception("数据间无相交部分,无法创建虚拟数据提供者!"); } try { ArgumentProvider ap = new ArgumentProvider(vrd, null); RasterPixelsVisitor <T1> rpVisitor = new RasterPixelsVisitor <T1>(ap); IPixelFeatureMapper <T> result = new MemPixelFeatureMapper <T>(productIdentify, 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef); rpVisitor.VisitPixel(new int[] { filePrdMap["backWaterPath"].StartBand, filePrdMap["binWater"].StartBand }, (idx, values) => { result.Put(idx, function(values[0], values[1])); }); return(result); } finally { vrd.Dispose(); } }
/// <summary> /// 统计判识结果的面积 /// </summary> /// <param name="dataProvider">判识结果使用的栅格文件</param> /// <param name="extractedPixels">判识结果</param> /// <param name="aoi"></param> /// <param name="filterDic"></param> /// <returns></returns> public double Area(IRasterDataProvider dataProvider, IPixelIndexMapper extractedPixels, int[] aoi) { if (dataProvider.CoordEnvelope == null) { return(0); } IArgumentProvider argPrd = new ArgumentProvider(dataProvider, null); argPrd.AOI = aoi; IRasterPixelsVisitor <T> visitor = new RasterPixelsVisitor <T>(argPrd); int row = 0; int width = dataProvider.Width; double maxLat = dataProvider.CoordEnvelope.MaxY; double res = dataProvider.ResolutionX; double statArea = 0; visitor.VisitPixel(new int[] { 1 }, (idx, values) => { if (extractedPixels.Get(idx)) { statArea += ComputePixelArea(row, maxLat, res); } }); return(statArea); }
public double Area(int[] aoi, Func <T, bool> filter) { if (_coordEnvelope == null) { return(0d); } IArgumentProvider argPrd = new ArgumentProvider(_dataProvider, null); argPrd.AOI = aoi; IRasterPixelsVisitor <T> visitor = new RasterPixelsVisitor <T>(argPrd); double area = 0; int row = 0; int width = _dataProvider.Width; double maxLat = _dataProvider.CoordEnvelope.MaxY; double res = _dataProvider.ResolutionX; visitor.VisitPixel(new int[] { 1 }, (idx, values) => { if (filter(values[0])) { row = idx / width; area += ComputePixelArea(row, maxLat, res); } } ); return(area); }
private void StatArea(byte[] adminRaster, byte[] landuseRaster, IRasterDataProvider dataProvider, double[,] result, Func <T, bool> filter) { ArgumentProvider arg = new ArgumentProvider(dataProvider, null); int row = 0; int width = dataProvider.Width; float maxLat = (float)dataProvider.CoordEnvelope.MaxY; float res = dataProvider.ResolutionY; using (IRasterPixelsVisitor <T> v = new RasterPixelsVisitor <T>(arg)) { v.VisitPixel(new int[] { 1 }, (idx, bandValues) => { if (filter(bandValues[0])) { //计数 //result[adminRaster[idx], landuseRaster[idx]]++; //精确面积 row = idx / width; result[adminRaster[idx], landuseRaster[idx]] += RasterOperator <UInt16> .ComputePixelArea(row, maxLat, res); } } ); } }
public void Extract(IPixelFeatureMapper <TFeature> extractedPixels) { if (_infoExtracter == null || _featureComputer == null) { return; } _infoExtracter.VisitPixel(_visitBandNos, (idx, values) => { extractedPixels.Put(idx, _featureComputer(idx, values)); }); }
public void Extract(IPixelIndexMapper extractedPixels) { if (_infoExtracter == null || _boolFunc == null) { return; } _infoExtracter.VisitPixel(_visitBandNos, (idx, values) => { if (_boolFunc(idx, values)) { extractedPixels.Put(idx); } }); }
public int Count(int[] aoi, Func <T, int> weight) { IArgumentProvider argPrd = new ArgumentProvider(_dataProvider, null); argPrd.AOI = aoi; IRasterPixelsVisitor <T> visitor = new RasterPixelsVisitor <T>(argPrd); int retCount = 0; visitor.VisitPixel(new int[] { 1 }, (idx, values) => { retCount += weight(values[0]); }); return(retCount); }
public int Count(int[] aoi, Func <T, bool> filter) { IArgumentProvider argPrd = new ArgumentProvider(_dataProvider, null); argPrd.AOI = aoi; IRasterPixelsVisitor <T> visitor = new RasterPixelsVisitor <T>(argPrd); int retCount = 0; visitor.VisitPixel(new int[] { 1 }, (idx, values) => { if (filter(values[0])) { retCount++; } }); return(retCount); }
private void StatAreaUseAOI(byte[] adminRaster, byte[] landuseRaster, IRasterDataProvider dataProvider, double[,] result, int[] aoi, Func <T, int, int> weight) { ArgumentProvider arg = new ArgumentProvider(dataProvider, null) { AOI = aoi }; using (IRasterPixelsVisitor <T> v = new RasterPixelsVisitor <T>(arg)) { Rectangle aoiRect = AOIHelper.ComputeAOIRect(aoi, new Size(dataProvider.Width, dataProvider.Height)); v.VisitPixel(aoiRect, aoi, new int[] { 1 }, (idx, bandValues) => { result[adminRaster[idx], landuseRaster[idx]] += weight(bandValues[0], idx); } ); } }
public Dictionary <string, double> Area(IRasterDataProvider dataProvider, int[] aoi, Dictionary <string, Func <T, bool> > filterDic) { if (dataProvider.CoordEnvelope == null) { return(null); } IArgumentProvider argPrd = new ArgumentProvider(dataProvider, null); argPrd.AOI = aoi; IRasterPixelsVisitor <T> visitor = new RasterPixelsVisitor <T>(argPrd); int row = 0; int width = dataProvider.Width; double maxLat = dataProvider.CoordEnvelope.MaxY; double res = dataProvider.ResolutionX; Dictionary <string, double> areas = new Dictionary <string, double>(); int length = filterDic.Count; string[] keys = filterDic.Keys.ToArray(); Func <T, bool>[] filters = filterDic.Values.ToArray(); double[] statAreas = new double[length]; visitor.VisitPixel(new int[] { 1 }, (idx, values) => { for (int i = 0; i < length; i++) { if (filters[i](values[0])) { row = idx / width; statAreas[i] += ComputePixelArea(row, maxLat, res); break; } } } ); for (int i = 0; i < length; i++) { areas.Add(keys[i], statAreas[i]); } return(areas); }
public IInterestedRaster <T> CycleTimes(IRasterDataProvider[] srcRasters, RasterIdentify rasterIdentify, Func <int, T, T, T> iTimesGetter, Action <int, string> progress) { ////修改不同区域生成结果文件大小不足问题 by chennan 20120806 //CoordEnvelope dstEnvelope = srcRasters[srcRasters.Length - 1].CoordEnvelope; CoordEnvelope dstEnvelope = GetEnvelopeBySize(srcRasters[srcRasters.Length - 1]); float minResolutionX = 0f; float minResolutionY = 0f; Size dstSize = Size.Empty;; for (int i = 0; i < srcRasters.Length - 1; i++) { if (srcRasters[i].DataType != srcRasters[i + 1].DataType) { throw new ArgumentException("数据类型不一致无法进行频次统计!"); } dstEnvelope = dstEnvelope.Union(GetEnvelopeBySize(srcRasters[i])); // by chennan 20120806 minResolutionX = Math.Min(srcRasters[i].ResolutionX, srcRasters[i + 1].ResolutionX); minResolutionY = Math.Min(srcRasters[i].ResolutionY, srcRasters[i + 1].ResolutionY); dstSize = new Size((int)Math.Floor(dstEnvelope.Width / minResolutionX), (int)Math.Floor(dstEnvelope.Height / minResolutionY)); } //by chennan 20121025 修改单文件无法进行周期统计 if (srcRasters.Length == 1) { minResolutionX = srcRasters[0].ResolutionX; minResolutionY = srcRasters[0].ResolutionY; dstEnvelope = srcRasters[0].CoordEnvelope.Clone(); dstSize = new Size(srcRasters[0].Width, srcRasters[0].Height); } IInterestedRaster <T> dstRaster = CreateDstRaster(srcRasters[0], dstEnvelope, rasterIdentify, dstSize); IArgumentProvider argprd = new ArgumentProvider(new AlgorithmDef()); int offsetX = 0, offsetY = 0; int dstIndex = 0; int index = 0; foreach (IRasterDataProvider rst in srcRasters) { if (progress != null) { progress((int)(index++ *100f / srcRasters.Length), "正在执行周期统计"); } CoordEnvelope inc = rst.CoordEnvelope.Intersect(dstEnvelope); if (inc == null || inc.IsEmpty()) { continue; } int iCycle = Array.IndexOf <IRasterDataProvider>(srcRasters, rst) + 1; offsetX = (int)((rst.CoordEnvelope.MinX - dstEnvelope.MinX) / rst.ResolutionX); offsetY = (int)((dstEnvelope.MaxY - rst.CoordEnvelope.MaxY) / rst.ResolutionY); //by chennan 20120806 IRasterDataProvider dstTempPrd = GetSubPrd <T>(dstRaster.HostDataProvider, rst, rasterIdentify, offsetX, offsetY); try { IVirtualRasterDataProvider virtualDataProvider = new VirtualRasterDataProvider(new IRasterDataProvider[] { dstTempPrd, rst }); argprd.DataProvider = virtualDataProvider; using (IRasterPixelsVisitor <T> visitor = new RasterPixelsVisitor <T>(argprd)) { visitor.VisitPixel(new int[] { 1, 2 }, (idx, values) => { dstIndex = (idx / dstTempPrd.Width + offsetY) * dstRaster.HostDataProvider.Width + (idx % dstTempPrd.Width + offsetX); dstRaster.Put(dstIndex, iTimesGetter(iCycle, values[0], values[1])); }); } } finally { dstTempPrd.Dispose(); if (File.Exists(dstTempPrd.fileName)) { File.Delete(dstTempPrd.fileName); } } } for (int i = 0; i < srcRasters.Length; i++) { srcRasters[i].Dispose(); } return(dstRaster); }
public IInterestedRaster <T> Times(IRasterDataProvider[] srcRasters, RasterIdentify rasterIdentify, Action <int, string> progressTracker, Func <T, T, T> timesAction) { CoordEnvelope dstEnvelope = GetEnvelopeBySize(srcRasters[srcRasters.Length - 1]); float minResolutionX = 0f; float minResolutionY = 0f; Size dstSize = Size.Empty; for (int i = 0; i < srcRasters.Length - 1; i++) { if (srcRasters[i].DataType != srcRasters[i + 1].DataType) { throw new ArgumentException("数据类型不一致无法进行频次统计!"); } dstEnvelope = dstEnvelope.Union(GetEnvelopeBySize(srcRasters[i])); minResolutionX = Math.Min(srcRasters[i].ResolutionX, srcRasters[i + 1].ResolutionX); minResolutionY = Math.Min(srcRasters[i].ResolutionY, srcRasters[i + 1].ResolutionY); dstSize = new Size((int)Math.Round(dstEnvelope.Width / minResolutionX), (int)Math.Round(dstEnvelope.Height / minResolutionY)); } if (srcRasters.Length == 1) { minResolutionX = srcRasters[0].ResolutionX; minResolutionY = srcRasters[0].ResolutionY; dstEnvelope = srcRasters[0].CoordEnvelope.Clone(); dstSize = new Size(srcRasters[0].Width, srcRasters[0].Height); } IInterestedRaster <T> dstRaster = CreateDstRaster(srcRasters[0], dstEnvelope, rasterIdentify, dstSize); IArgumentProvider argprd = new ArgumentProvider(new AlgorithmDef()); int offsetX = 0, offsetY = 0; int dstIndex = 0; if (progressTracker != null) { progressTracker(0, "开始进行统计..."); } int num = 0; foreach (IRasterDataProvider rst in srcRasters) { offsetX = (int)((rst.CoordEnvelope.MinX - dstEnvelope.MinX) / rst.ResolutionX); offsetY = (int)((dstEnvelope.MaxY - rst.CoordEnvelope.MaxY) / rst.ResolutionY); //by chennan 20120806 IRasterDataProvider dstTempPrd = GetSubPrd <T>(dstRaster.HostDataProvider, rst, rasterIdentify, offsetX, offsetY); try { IVirtualRasterDataProvider virtualDataProvider = new VirtualRasterDataProvider(new IRasterDataProvider[] { dstTempPrd, rst }); argprd.DataProvider = virtualDataProvider; using (IRasterPixelsVisitor <T> visitor = new RasterPixelsVisitor <T>(argprd)) { visitor.VisitPixel(new int[] { 1, 2 }, (idx, values) => { dstIndex = (idx / dstTempPrd.Width + offsetY) * dstRaster.HostDataProvider.Width + (idx % dstTempPrd.Width + offsetX); dstRaster.Put(dstIndex, timesAction(values[0], values[1])); }); } num++; int persent = (int)(num * 100f / srcRasters.Length); if (progressTracker != null) { progressTracker(persent, "统计完成" + persent + "%"); } } finally { dstTempPrd.Dispose(); if (File.Exists(dstTempPrd.fileName)) { File.Delete(dstTempPrd.fileName); } } if (progressTracker != null) { progressTracker(100, "统计完成"); } } for (int i = 0; i < srcRasters.Length; i++) { srcRasters[i].Dispose(); } return(dstRaster); }