//分级渲染函数
        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("创建失败!");
            }
        }
Exemple #2
0
        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();
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        //更新色带渲染
        private void SingleClassifyRender(ILayer pLayerR, int NumOfClass, IColorRamp colorRamp)
        {
            // Get raster input from layer
            IRasterLayer pRLayer;

            pRLayer = pLayerR as IRasterLayer;
            IRaster pRaster;

            pRaster = pRLayer.Raster;

            //Create classfy renderer and QI RasterRenderer interface
            IRasterClassifyColorRampRenderer pClassRen;

            pClassRen = new RasterClassifyColorRampRenderer();
            IRasterRenderer pRasRen;

            pRasRen = (IRasterRenderer)pClassRen;

            //Set raster for the render and update
            pRasRen.Raster = pRaster;
            //pClassRen.ClassCount = NumOfClass;
            pClassRen.ClassCount = NumOfClass;

            //pRasRen.Update();


            //Create symbol for the classes
            IFillSymbol pFSymbol;

            pFSymbol = new SimpleFillSymbol();
            //http://blog.csdn.net/jack5s/article/details/48184819
            pRLayer.Renderer = (IRasterRenderer)pClassRen;  //label的设置,一定要放在RasterLayer.Renderer = RasterRender这句后面,否则无效
            //loop through the classes and apply the color and label
            int i;

            for (i = 0; i < pClassRen.ClassCount; i++)
            {
                pFSymbol.Color = colorRamp.get_Color(i);
                pClassRen.set_Symbol(i, (ISymbol)pFSymbol);
                pClassRen.set_Label(i, DataGridFilterData[i, 2].ToString());
                //pClassRen.set_Label(i, "Class" + i.ToString());
            }
            //Update the renderer and plug into layer
            //pRasRen.Update();
            pRLayer.Renderer = (IRasterRenderer)pClassRen;
        }
Exemple #8
0
        //更新色带渲染
        private void SingleClassifyRender(ILayer pLayerR, int NumOfClass, IColorRamp colorRamp)
        {
            // Get raster input from layer
            IRasterLayer pRLayer;

            pRLayer = pLayerR as IRasterLayer;
            IRaster pRaster;

            pRaster = pRLayer.Raster;

            //Create classfy renderer and QI RasterRenderer interface
            IRasterClassifyColorRampRenderer pClassRen;

            pClassRen = new RasterClassifyColorRampRenderer();
            IRasterRenderer pRasRen;

            pRasRen = (IRasterRenderer)pClassRen;

            //Set raster for the render and update
            pRasRen.Raster = pRaster;
            //pClassRen.ClassCount = NumOfClass;
            pClassRen.ClassCount = NumOfClass;

            //pRasRen.Update();


            //Create symbol for the classes
            IFillSymbol pFSymbol;

            pFSymbol = new SimpleFillSymbol();

            //loop through the classes and apply the color and label
            int i;

            for (i = 0; i < pClassRen.ClassCount; i++)
            {
                pFSymbol.Color = colorRamp.get_Color(i);
                pClassRen.set_Symbol(i, (ISymbol)pFSymbol);
                pClassRen.set_Label(i, "Class" + i.ToString());
            }
            //Update the renderer and plug into layer
            //pRasRen.Update();
            pRLayer.Renderer = (IRasterRenderer)pClassRen;
        }
Exemple #9
0
 public static void UsingRasterClassifyRendered(IRasterLayer irasterLayer_0, int int_0, string string_0)
 {
     try
     {
         bool        flag;
         IRaster     raster = irasterLayer_0.Raster;
         IRasterBand band   = (raster as IRasterBandCollection).Item(0);
         band.HasTable(out flag);
         if (flag)
         {
             int  num2;
             bool flag2;
             IRasterClassifyColorRampRenderer renderer = new RasterClassifyColorRampRenderer();
             IRasterRenderer renderer2 = renderer as IRasterRenderer;
             renderer2.Raster = raster;
             ITable          attributeTable = band.AttributeTable;
             ITableHistogram tableHistogram = new BasicTableHistogram() as ITableHistogram;
             tableHistogram.Field = string_0;
             tableHistogram.Table = attributeTable;
             ITableHistogram histogram = tableHistogram as ITableHistogram;
             double          maximum   = (histogram as IStatisticsResults).Maximum;
             IClassify       classify  = new EqualInterval() as IClassify;
             (classify as IClassifyMinMax).Minimum = (histogram as IStatisticsResults).Minimum;
             (classify as IClassifyMinMax).Maximum = (histogram as IStatisticsResults).Maximum;
             int_0--;
             classify.Classify(ref int_0);
             object classBreaks = classify.ClassBreaks;
             UID    classID     = classify.ClassID;
             IRasterClassifyUIProperties properties = renderer as IRasterClassifyUIProperties;
             properties.ClassificationMethod = classID;
             renderer.ClassCount             = int_0;
             renderer.ClassField             = string_0;
             for (num2 = 0; num2 < int_0; num2++)
             {
                 renderer.set_Break(num2, ((double[])classBreaks)[num2]);
             }
             IColorRamp ramp = ColorManage.CreateColorRamp();
             ramp.Size = int_0;
             ramp.CreateRamp(out flag2);
             IFillSymbol symbol = new SimpleFillSymbol();
             for (num2 = 0; num2 < renderer.ClassCount; num2++)
             {
                 double num4;
                 symbol.Color = ramp.get_Color(num2);
                 renderer.set_Symbol(num2, symbol as ISymbol);
                 double num3 = ((double[])classBreaks)[num2];
                 if (num2 == (renderer.ClassCount - 1))
                 {
                     num4 = maximum;
                 }
                 else
                 {
                     num4 = ((double[])classBreaks)[num2 + 1];
                 }
                 renderer.set_Label(num2, num3.ToString() + "-" + num4.ToString());
             }
             renderer2.Update();
             irasterLayer_0.Renderer = renderer as IRasterRenderer;
         }
         else
         {
             UsingRasterClassifyRendered1(irasterLayer_0, int_0, string_0);
         }
     }
     catch (Exception exception)
     {
         CErrorLog.writeErrorLog(null, exception, "栅格渲染");
     }
 }