private Dictionary <double, object[]> zoneValueDic = null;//value = [count,max,min,sum,sum2,dictionary<int,int>]->dictionary is for unique, entropy, and ASM private void calcZoneValues() { bool makeDic = (ZoneClassCount || ZoneTypes.Contains(rasterUtil.zoneType.VARIETY) || ZoneTypes.Contains(rasterUtil.zoneType.ENTROPY) || ZoneTypes.Contains(rasterUtil.zoneType.ASM) || ZoneTypes.Contains(rasterUtil.zoneType.MINORITY) || ZoneTypes.Contains(rasterUtil.zoneType.MODE) || ZoneTypes.Contains(rasterUtil.zoneType.MEDIAN)); IPnt zMeanCellSize = zRs.RasterInfo.CellSize; IPnt vMeanCellSize = vRs.RasterInfo.CellSize; int intersectWidthCells = System.Convert.ToInt32(intEnv.Width / zMeanCellSize.X); int intersectHeightCells = System.Convert.ToInt32(intEnv.Height / zMeanCellSize.Y); IPoint tl = intEnv.UpperLeft; int bH = 512; int bW = 512; int wCellsMax = intersectWidthCells; int hCellsMax = intersectHeightCells; IPnt zPntLoc = new PntClass(); IPnt vPntLoc = new PntClass(); IPnt zPntSize = new PntClass(); IRasterFunctionHelper inZoneHelper = new RasterFunctionHelperClass(); inZoneHelper.Bind(InZoneRaster); IRasterFunctionHelper inValueHelper = new RasterFunctionHelperClass(); inValueHelper.Bind(InValueRaster); IRaster2 zr = (IRaster2)inZoneHelper.Raster; IRaster2 vr = (IRaster2)inValueHelper.Raster; int zclm, zrw, vclm, vrw; zr.MapToPixel(tl.X + (zMeanCellSize.X / 2), tl.Y - (zMeanCellSize.Y / 2), out zclm, out zrw); vr.MapToPixel(tl.X + (zMeanCellSize.X / 2), tl.Y - (zMeanCellSize.Y / 2), out vclm, out vrw); int ozclm = zclm; int ozrw = zrw; int ovclm = vclm; int ovrw = vrw; zPntLoc.SetCoords(zclm, zrw); vPntLoc.SetCoords(vclm, vrw); for (int brw = 0; brw < hCellsMax; brw += bH) { int rH = hCellsMax - brw;//Height of block if (rH > bH) { rH = bH; } for (int bclm = 0; bclm < wCellsMax; bclm += bW) { int cW = wCellsMax - bclm;//Width of block if (cW > bW) { cW = bW; } zPntSize.SetCoords(cW, rH); IPixelBlock zPb = ((IRaster)zr).CreatePixelBlock(zPntSize); IPixelBlock vPb = ((IRaster)vr).CreatePixelBlock(zPntSize); inZoneHelper.Read(zPntLoc, null, (IRaster)zr, zPb); inValueHelper.Read(vPntLoc, null, (IRaster)vr, vPb); for (int i = 0; i < vPb.Planes; i++) { zoneValueDic = zoneValueDicArr[i]; //double vNoDataVl = System.Convert.ToDouble(((System.Array)vProps.NoDataValue).GetValue(i)); //System.Array vPix = (System.Array)vPb.get_SafeArray(i); for (int r = 0; r < rH; r++) { for (int c = 0; c < cW; c++) { object zObj = zPb.GetVal(0, c, r); if (zObj == null) { continue; } else { double z = System.Convert.ToDouble(zObj); object vObj = vPb.GetVal(i, c, r); if (vObj == null) { continue; } else { double v = System.Convert.ToDouble(vObj); object[] zoneValue; if (zoneValueDic.TryGetValue(z, out zoneValue)) { double cnt = System.Convert.ToDouble(zoneValue[0]); zoneValue[0] = cnt += 1; double maxVl = System.Convert.ToDouble(zoneValue[1]); if (v > maxVl) { maxVl = v; zoneValue[1] = maxVl; } double minVl = System.Convert.ToDouble(zoneValue[2]); if (v < minVl) { minVl = v; zoneValue[2] = minVl; } double s = System.Convert.ToDouble(zoneValue[3]); zoneValue[3] = s + v; double s2 = System.Convert.ToDouble(zoneValue[4]); zoneValue[4] = s2 + v * v; if (makeDic) { Dictionary <double, int> uDic = (Dictionary <double, int>)zoneValue[5]; int cntVl = 0; if (uDic.TryGetValue(v, out cntVl)) { uDic[v] = cntVl += 1; } else { uDic.Add(v, 1); } zoneValue[5] = uDic; } zoneValueDic[z] = zoneValue; } else { zoneValue = new object[6]; zoneValue[0] = 1d; zoneValue[1] = v; zoneValue[2] = v; zoneValue[3] = v; zoneValue[4] = v * v; if (makeDic) { Dictionary <double, int> uDic = new Dictionary <double, int>(); uDic.Add(v, 1); zoneValue[5] = uDic; } zoneValueDic.Add(z, zoneValue); } } } } } } //do this at the end zclm = zclm + cW; vclm = vclm + cW; zPntLoc.SetCoords(zclm, zrw); vPntLoc.SetCoords(vclm, vrw); } zrw = zrw + rH; vrw = vrw + rH; //reset PixelBlock columns zclm = ozclm; vclm = ovclm; zPntLoc.SetCoords(zclm, zrw); vPntLoc.SetCoords(vclm, vrw); } }
private void calcZoneValues() { bool makeDic = (ZoneClassCount||ZoneTypes.Contains(rasterUtil.zoneType.VARIETY)||ZoneTypes.Contains(rasterUtil.zoneType.ENTROPY)||ZoneTypes.Contains(rasterUtil.zoneType.ASM)||ZoneTypes.Contains(rasterUtil.zoneType.MINORITY)||ZoneTypes.Contains(rasterUtil.zoneType.MODE)||ZoneTypes.Contains(rasterUtil.zoneType.MEDIAN)); IPnt zMeanCellSize = zRs.RasterInfo.CellSize; IPnt vMeanCellSize = vRs.RasterInfo.CellSize; int intersectWidthCells = System.Convert.ToInt32(intEnv.Width / zMeanCellSize.X); int intersectHeightCells = System.Convert.ToInt32(intEnv.Height / zMeanCellSize.Y); IPoint tl = intEnv.UpperLeft; int bH = 512; int bW = 512; int wCellsMax = intersectWidthCells; int hCellsMax = intersectHeightCells; IPnt zPntLoc = new PntClass(); IPnt vPntLoc = new PntClass(); IPnt zPntSize = new PntClass(); IRasterFunctionHelper inZoneHelper = new RasterFunctionHelperClass(); inZoneHelper.Bind(InZoneRaster); IRasterFunctionHelper inValueHelper = new RasterFunctionHelperClass(); inValueHelper.Bind(InValueRaster); IRaster2 zr = (IRaster2)inZoneHelper.Raster; IRaster2 vr = (IRaster2)inValueHelper.Raster; int zclm, zrw, vclm, vrw; zr.MapToPixel(tl.X+(zMeanCellSize.X/2), tl.Y-(zMeanCellSize.Y/2), out zclm, out zrw); vr.MapToPixel(tl.X + (zMeanCellSize.X / 2), tl.Y - (zMeanCellSize.Y / 2), out vclm, out vrw); int ozclm = zclm; int ozrw = zrw; int ovclm = vclm; int ovrw = vrw; zPntLoc.SetCoords(zclm, zrw); vPntLoc.SetCoords(vclm, vrw); for (int brw = 0; brw < hCellsMax; brw += bH) { int rH = hCellsMax-brw;//Height of block if (rH > bH) rH = bH; for (int bclm = 0; bclm < wCellsMax; bclm += bW) { int cW = wCellsMax - bclm;//Width of block if (cW > bW) cW = bW; zPntSize.SetCoords(cW, rH); IPixelBlock zPb = ((IRaster)zr).CreatePixelBlock(zPntSize); IPixelBlock vPb = ((IRaster)vr).CreatePixelBlock(zPntSize); inZoneHelper.Read(zPntLoc, null, (IRaster)zr, zPb); inValueHelper.Read(vPntLoc, null, (IRaster)vr, vPb); for (int i = 0; i < vPb.Planes; i++) { zoneValueDic = zoneValueDicArr[i]; //double vNoDataVl = System.Convert.ToDouble(((System.Array)vProps.NoDataValue).GetValue(i)); //System.Array vPix = (System.Array)vPb.get_SafeArray(i); for (int r = 0; r < rH; r++) { for (int c = 0; c < cW; c++) { object zObj = zPb.GetVal(0, c, r); if (zObj==null) { continue; } else { double z = System.Convert.ToDouble(zObj); object vObj = vPb.GetVal(i, c, r); if (vObj==null) { continue; } else { double v = System.Convert.ToDouble(vObj); object[] zoneValue; if (zoneValueDic.TryGetValue(z, out zoneValue)) { double cnt = System.Convert.ToDouble(zoneValue[0]); zoneValue[0] = cnt += 1; double maxVl = System.Convert.ToDouble(zoneValue[1]); if (v > maxVl) { maxVl = v; zoneValue[1] = maxVl; } double minVl = System.Convert.ToDouble(zoneValue[2]); if (v < minVl) { minVl = v; zoneValue[2] = minVl; } double s = System.Convert.ToDouble(zoneValue[3]); zoneValue[3] = s + v; double s2 = System.Convert.ToDouble(zoneValue[4]); zoneValue[4] = s2 + v * v; if (makeDic) { Dictionary<double, int> uDic = (Dictionary<double, int>)zoneValue[5]; int cntVl = 0; if (uDic.TryGetValue(v, out cntVl)) { uDic[v] = cntVl += 1; } else { uDic.Add(v, 1); } zoneValue[5] = uDic; } zoneValueDic[z] = zoneValue; } else { zoneValue = new object[6]; zoneValue[0] = 1d; zoneValue[1] = v; zoneValue[2] = v; zoneValue[3] = v; zoneValue[4] = v * v; if (makeDic) { Dictionary<double, int> uDic = new Dictionary<double, int>(); uDic.Add(v, 1); zoneValue[5] = uDic; } zoneValueDic.Add(z, zoneValue); } } } } } } //do this at the end zclm = zclm + cW; vclm = vclm + cW; zPntLoc.SetCoords(zclm, zrw); vPntLoc.SetCoords(vclm, vrw); } zrw = zrw + rH; vrw = vrw + rH; //reset PixelBlock columns zclm = ozclm; vclm = ovclm; zPntLoc.SetCoords(zclm, zrw); vPntLoc.SetCoords(vclm, vrw); } }