Esempio n. 1
0
        internal static void UsingRasterClassifyRendered1(IRasterLayer irasterLayer_0, int int_0, string string_0)
        {
            bool    flag;
            IRaster raster = irasterLayer_0.Raster;
            IRasterClassifyColorRampRenderer o = new RasterClassifyColorRampRenderer();
            IRasterRenderer renderer2          = o as IRasterRenderer;

            renderer2.Raster = raster;
            o.ClassField     = string_0;
            o.ClassCount     = int_0;
            IClassify classify = new EqualInterval() as IClassify;
            UID       classID  = classify.ClassID;
            IRasterClassifyUIProperties properties = o as IRasterClassifyUIProperties;

            properties.ClassificationMethod = classID;
            renderer2.Update();
            IColorRamp ramp = ColorManage.CreateColorRamp();

            ramp.Size = int_0;
            ramp.CreateRamp(out flag);
            IFillSymbol symbol = new SimpleFillSymbol();

            for (int i = 0; i < o.ClassCount; i++)
            {
                symbol.Color = ramp.get_Color(i);
                o.set_Symbol(i, symbol as ISymbol);
            }
            renderer2.Update();
            irasterLayer_0.Renderer = o as IRasterRenderer;
            Marshal.ReleaseComObject(o);
            o = null;
        }
Esempio n. 2
0
        //分级渲染函数
        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("创建失败!");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Ge the render color of the input layer rendering with classified color ramp.
        /// </summary>
        /// <param name="layer">Input raster layer</param>
        /// <param name="value">Pixel value</param>
        /// <returns></returns>
        private static IColor GetRenderColor_Classified(ILayer layer, double value)
        {
            IRasterLayer rasterLayer = (IRasterLayer)layer;

            // Check whether the value is NoData value
            IRasterProps rasterProps = (IRasterProps)rasterLayer.Raster;

            System.Array noDataValue = (System.Array)rasterProps.NoDataValue;
            if ((rasterProps.NoDataValue != null) && (Convert.ToDouble(noDataValue.GetValue(0)) == value))
            {
                return(null);
            }

            RasterClassifyColorRampRenderer rasterRender = (RasterClassifyColorRampRenderer)rasterLayer.Renderer;
            IRasterRendererColorRamp        colorRamp    = (IRasterRendererColorRamp)rasterRender;

            for (int index = 0; index < rasterRender.ClassCount - 1; index++)
            {
                if (value <= rasterRender.Break[index])
                {
                    return(colorRamp.ColorRamp.Color[index]);
                }
            }

            return(colorRamp.ColorRamp.Color[rasterRender.ClassCount - 1]);
        }
Esempio n. 4
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();
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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;
        }
Esempio n. 10
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;
        }
Esempio n. 11
0
        /// <summary>
        /// 分类色带渲染
        /// </summary>
        /// <param name="classCount">分类数</param>
        /// <param name="colorRamp">色带</param>
        public void ClassifyColorRampRenderer(ILayer pLayerR, IColorRamp colorRamp, string classfield, System.Windows.Forms.DataGridView datagridview)
        {
            try
            {
                IRasterLayer    pRasterLayer    = pLayerR as IRasterLayer;
                IRaster         raster          = pRasterLayer.Raster;
                IRasterRenderer pRasterRenderer = new RasterClassifyColorRampRenderer() as IRasterRenderer;
                pRasterRenderer.Raster = raster;
                IRasterClassifyColorRampRenderer classifyRenderer = pRasterRenderer as IRasterClassifyColorRampRenderer;


                int classcount = datagridview.RowCount;
                classifyRenderer.ClassCount = classcount;
                classifyRenderer.ClassField = classfield;
                for (int i = 0; i < datagridview.RowCount; i++)
                {
                    classifyRenderer.set_Break(i, double.Parse(datagridview.Rows[i].Cells[0].Value.ToString()));
                }
                pRasterRenderer.Update();
                colorRamp.Size = 15;
                bool pOk;
                colorRamp.CreateRamp(out pOk);
                //create symbol for the classes
                IFillSymbol fillSymbol = new SimpleFillSymbol();
                for (int i = 0; i < classifyRenderer.ClassCount - 1; i++)
                {
                    fillSymbol.Color = colorRamp.get_Color(i);
                    classifyRenderer.set_Symbol(i, (ISymbol)fillSymbol);
                    classifyRenderer.set_Label(i, classifyRenderer.get_Break(i).ToString() + "—" + datagridview.Rows[i].Cells[1].Value.ToString());
                }
                pRasterLayer.Renderer = classifyRenderer as IRasterRenderer;
            }
            catch
            {
            }
        }
Esempio n. 12
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, "栅格渲染");
     }
 }