public IEnumColors GetColors(long lngStartColor, long lngEndColor, long Colors) { IRgbColor startColor = new RgbColor(); IRgbColor endColor = new RgbColor(); startColor.RGB = Convert.ToInt32(lngStartColor); endColor.RGB = Convert.ToInt32(lngEndColor); IAlgorithmicColorRamp ramp; ramp = new AlgorithmicColorRamp(); ramp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm; ramp.FromColor = startColor; ramp.ToColor = endColor; ramp.Size = Convert.ToInt32(Colors); bool blnIsRampOK; ramp.CreateRamp(out blnIsRampOK); if (!blnIsRampOK) { return(null); } else { return(ramp.Colors); } }
public IColorRamp AlgorithmicColorRamp(int ImageLstIndex, int ClassCount) { //Create a color ramp to use IAlgorithmicColorRamp pRamp; pRamp = new AlgorithmicColorRamp(); bool blncreate = true; pRamp.Size = ClassCount; IRgbColor pFromRgbColor = new RgbColor(); //构建一个RgbColorClass IRgbColor pToRgbColor = new RgbColor(); //构建一个RgbColorClass if (ImageLstIndex == 0) { pFromRgbColor.Red = 255; //设置Red属性 pFromRgbColor.Green = 255; //设置Green属性 pFromRgbColor.Blue = 0; //设置Blue属性 pToRgbColor.Red = 255; //设置Red属性 pToRgbColor.Green = 0; //设置Green属性 pToRgbColor.Blue = 0; //设置Blue属性 } else if (ImageLstIndex == 1) { pFromRgbColor.Red = 0; //设置Red属性 pFromRgbColor.Green = 255; //设置Green属性 pFromRgbColor.Blue = 0; //设置Blue属性 pToRgbColor.Red = 0; //设置Red属性 pToRgbColor.Green = 0; //设置Green属性 pToRgbColor.Blue = 255; //设置Blue属性 } else if (ImageLstIndex == 2) { pFromRgbColor.Red = 0; //设置Red属性 pFromRgbColor.Green = 255; //设置Green属性 pFromRgbColor.Blue = 0; //设置Blue属性 pToRgbColor.Red = 255; //设置Red属性 pToRgbColor.Green = 0; //设置Green属性 pToRgbColor.Blue = 0; //设置Blue属性 } else { pFromRgbColor.Red = 255; //设置Red属性 pFromRgbColor.Green = 255; //设置Green属性 pFromRgbColor.Blue = 0; //设置Blue属性 pToRgbColor.Red = 255; //设置Red属性 pToRgbColor.Green = 0; //设置Green属性 pToRgbColor.Blue = 0; //设置Blue属性 } pRamp.FromColor = (IColor)pFromRgbColor; pRamp.ToColor = (IColor)pToRgbColor; pRamp.CreateRamp(out blncreate); return(pRamp as IColorRamp); }
//分级渲染函数 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("创建失败!"); } }
/// <summary> /// 拉伸渲染raster图层 /// </summary> /// <params name="pRLayer">raster图层</params> /// <remarks></remarks> public void UsingRasterStretchColorRampRender(IRasterLayer pRLayer) { //获得图层 IRaster pRaster = default(IRaster); pRaster = pRLayer.Raster; //创建渲染并转换到栅格渲染 IRasterStretchColorRampRenderer pStretchRen = default(IRasterStretchColorRampRenderer); pStretchRen = new RasterStretchColorRampRenderer(); IRasterRenderer pRasRen = default(IRasterRenderer); pRasRen = (IRasterRenderer)pStretchRen; //栅格渲染赋值和更新 pRasRen.Raster = pRaster; pRasRen.Update(); //定义起止颜色 IRgbColor pFromColor = new RgbColorClass(); pFromColor.Red = 0; pFromColor.Green = 255; pFromColor.Blue = 0; IRgbColor pToColor = new RgbColorClass(); pToColor.Red = 255; pToColor.Green = 0; pToColor.Blue = 0; //创建颜色条 IAlgorithmicColorRamp pRamp = new AlgorithmicColorRamp(); pRamp.Size = 255; pRamp.FromColor = pFromColor; pRamp.ToColor = pToColor; bool bOK; pRamp.CreateRamp(out bOK); //插入颜色条和选择渲染波段 pStretchRen.BandIndex = 0; pStretchRen.ColorRamp = pRamp; //用新的设置更新渲染并赋值给图层 pRasRen.Update(); pRLayer.Renderer = (IRasterRenderer)pStretchRen; //释放内存 pRLayer = null; pRaster = null; pStretchRen = null; pRasRen = null; pRamp = null; pToColor = null; pFromColor = null; }
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(); }
private IColorRamp StretchAlgorithmicColorRamp(int ImageLstIndex) { IAlgorithmicColorRamp pRamp = new AlgorithmicColorRamp(); IRgbColor pFromRgbColor = new RgbColor(); //构建一个RgbColorClass IRgbColor pToRgbColor = new RgbColor(); //构建一个RgbColorClass if (ImageLstIndex == 0) { pFromRgbColor.Red = 255; //设置Red属性 pFromRgbColor.Green = 255; //设置Green属性 pFromRgbColor.Blue = 0; //设置Blue属性 pToRgbColor.Red = 255; //设置Red属性 pToRgbColor.Green = 0; //设置Green属性 pToRgbColor.Blue = 0; //设置Blue属性 } else if (ImageLstIndex == 1) { pFromRgbColor.Red = 0; //设置Red属性 pFromRgbColor.Green = 255; //设置Green属性 pFromRgbColor.Blue = 0; //设置Blue属性 pToRgbColor.Red = 0; //设置Red属性 pToRgbColor.Green = 0; //设置Green属性 pToRgbColor.Blue = 255; //设置Blue属性 } else if (ImageLstIndex == 2) { pFromRgbColor.Red = 0; //设置Red属性 pFromRgbColor.Green = 255; //设置Green属性 pFromRgbColor.Blue = 0; //设置Blue属性 pToRgbColor.Red = 255; //设置Red属性 pToRgbColor.Green = 0; //设置Green属性 pToRgbColor.Blue = 0; //设置Blue属性 } else { pFromRgbColor.Red = 255; //设置Red属性 pFromRgbColor.Green = 255; //设置Green属性 pFromRgbColor.Blue = 0; //设置Blue属性 pToRgbColor.Red = 255; //设置Red属性 pToRgbColor.Green = 0; //设置Green属性 pToRgbColor.Blue = 0; //设置Blue属性 } pRamp.FromColor = (IColor)pFromRgbColor; pRamp.ToColor = (IColor)pToRgbColor; pRamp.Size = 255; bool blncreate = true; pRamp.CreateRamp(out blncreate); return(pRamp as IColorRamp); }
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 static IRasterClassifyColorRampRenderer RasterClassifyRenderer(IRasterLayer irasterLayer_0) { bool flag; double @break; string str; IRasterClassifyColorRampRenderer rasterClassifyColorRampRenderer; try { IRasterClassifyColorRampRenderer rasterClassifyColorRampRendererClass = new RasterClassifyColorRampRenderer(); IRasterRenderer raster = (IRasterRenderer)rasterClassifyColorRampRendererClass; rasterClassifyColorRampRendererClass.ClassField = "<VALUE>"; rasterClassifyColorRampRendererClass.NormField = "<NONE>"; raster.Raster = irasterLayer_0.Raster; rasterClassifyColorRampRendererClass.ClassCount = 3; raster.Update(); IAlgorithmicColorRamp algorithmicColorRampClass = new AlgorithmicColorRamp() { Size = 3 }; algorithmicColorRampClass.CreateRamp(out flag); IFillSymbol simpleFillSymbolClass = new SimpleFillSymbol(); for (int i = 0; i < rasterClassifyColorRampRendererClass.ClassCount; i++) { simpleFillSymbolClass.Color = algorithmicColorRampClass.Color[i]; rasterClassifyColorRampRendererClass.Symbol[i] = (ISymbol)simpleFillSymbolClass; if (i != rasterClassifyColorRampRendererClass.ClassCount - 1) { @break = rasterClassifyColorRampRendererClass.Break[i]; string str1 = @break.ToString("0.####"); @break = rasterClassifyColorRampRendererClass.Break[i + 1]; str = string.Concat(str1, " - ", @break.ToString("0.####")); } else { @break = rasterClassifyColorRampRendererClass.Break[i]; str = @break.ToString("0.####"); } rasterClassifyColorRampRendererClass.set_Label(i, str); } rasterClassifyColorRampRenderer = raster as IRasterClassifyColorRampRenderer; } catch (Exception exception) { Debug.WriteLine(exception.Message); rasterClassifyColorRampRenderer = null; } return(rasterClassifyColorRampRenderer); }
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); }
public static IRasterLayer SetStretchRenderer(IRaster pRaster) { try { //创建着色类和QI栅格着色 IRasterStretchColorRampRenderer pStretchRen = new RasterStretchColorRampRenderer(); IRasterRenderer pRasRen = pStretchRen as IRasterRenderer; //为着色和更新设置栅格数据 pRasRen.Raster = pRaster; pRasRen.Update(); //定义起点和终点颜色 IColor pFromColor = new RgbColor(); IRgbColor pRgbColor = pFromColor as IRgbColor; pRgbColor.Red = 255; pRgbColor.Green = 0; pRgbColor.Blue = 0; IColor pToColor = new RgbColor(); pRgbColor = pToColor as IRgbColor; pRgbColor.Red = 0; pRgbColor.Green = 255; pRgbColor.Blue = 0; //创建颜色分级 IAlgorithmicColorRamp pRamp = new AlgorithmicColorRamp(); pRamp.Size = 255; pRamp.FromColor = pFromColor; pRamp.ToColor = pToColor; bool ok = true; pRamp.CreateRamp(out ok); //把颜色分级插入着色中并选择一个波段 pStretchRen.BandIndex = 0; pStretchRen.ColorRamp = pRamp; pRasRen.Update(); IRasterLayer pRLayer = new RasterLayer(); pRLayer.CreateFromRaster(pRaster); pRLayer.Renderer = pStretchRen as IRasterRenderer; return(pRLayer); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } }
/// <summary> /// Generates a raster renderer using the provided settings /// </summary> /// <returns>IRasterRenderer</returns> private static IRasterRenderer GenerateRasterRenderer(IRaster pRaster) { IRasterStretchColorRampRenderer pStretchRen = new RasterStretchColorRampRenderer(); //IRasterUniqueValueRenderer pStretchRen = new RasterUniqueValueRenderer(); IRasterRenderer pRasRen = (IRasterRenderer)pStretchRen; pRasRen.Raster = pRaster; pRasRen.Update(); IRgbColor pFromColor = new RgbColorClass(); pFromColor.Red = 255; pFromColor.Green = 0; pFromColor.Blue = 0; IRgbColor pToColor = new RgbColorClass(); pToColor.Red = 0; pToColor.Green = 255; pToColor.Blue = 0; IAlgorithmicColorRamp pRamp = new AlgorithmicColorRamp(); pRamp.Size = 255; pRamp.FromColor = pFromColor; pRamp.ToColor = pToColor; bool bOK; pRamp.CreateRamp(out bOK); pStretchRen.BandIndex = 0; pStretchRen.ColorRamp = pRamp; pRasRen.Update(); pRaster = null; pRasRen = null; pRamp = null; pToColor = null; pFromColor = null; return((IRasterRenderer)pStretchRen); }
private void btnStretch_Click(object sender, EventArgs e) { IMap map = axMapControl1.ActiveView.FocusMap; IRasterLayer rLayer = map.get_Layer(0) as IRasterLayer; IRaster raster = rLayer.Raster; IRasterStretchColorRampRenderer stretchRen = new RasterStretchColorRampRenderer(); IRasterRenderer rasRen = stretchRen as IRasterRenderer; rasRen.Raster = raster; rasRen.Update(); IRgbColor fromColor = new RgbColor(); fromColor.Red = 255; fromColor.Green = 0; fromColor.Blue = 0; IRgbColor toColor = new RgbColor(); toColor.Red = 0; toColor.Green = 255; toColor.Blue = 0; IAlgorithmicColorRamp ramp = new AlgorithmicColorRamp(); ramp.Size = 255; ramp.FromColor = fromColor; ramp.ToColor = toColor; bool bTrue = true; //Special syntax ramp.CreateRamp(out bTrue); //plug this colorramp ubti renderer and select a band stretchRen.BandIndex = 1;//0 stretchRen.ColorRamp = ramp; rasRen.Update(); rLayer.Renderer = stretchRen as IRasterRenderer; axMapControl1.ActiveView.Refresh(); axTOCControl1.Update(); }
/// <summary> /// Occurs when this command is clicked /// </summary> /// public void RasterStretchColorMapRender(IRasterLayer pRasterlayer) { try { IRaster pRaster = pRasterlayer.Raster; int intTransPValue = 30; IColor pFromColor = new RgbColorClass(); //Red + (0x100 * Green) + (0x10000 * Blue); pFromColor.RGB = 255 + 0x100 * 255; IColor pToColor = new RgbColorClass(); pToColor.RGB = 0x10000 * 255; IRasterStretchColorRampRenderer pStretchRender = (IRasterStretchColorRampRenderer)pRasterlayer.Renderer; IRasterRenderer pRasterRender = default(IRasterRenderer); pRasterRender = (IRasterRenderer)pStretchRender; pRasterRender.Raster = pRaster; pRasterRender.Update(); IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRamp(); pColorRamp.Size = 255; pColorRamp.FromColor = pFromColor; pColorRamp.ToColor = pToColor; bool outvalue = true; pColorRamp.CreateRamp(out outvalue); pStretchRender.BandIndex = 0; pStretchRender.ColorRamp = pColorRamp; if (intTransPValue > 0) { IRasterDisplayProps pRRenProp = (IRasterDisplayProps)pStretchRender; pRRenProp.TransparencyValue = intTransPValue; } pRasterRender.Update(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
public static IRasterStretchColorRampRenderer RasterStretchRenderer(IRasterLayer irasterLayer_0) { bool flag; IRasterStretchColorRampRenderer rasterStretchColorRampRenderer; try { IRasterStretchColorRampRenderer rasterStretchColorRampRendererClass = new RasterStretchColorRampRenderer(); IRasterRenderer raster = (IRasterRenderer)rasterStretchColorRampRendererClass; raster.Raster = irasterLayer_0.Raster; raster.Update(); rasterStretchColorRampRendererClass.BandIndex = 0; IAlgorithmicColorRamp algorithmicColorRampClass = new AlgorithmicColorRamp(); IColor rgbColorClass = new RgbColor(); (rgbColorClass as IRgbColor).Red = 255; (rgbColorClass as IRgbColor).Red = 0; (rgbColorClass as IRgbColor).Green = 0; (rgbColorClass as IRgbColor).Blue = 0; IColor color = new RgbColor(); (color as IRgbColor).Red = 255; (color as IRgbColor).Green = 255; (color as IRgbColor).Blue = 255; algorithmicColorRampClass.Size = 255; algorithmicColorRampClass.FromColor = rgbColorClass; algorithmicColorRampClass.ToColor = color; algorithmicColorRampClass.CreateRamp(out flag); rasterStretchColorRampRendererClass.ColorRamp = algorithmicColorRampClass; raster.Update(); rasterStretchColorRampRenderer = raster as IRasterStretchColorRampRenderer; } catch (Exception exception) { Debug.WriteLine(exception.Message); rasterStretchColorRampRenderer = null; } return(rasterStretchColorRampRenderer); }
public static void UsingRasterStretchColorRampRenderer(IRasterLayer irasterLayer_0) { bool flag; IRaster raster = irasterLayer_0.Raster; IRasterStretchColorRampRenderer renderer = new RasterStretchColorRampRenderer(); IRasterRenderer renderer2 = renderer as IRasterRenderer; renderer2.Raster = raster; renderer2.Update(); IColor color = ColorManage.CreatColor(255, 0, 0); IColor color2 = ColorManage.CreatColor(0, 255, 0); IAlgorithmicColorRamp ramp = new AlgorithmicColorRamp { Size = 255, FromColor = color, ToColor = color2 }; ramp.CreateRamp(out flag); renderer.BandIndex = 0; renderer.ColorRamp = ramp; renderer2.Update(); irasterLayer_0.Renderer = renderer as IRasterRenderer; }
/*创建枚举色彩 * */ public IColorRamp CreateAlgorithmicColorRamp(int size = 2, IRgbColor fromcolor = null, IRgbColor tocolor = null, esriColorRampAlgorithm alogrithm = esriColorRampAlgorithm.esriCIELabAlgorithm) { if (fromcolor == null) { fromcolor = getRGB(25, 96, 200) as IRgbColor; } if (tocolor == null) { tocolor = getRGB(0, 55, 66) as IRgbColor; } IAlgorithmicColorRamp algColorRamp = new AlgorithmicColorRamp(); algColorRamp.FromColor = fromcolor; algColorRamp.ToColor = tocolor; algColorRamp.Algorithm = alogrithm; algColorRamp.Size = size; bool btrue = true; algColorRamp.CreateRamp(out btrue); return(algColorRamp); }
private void btnOK_Click(object sender, EventArgs e) { // valida os campos if (!this.ValidarCampos()) { return; } this.Cursor = Cursors.WaitCursor; //enviar os parametros pra function do banco try { var incidenciaDoencaEmUnidadeSaude = new DoencaEmUnidadeSaudeRepositorio(); //retorna uma lista de unidades de saude com incidencia da doença escolhida var listaIncidenciaDoencaEmDistritosSanitarios = incidenciaDoencaEmUnidadeSaude.GerarMapaTematicoEmDistritosSanitarios((int)this.cmbDoenca.SelectedValue, this.dateTPDe.Value.Year, this.dateTPAte.Value.Year); listaIncidenciaDoencaEmDistritosSanitarios.Count.ToString(); //criar a Feature Class IFeatureClass featureClass = CreateNewShapeFile(@"C:\Sistemas\GestaoSMS\Files\Mapas\MapaIncidencia" + cmbDoenca.Text + "EmDistritosSanitarios" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".shp"); //criar uma feature buffer IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer(); //campo nome int indexNome = featureClass.FindField("nome"); //campo incidências int indexIncidencia = featureClass.FindField("incidencia"); //criar um feature cursor com buffer ativado IFeatureCursor featureCursor = featureClass.Insert(true); foreach (MapaDoencaEmDistritoSanitario incidencia in listaIncidenciaDoencaEmDistritosSanitarios) { //passar de Wkb para IGeometry var geometry = WKBToGeometry(incidencia.DistritosSanitarios); //atribuir a geometria ao buffer featureBuffer.Shape = geometry; featureBuffer.set_Value(indexNome, incidencia.Nome); featureBuffer.set_Value(indexIncidencia, incidencia.TotalIncidencias); //inserir a feature na featureclass featureCursor.InsertFeature(featureBuffer); } featureCursor.Flush(); Marshal.FinalReleaseComObject(featureCursor); try { //cria featureLayer IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.FeatureClass = featureClass; if (featureLayer != null) { //cria a geofeaturelayer IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer; //ativar os Labels //geoFeatureLayer.DisplayAnnotation = true; //tabela dos dados ITable table = (ITable)featureClass; //define o metodo de classificacao IClassifyGEN classifyGEN = new NaturalBreaks(); //objetos com array de frequencia de dados e valores dos dados object dataFrequency; object dataValues; //histograma ITableHistogram tableHistogram = new TableHistogramClass(); IHistogram histogram = (IHistogram)tableHistogram; tableHistogram.Field = "incidencia"; tableHistogram.Table = table; histogram.GetHistogram(out dataValues, out dataFrequency); double[] data = dataValues as double[]; int[] freq = dataFrequency as int[]; classifyGEN.Classify(data, freq, 5); //Renderer de simbolos proporcionais IClassBreaksRenderer render = new ClassBreaksRenderer(); double[] cb = (double[])classifyGEN.ClassBreaks; render.Field = "incidencia"; render.BreakCount = 5; //render.MinimumBreak = listaIncidenciaDoencaEmDistritosSanitarios.Min(p => p.TotalIncidencias); render.MinimumBreak = cb[0]; //define a escala de cores IRgbColor color1 = new RgbColor(); IRgbColor color2 = new RgbColor(); color1.Red = 255; color1.Green = 255; color1.Blue = 0; color2.Red = 140; color2.Green = 23; color2.Blue = 23; IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRamp(); colorRamp.FromColor = color1; colorRamp.ToColor = color2; colorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; colorRamp.Size = 5; bool ok; colorRamp.CreateRamp(out ok); IEnumColors enumColors = colorRamp.Colors; enumColors.Reset(); IClassBreaksUIProperties uiProperties = (IClassBreaksUIProperties)render; uiProperties.ColorRamp = "Custom"; //loop para definir o estilo de cada geometria de distrito sanitario for (int i = 0; i < 5; i++) { if (i != 0) { render.Break[i] = cb[i + 1]; render.Label[i] = (cb[i] + 1).ToString("0") + " - " + cb[i + 1].ToString("0"); uiProperties.LowBreak[i] = cb[i] + 1; } else { render.Break[i] = cb[i + 1]; render.Label[i] = "0 - " + cb[i + 1].ToString("0"); uiProperties.LowBreak[i] = cb[i] + 1; } ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(); simpleFillSymbol.Color = enumColors.Next(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; ISymbol symbolteste = simpleFillSymbol as ISymbol; render.Symbol[i] = (ISymbol)symbolteste; } //carregar o shape no mapa geoFeatureLayer.FeatureClass = featureClass; geoFeatureLayer.Name = featureClass.AliasName; geoFeatureLayer.Visible = true; geoFeatureLayer.Renderer = (IFeatureRenderer)render; ArcMap.Document.FocusMap.AddLayer(geoFeatureLayer); } MessageBox.Show("O mapa de incidência da doença [" + cmbDoenca.Text + "] nos Distritos Sanitários foi gerado com sucesso!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch (Exception ex) { MostrarErro(ex); MessageBox.Show("Escolha um período que contenha incidências da doença [" + cmbDoenca.Text + "].", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { this.MostrarErro(ex); } finally { this.Cursor = Cursors.Default; } }
public void Render_Layers() { IMxDocument pMxDoc; pMxDoc = (IMxDocument)ArcMap.Application.Document; IMap pMap; pMap = pMxDoc.FocusMap; string strChoice = null; //** Giving the user a choice of 3 predefined maps strChoice = Interaction.InputBox("1 - U.S. States, " + Environment.NewLine + "2 - Major Cities, " + Environment.NewLine + "3 - State Polygon Area Rank", "Please choose a map."); if (string.IsNullOrEmpty(strChoice)) { return; } IWorkspaceFactory pWFactory; pWFactory = new ShapefileWorkspaceFactory(); IWorkspace pWorkspace; pWorkspace = pWFactory.OpenFromFile("C:\\GEOG489\\Lesson1-2", 0); IFeatureWorkspace pFeatureWorkspace; pFeatureWorkspace = (IFeatureWorkspace)pWorkspace; IFeatureLayer pFLayer; pFLayer = new FeatureLayer(); IGeoFeatureLayer pGeoFLayer; pGeoFLayer = (IGeoFeatureLayer)pFLayer; IFeatureClass pFClass; ITable pTable; IClassify pClasses; ITableHistogram pTableHist; IHistogram pHist; IClassBreaksRenderer pCBR; IClassBreaksUIProperties pUIProperties; ILegendInfo pLegendInfo; object Frequencies = null; object Values = null; if (strChoice == "1") { //** User gets a Unique Value rendering of U.S. States by sub-region pFClass = pFeatureWorkspace.OpenFeatureClass("us_boundaries.shp"); pFLayer.FeatureClass = pFClass; pFLayer.Name = "U.S. States"; pMap.AddLayer(pFLayer); IUniqueValueRenderer pUVRender; pUVRender = new UniqueValueRenderer(); //** Setting default symbol for features that don't have a value in //** the classification field ISimpleFillSymbol pSymDefault; pSymDefault = new SimpleFillSymbol(); pSymDefault.Style = ESRI.ArcGIS.Display.esriSimpleFillStyle.esriSFSSolid; pSymDefault.Outline.Width = 0.4; //** These properties should be set prior to adding values pUVRender.FieldCount = 1; //** Can classify based on up to 3 fields pUVRender.Field[0] = "NAME"; //** Name of the 1st (only) field pUVRender.DefaultSymbol = (ISymbol)pSymDefault; pUVRender.UseDefaultSymbol = true; IQueryFilter pQFilter; pQFilter = new QueryFilter(); //** empty QueryFilter same as selecting all recs IFeatureCursor pFCursor; pFCursor = pFClass.Search(pQFilter, false); //** getting all features //** Make the color ramp we will use for the symbols in the renderer. //** Colors should be random for Unique Value, as opposed to light-to-dark. //** Make settings for hue, saturation, value, and seed to have random //** colors generated within certain limits. IRandomColorRamp pRamp; pRamp = new RandomColorRamp(); pRamp.MinSaturation = 25; pRamp.MaxSaturation = 45; pRamp.MinValue = 85; pRamp.MaxValue = 100; pRamp.StartHue = 205; pRamp.EndHue = 320; pRamp.UseSeed = true; pRamp.Seed = 25; IFeature pFeature; int n = 0; int i = 0; n = pFClass.FeatureCount(pQFilter); //** Getting total count of state features //** Loop through the features while (i != n) { ISimpleFillSymbol pSymX; pSymX = new SimpleFillSymbol(); //** Move to the next feature and assign the value in the Sub_region field to a var pFeature = pFCursor.NextFeature(); string strVal = null; strVal = pFeature.Value[2].ToString(); //** NAME Field is at this index in fields collection //** Test to see if we've already added this value //** to the renderer, if not, then add it. bool blnAdded = false; blnAdded = false; int x = 0; //** First time through, ValueCount = 0 for (x = 0; x <= (pUVRender.ValueCount - 1); x++) { if (pUVRender.Value[x] == strVal) { blnAdded = true; break; } } //** Value not yet encountered, must add it if (blnAdded == false) { pUVRender.AddValue(strVal, "Predominant Term", (ISymbol)pSymDefault); pUVRender.Label[strVal] = strVal; pUVRender.Symbol[strVal] = (ISymbol)pSymX; //** All values get same symbol at first, //** colors assigned later } i = i + 1; } //** Can size the color ramp and assign the colors, now that the //** number of unique values is known. pRamp.Size = pUVRender.ValueCount; bool blnRamp; pRamp.CreateRamp(out blnRamp); //** Create an enum of colors from the color ramp and initialize it IEnumColors pColors; pColors = pRamp.Colors; pColors.Reset(); int y = 0; //** Loop through each unique value, setting its symbol's color for (y = 0; y <= (pUVRender.ValueCount - 1); y++) { string strRendVal = null; strRendVal = pUVRender.Value[y]; if (!string.IsNullOrEmpty(strRendVal)) { ISimpleFillSymbol pSym; pSym = (ISimpleFillSymbol)pUVRender.Symbol[strRendVal]; pSym.Color = pColors.Next(); pUVRender.Symbol[strRendVal] = (ISymbol)pSym; } } //** If you didn't use a color ramp that was predefined //** in a style, use "Custom" here, otherwise //** use the name of the color ramp you chose. pUVRender.ColorScheme = "Custom"; pUVRender.FieldType[0] = true; //** Set to True since Sub_region is a string pGeoFLayer.Renderer = (IFeatureRenderer)pUVRender; //** Make sure the symbology tab shows the correct info. IRendererPropertyPage pRendPropPage; pRendPropPage = (IRendererPropertyPage) new UniqueValuePropertyPage(); pGeoFLayer.RendererPropertyPageClassID = pRendPropPage.ClassID; } else if (strChoice == "2") { //** User gets a graduated symbol map of U.S. Cities pFClass = pFeatureWorkspace.OpenFeatureClass("us_cities.shp"); pFLayer.FeatureClass = pFClass; pFLayer.Name = "Major U.S. Cities"; pGeoFLayer = (IGeoFeatureLayer)pFLayer; pMap.AddLayer(pFLayer); //** Switching to the ITable interface; FeatureClass is a type of Table pTable = (ITable)pFClass; //** Creating a new quantile classification pClasses = (IClassify) new Quantile(); //** Must create a TableHistogram to generate classes //** Need both ITableHistogram and IHistogram interfaces pTableHist = (ITableHistogram) new TableHistogram(); pHist = (IHistogram)pTableHist; //** Set the table and field for the histogram, then use GetHistogram to //** get arrays of values and corresponding frequencies pTableHist.Field = "POPCLASS"; pTableHist.Table = pTable; pHist.GetHistogram(out Values, out Frequencies); //** Assign the arrays of values and frequencies to the quantile classification //** then break the data into 5 classes pClasses.SetHistogramData(Values, Frequencies); pClasses.Classify(4); double[] classBreaks = new double[4]; classBreaks = (double[])pClasses.ClassBreaks; //** Ready to render the data pCBR = new ClassBreaksRenderer(); pCBR.BreakCount = 4; pCBR.Field = "POPCLASS"; pCBR.MinimumBreak = classBreaks[0]; //** ClassBreak(0) is min value of 1st class int j = 0; //** Loop thru each class, setting the renderers breaks //** The renderer's breaks are 0-based, quantile's breaks are 1-based for (j = 0; j <= (pCBR.BreakCount - 1); j++) { pCBR.Break[j] = classBreaks[j + 1]; pCBR.Label[j] = classBreaks[j] + " - " + classBreaks[j + 1]; } //** Ready for symbols ISimpleMarkerSymbol pCitySym; //** Setting the smallest symbol size double dblFromSize = 0; dblFromSize = 4; //** Setting the largest symbol size double dblToSize = 0; dblToSize = 16; //** Calculating the change in size between classes based on the min size, //** max size, and # of classes double dblStep = 0; dblStep = (dblToSize - dblFromSize) / (pCBR.BreakCount - 1); //** Setting the foreground color of the symbols IRgbColor pColor; pColor = new RgbColor(); pColor.Red = 179; pColor.Green = 235; pColor.Blue = 255; //** Setting the outline color of the symbols //** No color settings means black outline (r=0, g=0, b=0) IRgbColor pOlColor; pOlColor = new RgbColor(); int k = 0; //** Setting symbol for each class for (k = 0; k <= pCBR.BreakCount - 1; k++) { pCitySym = new SimpleMarkerSymbol(); pCitySym.Color = pColor; pCitySym.Outline = true; pCitySym.OutlineColor = pOlColor; pCitySym.OutlineSize = 1; pCitySym.Size = dblFromSize + (dblStep * Convert.ToDouble(k)); pCBR.Symbol[k] = (ISymbol)pCitySym; } //** Assigning the ClassBreaksRenderer to the layer pGeoFLayer.Renderer = (IFeatureRenderer)pCBR; pUIProperties = (IClassBreaksUIProperties)pCBR; pUIProperties.LowBreak[0] = pCBR.MinimumBreak; int m = 0; for (m = 1; m <= pCBR.BreakCount - 1; m++) { pUIProperties.LowBreak[m] = classBreaks[m]; } //** Creating a heading for the legend in the Table of Contents pLegendInfo = (ILegendInfo)pCBR; //qi pLegendInfo.LegendGroup[0].Heading = "Population Class"; pLegendInfo.SymbolsAreGraduated = false; } else if (strChoice == "3") { //** User gets a graduated color map of state population normalized by area pFClass = pFeatureWorkspace.OpenFeatureClass("us_boundaries.shp"); pFLayer.FeatureClass = pFClass; pFLayer.Name = "State Polygon Area Rank"; pGeoFLayer = (IGeoFeatureLayer)pFLayer; pMap.AddLayer(pFLayer); //** Very similar to previous example pTable = (ITable)pFClass; pClasses = (IClassify) new Quantile(); pTableHist = (ITableHistogram) new TableHistogram(); pHist = (IHistogram)pTableHist; pTableHist.Field = "Shape_Area"; pTableHist.Table = pTable; //pTableHist.NormField = "Rank" '** Setting the normalization field before getting histogram pHist.GetHistogram(out Values, out Frequencies); pClasses.SetHistogramData(Values, Frequencies); pClasses.Classify(5); double[] classBreaks = new double[4]; classBreaks = (double[])pClasses.ClassBreaks; pCBR = new ClassBreaksRenderer(); //** Making normalization settings for the renderer //Dim pNorm As IDataNormalization //pNorm = pCBR //pNorm.NormalizationField = "Rank" //pNorm.NormalizationType = esriDataNormalization.esriNormalizeByField pCBR.BreakCount = 5; pCBR.Field = "Shape_Area"; pCBR.MinimumBreak = classBreaks[0]; int t = 0; pUIProperties = (IClassBreaksUIProperties)pCBR; pUIProperties.LowBreak[0] = pCBR.MinimumBreak; for (t = 0; t <= Information.UBound(classBreaks) - 1; t++) { pCBR.Break[t] = classBreaks[t + 1]; //** Want to round the class break values in the class labels //** Use the NumericFormat class to set up a 1-decimal format INumericFormat pNumericFormat; pNumericFormat = (INumericFormat) new NumericFormat(); pNumericFormat.RoundingOption = ESRI.ArcGIS.esriSystem.esriRoundingOptionEnum.esriRoundNumberOfDecimals; pNumericFormat.RoundingValue = 1; INumberFormat pNumberFormat; pNumberFormat = (INumberFormat)pNumericFormat; string strRndVal1 = null; string strRndVal2 = null; //** Using ValueToString method to convert the numbers into the desired format strRndVal1 = pNumberFormat.ValueToString(classBreaks[t]); strRndVal2 = pNumberFormat.ValueToString(classBreaks[t + 1]); pCBR.Label[t] = strRndVal1 + " - " + strRndVal2; } pGeoFLayer.Renderer = (IFeatureRenderer)pCBR; for (t = 1; t <= 4; t++) { pUIProperties.LowBreak[t] = classBreaks[t]; } //** Ready to set colors //** Want to use AlgorithmicColorRamp to ramp from one color to another IEnumColors pColorEnum; IAlgorithmicColorRamp pAColorRamp; IRgbColor pFromColor; IRgbColor pToColor; //** Setting up the algorithmic color ramp pFromColor = new RgbColor(); pFromColor.RGB = Information.RGB(242, 233, 250); // lavender pToColor = new RgbColor(); pToColor.RGB = Information.RGB(56, 45, 121); // deep purple pAColorRamp = new AlgorithmicColorRamp(); pAColorRamp.Algorithm = ESRI.ArcGIS.Display.esriColorRampAlgorithm.esriHSVAlgorithm; pAColorRamp.Size = 5; //** # of classes pAColorRamp.FromColor = pFromColor; pAColorRamp.ToColor = pToColor; bool blnRamp; pAColorRamp.CreateRamp(out blnRamp); pColorEnum = pAColorRamp.Colors; pColorEnum.Reset(); int s = 0; //** Loop thru the classes, creating a new symbol, assigning the next color //** created by the ramp, and assigning the symbol to the renderer. for (s = 0; s <= 4; s++) { ISimpleFillSymbol pSFSym; pSFSym = new SimpleFillSymbol(); pSFSym.Color = pColorEnum.Next(); pCBR.Symbol[s] = (ISymbol)pSFSym; } //** Creating a heading for the legend in the Table of Contents pLegendInfo = (ILegendInfo)pCBR; //qi pLegendInfo.LegendGroup[0].Heading = "Area (Degrees)"; pLegendInfo.SymbolsAreGraduated = false; } //** Refreshing the Table of Contents pMxDoc.ActiveView.ContentsChanged(); pMxDoc.UpdateContents(); //** Re-drawing the map pMxDoc.ActiveView.Refresh(); }
private ESRI.ArcGIS.Display.IColor GetCombinedColor(IColor pColor1, IColor pColor2, EColorCombinationType eCombinationMethod, IColor pOriginColor) { // combines the input colors based on m_eColorCombinationMethod // (11/08/04) -- RGB and enuLabLChColorRamp aren't used by GUI IColor pOutColor = null; long MyOLE_COLOR = 0; // As OLE_COLOR in VB6 IRgbColor pMainRGBColor = null; IRgbColor pVariationRGBColor = null; IRgbColor pMergedRGBColor = null; bool bOK = false; IAlgorithmicColorRamp pAlgorithmicCR = null; // if either of the colors are null, then don't run the color through any algorithm, // instead, just return the other color. if both are null, then return a null color if (pColor1.NullColor) { pOutColor = pColor2; } else if (pColor2.NullColor) { pOutColor = pColor1; } else if (eCombinationMethod == EColorCombinationType.enuComponents) { // HSV components // create a new HSV color IHsvColor pHSVDrawColor = null; pHSVDrawColor = new HsvColor(); // get HSV values from Color1 and Color2 and assign to pHSVDrawColor IHsvColor pHSVColor1 = null; IHsvColor pHSVColor2 = null; // (new 4/27/04) didn't think I had to do this... //pHSVColor1 = pColor1 //pHSVColor2 = pColor2 pHSVColor1 = new HsvColor(); pHSVColor1.RGB = pColor1.RGB; pHSVColor2 = new HsvColor(); pHSVColor2.RGB = pColor2.RGB; pHSVDrawColor.Hue = pHSVColor1.Hue; pHSVDrawColor.Saturation = pHSVColor2.Saturation; pHSVDrawColor.Value = pHSVColor2.Value; pOutColor = pHSVDrawColor; } else if (eCombinationMethod == EColorCombinationType.enuRGBAverage) { // use additive color model to merge the two colors MyOLE_COLOR = pColor1.RGB; pMainRGBColor = new RgbColor(); pMainRGBColor.RGB = (int)MyOLE_COLOR; MyOLE_COLOR = pColor2.RGB; pVariationRGBColor = new RgbColor(); pVariationRGBColor.RGB = (int)MyOLE_COLOR; // merged color = RGB average of the two colors pMergedRGBColor = new RgbColor(); pMergedRGBColor.Red = (pMainRGBColor.Red + pVariationRGBColor.Red) / 2; pMergedRGBColor.Green = (pMainRGBColor.Green + pVariationRGBColor.Green) / 2; pMergedRGBColor.Blue = (pMainRGBColor.Blue + pVariationRGBColor.Blue) / 2; pOutColor = pMergedRGBColor; } else if ((eCombinationMethod == EColorCombinationType.enuCIELabColorRamp) | (eCombinationMethod == EColorCombinationType.enuLabLChColorRamp)) { // use color ramp and take central color between the two colors pAlgorithmicCR = new AlgorithmicColorRamp(); if (m_eColorCombinationMethod == EColorCombinationType.enuCIELabColorRamp) pAlgorithmicCR.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm; else pAlgorithmicCR.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm; pAlgorithmicCR.Size = 3; pAlgorithmicCR.FromColor = pColor1; pAlgorithmicCR.ToColor = pColor2; pAlgorithmicCR.CreateRamp(out bOK); pOutColor = pAlgorithmicCR.get_Color(1); // middle color in ramp } else // EColorCombinationType.enuCIELabMatrix { double[] iLab1 = new double[4]; // L, a, b values for Color1 double[] iLab2 = new double[4]; // L, a, b values for Color2 double[] iLabOrig = new double[4]; // L, a, b values for pOriginColor pColor1.GetCIELAB(out iLab1[0], out iLab1[1], out iLab1[2]); pColor2.GetCIELAB(out iLab2[0], out iLab2[1], out iLab2[2]); pOriginColor.GetCIELAB(out iLabOrig[0], out iLabOrig[1], out iLabOrig[2]); double[] iLabOut = new double[4]; // add color1 vector and color2 vector, then subtract the origin color vector iLabOut[0] = iLab1[0] + iLab2[0] - iLabOrig[0]; iLabOut[1] = iLab1[1] + iLab2[1] - iLabOrig[1]; iLabOut[2] = iLab1[2] + iLab2[2] - iLabOrig[2]; CorrectLabOutofRange(ref iLabOut[0], ref iLabOut[1], ref iLabOut[2]); IHsvColor pHSVColor = null; pHSVColor = new HsvColor(); pHSVColor.SetCIELAB(iLabOut[0], iLabOut[1], iLabOut[2]); pOutColor = pHSVColor; } return pOutColor; }
/// <summary> /// Generates a raster renderer using the provided settings /// </summary> /// <returns>IRasterRenderer</returns> private static IRasterRenderer GenerateRasterRenderer(IRaster pRaster) { IRasterStretchColorRampRenderer pStretchRen = new RasterStretchColorRampRenderer(); //IRasterUniqueValueRenderer pStretchRen = new RasterUniqueValueRenderer(); IRasterRenderer pRasRen = (IRasterRenderer)pStretchRen; pRasRen.Raster = pRaster; pRasRen.Update(); IRgbColor pFromColor = new RgbColorClass(); pFromColor.Red = 255; pFromColor.Green = 0; pFromColor.Blue = 0; IRgbColor pToColor = new RgbColorClass(); pToColor.Red = 0; pToColor.Green = 255; pToColor.Blue = 0; IAlgorithmicColorRamp pRamp = new AlgorithmicColorRamp(); pRamp.Size = 255; pRamp.FromColor = pFromColor; pRamp.ToColor = pToColor; bool bOK; pRamp.CreateRamp(out bOK); pStretchRen.BandIndex = 0; pStretchRen.ColorRamp = pRamp; pRasRen.Update(); pRaster = null; pRasRen = null; pRamp = null; pToColor = null; pFromColor = null; return (IRasterRenderer)pStretchRen; }
/// <summary> /// 拉伸渲染raster图层 /// </summary> /// <params name="pRLayer">raster图层</params> /// <remarks></remarks> public void UsingRasterStretchColorRampRender(IRasterLayer pRLayer) { //获得图层 IRaster pRaster = default(IRaster); pRaster = pRLayer.Raster; //创建渲染并转换到栅格渲染 IRasterStretchColorRampRenderer pStretchRen = default(IRasterStretchColorRampRenderer); pStretchRen = new RasterStretchColorRampRenderer(); IRasterRenderer pRasRen = default(IRasterRenderer); pRasRen = (IRasterRenderer)pStretchRen; //栅格渲染赋值和更新 pRasRen.Raster = pRaster; pRasRen.Update(); //定义起止颜色 IRgbColor pFromColor = new RgbColorClass(); pFromColor.Red = 0; pFromColor.Green = 255; pFromColor.Blue = 0; IRgbColor pToColor = new RgbColorClass(); pToColor.Red = 255; pToColor.Green = 0; pToColor.Blue = 0; //创建颜色条 IAlgorithmicColorRamp pRamp = new AlgorithmicColorRamp(); pRamp.Size = 255; pRamp.FromColor = pFromColor; pRamp.ToColor = pToColor; bool bOK; pRamp.CreateRamp(out bOK); //插入颜色条和选择渲染波段 pStretchRen.BandIndex = 0; pStretchRen.ColorRamp = pRamp; //用新的设置更新渲染并赋值给图层 pRasRen.Update(); pRLayer.Renderer = (IRasterRenderer)pStretchRen; //释放内存 pRLayer = null; pRaster = null; pStretchRen = null; pRasRen = null; pRamp = null; pToColor = null; pFromColor = null; }
public static void Symbology_GraduatedColors(IFeatureLayer featureLayer, string fieldName, int numClasses, IMapControl2 mapControl, AxTOCControl tocControl) { // 获取渲染字段的值及其出现的频率 ITable pTable = featureLayer as ITable; IBasicHistogram pBasicHistogram = new BasicTableHistogramClass() { Field = fieldName, Table = pTable }; object dataFrequency, dataValue; // 频率和值 pBasicHistogram.GetHistogram(out dataValue, out dataFrequency); // 数据分级 IClassifyGEN pClassifyGEN = new EqualIntervalClass(); // 等间隔 //IClassifyGEN pClassifyGEN = new GeometricalIntervalClass(); // 几何间隔 //IClassifyGEN pClassifyGEN = new NaturalBreaksClass(); // 自然裂变 //IClassifyGEN pClassifyGEN = new QuantileClass(); // 分位数 //IClassifyGEN pClassifyGEN = new StandardDeviationClass(); // 标准偏差 try { pClassifyGEN.Classify(dataValue, dataFrequency, numClasses); } catch { } double[] Classes = pClassifyGEN.ClassBreaks as double[]; int ClassesCount = Classes.GetUpperBound(0); IClassBreaksRenderer pRenderer = new ClassBreaksRendererClass() { // 分类字段 分类数目 升序 Field = fieldName, BreakCount = ClassesCount, SortClassesAscending = true }; // 生成颜色色带 IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRamp() { FromColor = GetRgbColor(255, 200, 200), ToColor = GetRgbColor(255, 0, 0), Size = ClassesCount }; bool bOk = false; pColorRamp.CreateRamp(out bOk); IEnumColors pColors = pColorRamp.Colors; // 逐一设置填充符号及每一分级的分级断点 for (int index = 0; index < ClassesCount; index++) { IColor pColor = pColors.Next(); ISymbol pSymbol = null; switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: pSymbol = new SimpleMarkerSymbolClass() { Color = pColor }; break; case esriGeometryType.esriGeometryPolyline: pSymbol = new SimpleLineSymbolClass() { Color = pColor }; break; case esriGeometryType.esriGeometryPolygon: pSymbol = new SimpleFillSymbolClass() { Color = pColor }; break; } pRenderer.set_Symbol(index, pSymbol); // 每级的符号 pRenderer.set_Break(index, Classes[index + 1]); // 每级的断点 } (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer; mapControl.Refresh(); tocControl.Update(); }