//分级渲染函数 private void RasterClassifyRender(IRasterLayer pRasterLayer) { try { IColorRamp pColorRamp = (IColorRamp)EnumStyleItem[comboBoxColor.SelectedIndex]; 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; pRRend.Update(); IRgbColor pFromColor = new RgbColor() as IRgbColor; pFromColor.Red = 255; pFromColor.Green = 0; pFromColor.Blue = 0; IRgbColor pToColor = new RgbColor() as IRgbColor; pToColor.Red = 0; pToColor.Green = 0; pToColor.Blue = 255; IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp() as IAlgorithmicColorRamp; //colorRamp = pColorRamp as IAlgorithmicColorRamp;/////// colorRamp.Size = comboBoxClassValue.SelectedIndex + 1; //colorRamp.FromColor = pFromColor; //colorRamp.ToColor = pToColor; int nClass = comboBoxClassValue.SelectedIndex + 1; colorRamp.FromColor = pColorRamp.get_Color(0); colorRamp.ToColor = pColorRamp.get_Color(nClass - 1); bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); IFillSymbol fillSymbol = new SimpleFillSymbol() as IFillSymbol; for (int i = 0; i < nClass; i++) { fillSymbol.Color = colorRamp.get_Color(i); pRClassRend.set_Symbol(i, fillSymbol as ISymbol); pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00")); } pRasterLayer.Renderer = pRRend; m_mapControl.Refresh(); } catch (Exception e) { MessageBox.Show("创建失败!"); } }
public void createSSTrst(ILayer layer) { IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRenderer() as IRasterClassifyColorRampRenderer; IRasterRenderer pRRend = pRClassRend as IRasterRenderer; IRasterLayer rstLayer = layer as IRasterLayer; IRaster pRaster = rstLayer.Raster; IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection; IRasterBand pRBand = pRBandCol.Item(0); if(pRBand.Histogram == null) { pRBand.ComputeStatsAndHist(); } pRRend.Raster = pRaster; pRClassRend.ClassCount = 10; pRRend.Update(); IRgbColor pFromColor = new RgbColor() as IRgbColor; pFromColor.Red = 0; pFromColor.Green = 0; pFromColor.Blue = 255; IRgbColor pToColor = new RgbColor() as IRgbColor; pToColor.Red = 255; pToColor.Green = 0; pToColor.Blue = 0; IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp() as IAlgorithmicColorRamp; colorRamp.Size = 10; colorRamp.FromColor = pFromColor; colorRamp.ToColor = pToColor; bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); IFillSymbol fillSymbol = new SimpleFillSymbol() as IFillSymbol; for(int i = 0; i < pRClassRend.ClassCount; i++) { fillSymbol.Color = colorRamp.get_Color(i); pRClassRend.set_Symbol(i, fillSymbol as ISymbol); pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00")); } rstLayer.Renderer = pRRend; axMapControl1.AddLayer(rstLayer); this.axMapControl1.ActiveView.Refresh(); this.axTOCControl1.Update(); }
public void funColorForRaster_Classify(IRasterLayer pRasterLayer) { 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; pRClassRend.ClassCount = 10; pRRend.Update(); IRgbColor pFromColor = new RgbColor() as IRgbColor; pFromColor.Red = 255; pFromColor.Green = 0; pFromColor.Blue = 0; IRgbColor pToColor = new RgbColor() as IRgbColor; pToColor.Red = 0; pToColor.Green = 0; pToColor.Blue = 255; IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp() as IAlgorithmicColorRamp; colorRamp.Size = 10; colorRamp.FromColor = pFromColor; colorRamp.ToColor = pToColor; bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); IFillSymbol fillSymbol = new SimpleFillSymbol() as IFillSymbol; for (int i = 0; i < pRClassRend.ClassCount; i++) { fillSymbol.Color = colorRamp.get_Color(i); pRClassRend.set_Symbol(i, fillSymbol as ISymbol); pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00")); } pRasterLayer.Renderer = pRRend; IActiveView activeview = this.axMapControl1.ActiveView; activeview.ContentsChanged(); //刷新窗口 activeview.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
public void funColorForRaster_Classify(IRasterLayer pRasterLayer, int number) { 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; pRClassRend.ClassCount = number;//设置分级层次,默认为10 pRRend.Update(); //设置初始渐变色和结束渐变色 MessageBox.Show("请选择初始颜色", "颜色选择", MessageBoxButtons.OK, MessageBoxIcon.Information); IRgbColor pFromColor = new RgbColor() as IRgbColor; selectColor(pFromColor); MessageBox.Show("请选择结束颜色", "颜色选择", MessageBoxButtons.OK, MessageBoxIcon.Information); IRgbColor pToColor = new RgbColor() as IRgbColor; selectColor(pToColor); IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp() as IAlgorithmicColorRamp; colorRamp.Size = 10; colorRamp.FromColor = pFromColor; colorRamp.ToColor = pToColor; bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); IFillSymbol fillSymbol = new SimpleFillSymbol() as IFillSymbol; for (int i = 0; i < pRClassRend.ClassCount; i++) { fillSymbol.Color = colorRamp.get_Color(i); pRClassRend.set_Symbol(i, fillSymbol as ISymbol); pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00")); } pRasterLayer.Renderer = pRRend; IActiveView activeview = this.axMapControl1.ActiveView; activeview.ContentsChanged(); //刷新窗口 activeview.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
public IRasterLayer funColorForRaster(IRasterLayer pRasterLayer) { 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; pRClassRend.ClassCount = 10; pRRend.Update(); IRgbColor pFromColor = new RgbColor() as IRgbColor; pFromColor.Red = 255; pFromColor.Green = 0; pFromColor.Blue = 0; IRgbColor pToColor = new RgbColor() as IRgbColor; pToColor.Red = 0; pToColor.Green = 0; pToColor.Blue = 255; IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp() as IAlgorithmicColorRamp; colorRamp.Size = 10; colorRamp.FromColor = pFromColor; colorRamp.ToColor = pToColor; //ESRI.ArcGIS.Display.IMultiPartColorRamp colorRamp = new MultiPartColorRamp() as IMultiPartColorRamp; comboBox1.Items.Add(colorRamp); bool createColorRamp; colorRamp.CreateRamp(out createColorRamp); IFillSymbol fillSymbol = new SimpleFillSymbol() as IFillSymbol; for (int i = 0; i < pRClassRend.ClassCount; i++) { fillSymbol.Color = colorRamp.get_Color(i); pRClassRend.set_Symbol(i, fillSymbol as ISymbol); pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00")); } pRasterLayer.Renderer = pRRend; return(pRasterLayer); }