AE栅格分类渲染问题解决
一个0-255的波段图像,要分为三类,0-85,85-170,170-255,那么这个断点其实有四个,分别是0,85,170,255
当按照下面方式写代码时,真正的分类break并没有设置成功。注意黑体部分;
public static void ClassifyRenderRaster(IRasterLayer pRasterLayer, int ClassifyNum) { IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRenderer() as IRasterClassifyColorRampRenderer; IRasterRenderer pRRend = pRClassRend as IRasterRenderer; IRaster pRaster = pRasterLayer.Raster; IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection; IRasterBand pRBand = pRBandCol.Item(0); if (pRBand.Histogram == null) { pRBand.ComputeStatsAndHist(); } pRRend.Raster = pRaster;//this pRClassRend.ClassCount = ClassifyNum; pRRend.Update();//this //省略colorRamp的生成代码 int[] breaks = { 0, 25, 50, 75, 100, 200 }; IFillSymbol fillSymbol = new SimpleFillSymbol() as IFillSymbol; for (int i = 0; i < pRClassRend.ClassCount; i++) { //fillSymbol.Color = colorRamp.get_Color(i); fillSymbol.Color = GetColor(i); pRClassRend.set_Symbol(i, fillSymbol as ISymbol); pRClassRend.set_Break(i, breaks[i]);//this //pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00")); } pRasterLayer.Renderer = pRRend //this }
改动后成功。IRasterRenderer.Update须在设置break之后,并且IRasterLayer须赋值为IRasterClassifyColorRampRenderer。
public static void ClassifyRenderRaster(IRasterLayer pRasterLayer, int ClassifyNum) { IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRenderer() as IRasterClassifyColorRampRenderer; IRaster pRaster = pRasterLayer.Raster; IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection; IRasterBand pRBand = pRBandCol.Item(0); if (pRBand.Histogram == null) { pRBand.ComputeStatsAndHist(); } pRClassRend.ClassCount = ClassifyNum; int[] breaks = { 0, 25, 50, 75, 100, 200 }; IFillSymbol fillSymbol = new SimpleFillSymbol() as IFillSymbol; for (int i = 0; i < pRClassRend.ClassCount; i++) { fillSymbol.Color = colorRamp.get_Color(i); fillSymbol.Color = GetColor(i); pRClassRend.set_Symbol(i, fillSymbol as ISymbol); pRClassRend.set_Break(i, breaks[i]); //pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00")); } //IRasterRenderer pRRend = pRClassRend as IRasterRenderer; //pRRend.Update(); 这两句可以省略 pRasterLayer.Renderer = pRClassRend as IRasterRenderer; //this }
开始主要参照这几个,没有解决
AE 栅格图分级渲染 : 参照这里不重新设置break的话(就是不是自定义分类),只设置每个分级的颜色之类的,是可以的,
版权声明:本博原创文章可以被转载,但是在未经本人许可前,不得用于任何商业用途或其他以盈利为目的的用途。如需转载,请在转载时声明作者、保留出处。本人保留对本文的一切权利。
作者:AllenRobin Blog:http://gisrsman.cnblogs.com