Exemplo n.º 1
0
 private void cboBand_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.bool_0 && (this.cboBand.SelectedIndex != -1))
     {
         bool flag;
         IRasterStretchColorRampRenderer renderer = this.irasterStretchColorRampRenderer_0;
         IRasterRenderer renderer2 = (IRasterRenderer)renderer;
         renderer.BandIndex = this.cboBand.SelectedIndex;
         if (this.icolorRamp_0 == null)
         {
             IAlgorithmicColorRamp ramp = new AlgorithmicColorRampClass();
             IColor color = new RgbColorClass();
             (color as IRgbColor).Red   = 255;
             (color as IRgbColor).Red   = 0;
             (color as IRgbColor).Green = 0;
             (color as IRgbColor).Blue  = 0;
             IColor color2 = new RgbColorClass();
             (color2 as IRgbColor).Red   = 255;
             (color2 as IRgbColor).Green = 255;
             (color2 as IRgbColor).Blue  = 255;
             ramp.FromColor    = color;
             ramp.ToColor      = color2;
             this.icolorRamp_0 = ramp;
         }
         this.icolorRamp_0.Size = 255;
         this.icolorRamp_0.CreateRamp(out flag);
         renderer.ColorRamp = this.icolorRamp_0;
         renderer2.Update();
     }
 }
Exemplo n.º 2
0
 private void cboColorRamp_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.bool_0)
     {
         bool flag;
         this.icolorRamp_0 = this.cboColorRamp.GetSelectStyleGalleryItem().Item as IColorRamp;
         (this.irasterStretchColorRampRenderer_0 as IRasterRendererColorRamp).ColorScheme =
             this.cboColorRamp.Text;
         IRasterStretchColorRampRenderer renderer = this.irasterStretchColorRampRenderer_0;
         IRasterRenderer renderer2 = (IRasterRenderer)renderer;
         if (this.icolorRamp_0 == null)
         {
             IAlgorithmicColorRamp ramp = new AlgorithmicColorRampClass();
             IColor color = new RgbColorClass();
             (color as IRgbColor).Red   = 255;
             (color as IRgbColor).Red   = 0;
             (color as IRgbColor).Green = 0;
             (color as IRgbColor).Blue  = 0;
             IColor color2 = new RgbColorClass();
             (color2 as IRgbColor).Red   = 255;
             (color2 as IRgbColor).Green = 255;
             (color2 as IRgbColor).Blue  = 255;
             ramp.FromColor    = color;
             ramp.ToColor      = color2;
             this.icolorRamp_0 = ramp;
         }
         this.icolorRamp_0.Size = 255;
         this.icolorRamp_0.CreateRamp(out flag);
         renderer.ColorRamp = this.icolorRamp_0;
         renderer2.Update();
     }
 }
Exemplo n.º 3
0
        //创建颜色带
        private IColorRamp CreateAlgorithmicColorRamp(int count)
        {
            //创建一个新AlgorithmicColorRampClass对象
            IAlgorithmicColorRamp algColorRamp = new AlgorithmicColorRampClass();
            IRgbColor             fromColor    = new RgbColorClass();
            IRgbColor             toColor      = new RgbColorClass();

            //创建起始颜色对象
            fromColor.Red   = 255;
            fromColor.Green = 0;
            fromColor.Blue  = 0;
            //创建终止颜色对象
            toColor.Red   = 0;
            toColor.Green = 0;
            toColor.Blue  = 255;
            //设置AlgorithmicColorRampClass的起止颜色属性
            algColorRamp.ToColor   = fromColor;
            algColorRamp.FromColor = toColor;
            //设置梯度类型
            algColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
            //设置颜色带颜色数量
            algColorRamp.Size = count;
            //创建颜色带
            bool bture = true;

            algColorRamp.CreateRamp(out bture);
            return(algColorRamp);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据单波段拉伸渲染
        /// </summary>
        /// <param name="rasterDataset">栅格数据集</param>
        /// <param name="graypos">第几波段</param>
        /// <param name="stretchType">拉伸方式</param>
        /// <param name="pFromColor">fromColor</param>
        /// <param name="pToColor">toColor</param>
        /// <returns></returns>
        public static IRasterRenderer StretchRenderer(ESRI.ArcGIS.Geodatabase.IRasterDataset rasterDataset, int graypos,
                                                      esriRasterStretchTypesEnum stretchType, IRgbColor pFromColor, IRgbColor pToColor)
        {
            try
            {
                //Create the color ramp.
                IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass();
                colorRamp.Size      = 255;
                colorRamp.FromColor = pFromColor;
                colorRamp.ToColor   = pToColor;
                bool createColorRamp;
                colorRamp.CreateRamp(out createColorRamp);
                //Create a stretch renderer.
                IRasterStretchColorRampRenderer stretchRenderer = new
                                                                  RasterStretchColorRampRendererClass();

                IRasterRenderer rasterRenderer = (IRasterRenderer)stretchRenderer;
                //Set the renderer properties.
                IRaster raster = rasterDataset.CreateDefaultRaster();
                rasterRenderer.Raster = raster;
                rasterRenderer.Update();
                stretchRenderer.BandIndex = graypos;
                stretchRenderer.ColorRamp = colorRamp;
                //Set the stretch type.
                IRasterStretch pRasterStretch = (IRasterStretch)rasterRenderer;
                pRasterStretch.StretchType             = stretchType;
                pRasterStretch.StandardDeviationsParam = 2;
                return(rasterRenderer);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        //渲染建设用地适宜级栅格图
        public void Render()
        {
            if (this.RasterLayerClass != null)
            {
                RgbColorClass pFromColor = new RgbColorClass();
                pFromColor.Red   = 255; //红色
                pFromColor.Green = 0;
                pFromColor.Blue  = 0;

                RgbColorClass pToColor = new RgbColorClass();
                pToColor.Red   = 0;
                pToColor.Green = 255; //绿色
                pToColor.Blue  = 0;

                bool ok = false;

                AlgorithmicColorRampClass acrc = new AlgorithmicColorRampClass();
                acrc.Size      = 255;
                acrc.FromColor = pFromColor as IColor;
                acrc.ToColor   = pToColor as IColor;
                acrc.CreateRamp(out ok);

                RasterStretchColorRampRendererClass scr = new RasterStretchColorRampRendererClass();
                scr.Raster = this.RasterLayerClass.Raster;   //显示图例
                scr.Update();                                //显示图例
                scr.BandIndex = 0;
                scr.ColorRamp = acrc as IColorRamp;
                scr.Update();                                //显示图例

                this.RasterLayerClass.Renderer = scr;
            }
        }
Exemplo n.º 6
0
        //创建颜色带
        private IColorRamp CreateAlgorithmicColorRamp(int count)
        {
            IAlgorithmicColorRamp algColorRamp = new AlgorithmicColorRampClass();
            IRgbColor             fromColor    = new RgbColorClass();
            IRgbColor             toColor      = new RgbColorClass();

            fromColor.Red   = 255;
            fromColor.Green = 255;
            fromColor.Blue  = 255;

            toColor.Red   = 255;
            toColor.Green = 0;
            toColor.Blue  = 0;

            algColorRamp.ToColor = toColor;

            algColorRamp.FromColor = fromColor;


            algColorRamp.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;

            algColorRamp.Size = count;

            bool bture = true;

            algColorRamp.CreateRamp(out bture);
            return(algColorRamp);
        }
Exemplo n.º 7
0
        //GradientFillSymbol
        private void button15_Click(object sender, EventArgs e)
        {
            IGradientFillSymbol   gradientFillSymbol = new GradientFillSymbolClass();
            IAlgorithmicColorRamp algorithcColorRamp = new AlgorithmicColorRampClass();

            algorithcColorRamp.FromColor          = getRGB(255, 0, 0);
            algorithcColorRamp.ToColor            = getRGB(0, 255, 0);
            algorithcColorRamp.Algorithm          = esriColorRampAlgorithm.esriHSVAlgorithm;
            gradientFillSymbol.ColorRamp          = algorithcColorRamp;
            gradientFillSymbol.GradientAngle      = 45;
            gradientFillSymbol.GradientPercentage = 0.9;
            gradientFillSymbol.Style = esriGradientFillStyle.esriGFSLinear;


            object           Missing         = Type.Missing;
            IPolygon         polygon         = new PolygonClass();
            IPointCollection pointCollection = polygon as IPointCollection;
            IPoint           point           = new PointClass();

            point.PutCoords(5, 5);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(5, 10);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(10, 10);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(10, 5);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            polygon.SimplifyPreserveFromTo();
            IActiveView activeView = this.axMapControl1.ActiveView;

            activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            activeView.ScreenDisplay.SetSymbol(gradientFillSymbol as ISymbol);
            activeView.ScreenDisplay.DrawPolygon(polygon as IGeometry);
            activeView.ScreenDisplay.FinishDrawing();
        }
Exemplo n.º 8
0
        public static IRasterRenderer ClassifyRenderer(IRasterLayer raslyr,IRgbColor start_clr,IRgbColor end_clr,int count)
        {
            IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRendererClass();
            IRasterRenderer rasterRenderer = pRClassRend as IRasterRenderer;

            IRaster pRaster = raslyr.Raster;
            IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection;
            IRasterBand pRBand = pRBandCol.Item(0);
            if (pRBand.Histogram == null)
            {
                pRBand.ComputeStatsAndHist();
            }
            rasterRenderer.Raster = pRaster;
            pRClassRend.ClassCount = count;
            rasterRenderer.Update();

            IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass();
            colorRamp.Size = count;
            colorRamp.FromColor = start_clr;
            colorRamp.ToColor = end_clr;
            bool createColorRamp;
            colorRamp.CreateRamp(out createColorRamp);

            IFillSymbol fillSymbol = new SimpleFillSymbolClass();
            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"));
            }
            return rasterRenderer;
        }
Exemplo n.º 9
0
        private void button4_Click(object sender, EventArgs e)
        {
            int    selectedFieldIndex            = m_pTarFeatureLayer.FeatureClass.Fields.FindField(comboBox1.SelectedItem.ToString());
            IField selectedField                 = m_pTarFeatureLayer.FeatureClass.Fields.get_Field(selectedFieldIndex);
            IUniqueValueRenderer unqValueRenderr = new UniqueValueRendererClass();

            #region UniqueValueRenderer需要定义字段数,字段名,并最后添加字段中每一种值对应的渲染方式(AddValue)
            unqValueRenderr.FieldCount = 1;
            unqValueRenderr.set_Field(0, selectedField.Name);//0是干什么的?
            #endregion
            IAlgorithmicColorRamp acr = new AlgorithmicColorRampClass();
            acr.FromColor = m_pFillColor;
            acr.ToColor   = m_pOutlineColor;
            acr.Size      = m_pTarFeatureLayer.FeatureClass.FeatureCount(null);
            bool isOK;
            acr.CreateRamp(out isOK);
            #region 很迷,不知道为什么直接acr.colors.next遍历不了colorramp
            IEnumColors enumColor = acr.Colors;
            IColor      curColor  = enumColor.Next();
            #endregion
            #region 开始遍历图层获取所有feature
            for (int i = 0; i < m_pTarFeatureLayer.FeatureClass.FeatureCount(null); i++)
            {
                IFeature curFeature = m_pTarFeatureLayer.FeatureClass.GetFeature(i);
                switch (m_pTarFeatureLayer.FeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPolygon:
                {
                    ISimpleFillSymbol sfs = new SimpleFillSymbolClass();
                    sfs.Color = curColor;
                    unqValueRenderr.AddValue(curFeature.get_Value(selectedFieldIndex).ToString(), "", sfs as ISymbol);
                    break;
                }

                case esriGeometryType.esriGeometryPoint:
                {
                    ISimpleMarkerSymbol sms = new SimpleMarkerSymbolClass
                    {
                        Color = curColor
                    };
                    unqValueRenderr.AddValue(curFeature.get_Value(selectedFieldIndex).ToString(), "", sms as ISymbol);
                    break;
                }

                case esriGeometryType.esriGeometryPolyline:
                {
                    ISimpleLineSymbol sls = new SimpleLineSymbolClass();
                    sls.Color = curColor;
                    unqValueRenderr.AddValue(curFeature.get_Value(selectedFieldIndex).ToString(), "", sls as ISymbol);
                    break;
                }
                }
                curColor = enumColor.Next();
            }
            m_pTarGeoFeatureLayer.Renderer = unqValueRenderr as IFeatureRenderer;
            frmMainOper(OperationType.RefreshMapCtrl);
            frmMainOper(OperationType.UpdateTOCCtrl);
            #endregion
        }
Exemplo n.º 10
0
        //MultilayerFillSymbol
        private void button17_Click(object sender, EventArgs e)
        {
            IMultiLayerFillSymbol multiLayerFillSymbol = new MultiLayerFillSymbolClass();

            IGradientFillSymbol   gradientFillSymbol = new GradientFillSymbolClass();
            IAlgorithmicColorRamp algorithcColorRamp = new AlgorithmicColorRampClass();

            algorithcColorRamp.FromColor          = getRGB(255, 0, 0);
            algorithcColorRamp.ToColor            = getRGB(0, 255, 0);
            algorithcColorRamp.Algorithm          = esriColorRampAlgorithm.esriHSVAlgorithm;
            gradientFillSymbol.ColorRamp          = algorithcColorRamp;
            gradientFillSymbol.GradientAngle      = 45;
            gradientFillSymbol.GradientPercentage = 0.9;
            gradientFillSymbol.Style = esriGradientFillStyle.esriGFSLinear;

            ICartographicLineSymbol cartoLine = new CartographicLineSymbol();

            cartoLine.Cap   = esriLineCapStyle.esriLCSButt;
            cartoLine.Join  = esriLineJoinStyle.esriLJSMitre;
            cartoLine.Color = getRGB(255, 0, 0);
            cartoLine.Width = 2;
            //Create the LineFillSymbo
            ILineFillSymbol lineFill = new LineFillSymbol();

            lineFill.Angle      = 45;
            lineFill.Separation = 10;
            lineFill.Offset     = 5;
            lineFill.LineSymbol = cartoLine;


            multiLayerFillSymbol.AddLayer(gradientFillSymbol);
            multiLayerFillSymbol.AddLayer(lineFill);

            object           Missing         = Type.Missing;
            IPolygon         polygon         = new PolygonClass();
            IPointCollection pointCollection = polygon as IPointCollection;
            IPoint           point           = new PointClass();

            point.PutCoords(5, 5);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(5, 10);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(10, 10);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            point.PutCoords(10, 5);
            pointCollection.AddPoint(point, ref Missing, ref Missing);
            polygon.SimplifyPreserveFromTo();
            IActiveView activeView = this.axMapControl1.ActiveView;

            activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            activeView.ScreenDisplay.SetSymbol(multiLayerFillSymbol as ISymbol);
            activeView.ScreenDisplay.DrawPolygon(polygon as IGeometry);
            activeView.ScreenDisplay.FinishDrawing();
        }
Exemplo n.º 11
0
        //AlgorithmicColorRamp是通过起止颜色来确定多个在这两个颜色之间的色带
        private IEnumColors createAlgorithmicColorRamp(IColor fromColor, IColor toColor, int count)
        {
            IAlgorithmicColorRamp pRampColor;

            pRampColor           = new AlgorithmicColorRampClass();
            pRampColor.FromColor = fromColor;
            pRampColor.ToColor   = toColor;
            pRampColor.Size      = count;
            bool ok;

            pRampColor.CreateRamp(out ok);
            return(pRampColor.Colors);
        }
Exemplo n.º 12
0
        private IColorRamp getRamp()
        {
            IAlgorithmicColorRamp ramp = new AlgorithmicColorRampClass();

            ramp.FromColor = ColorToIColor(colorPickEdit1.Color);
            ramp.ToColor   = ColorToIColor(colorPickEdit2.Color);
            ramp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
            ramp.Size      = Convert.ToInt16(spinEdit1.Text);
            bool b = true;

            ramp.CreateRamp(out b);
            return(ramp);
        }
Exemplo n.º 13
0
        public static IAlgorithmicColorRamp CreateAlgorithmicColorRamp(IColor pStartColor, IColor pEndColor, esriColorRampAlgorithm eColorAlgorithm = esriColorRampAlgorithm.esriHSVAlgorithm, int iSize = 500)
        {
            IAlgorithmicColorRamp pAlgorithmicColorRamp = new AlgorithmicColorRampClass();

            pAlgorithmicColorRamp.FromColor = pStartColor;
            pAlgorithmicColorRamp.ToColor   = pEndColor;
            pAlgorithmicColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
            pAlgorithmicColorRamp.Size      = iSize;
            bool bOK = true;

            pAlgorithmicColorRamp.CreateRamp(out bOK);
            return(pAlgorithmicColorRamp);
        }
Exemplo n.º 14
0
        private int[,] RedToBlueColorRamps()
        {
            IEnumColors pEnumColors = null;

            int[,] arrSepLineColor = new int[10, 3];
            IAlgorithmicColorRamp pColorRamp1 = new AlgorithmicColorRampClass();
            IAlgorithmicColorRamp pColorRamp2 = new AlgorithmicColorRampClass();

            pColorRamp1.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
            pColorRamp2.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;

            IRgbColor pColor1 = new RgbColor();
            IRgbColor pColor2 = new RgbColor();
            IRgbColor pColor3 = new RgbColor();



            pColor1 = pSnippet.getRGB(165, 0, 38);
            pColor2 = pSnippet.getRGB(255, 255, 191);
            pColor3 = pSnippet.getRGB(49, 54, 149);

            pColorRamp1.FromColor = pColor1;
            pColorRamp1.ToColor   = pColor2;
            pColorRamp2.FromColor = pColor2;
            pColorRamp2.ToColor   = pColor3;

            Boolean blnOK = true;

            IMultiPartColorRamp pMultiColorRamp = new MultiPartColorRampClass();

            pMultiColorRamp.Ramp[0] = pColorRamp1;
            pMultiColorRamp.Ramp[1] = pColorRamp2;
            pMultiColorRamp.Size    = 10;
            pMultiColorRamp.CreateRamp(out blnOK);


            pEnumColors = pMultiColorRamp.Colors;
            pEnumColors.Reset();
            for (int k = 0; k < 10; k++)
            {
                IColor    pColor    = pEnumColors.Next();
                IRgbColor pRGBColor = new RgbColorClass();
                pRGBColor.RGB = pColor.RGB;

                arrSepLineColor[k, 0] = pRGBColor.Red;
                arrSepLineColor[k, 1] = pRGBColor.Green;
                arrSepLineColor[k, 2] = pRGBColor.Blue;
            }

            return(arrSepLineColor);
        }
Exemplo n.º 15
0
        public static IEnumColors CreateColors(IRgbColor fromColor, IRgbColor toColor, int size)
        {
            IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass()
            {
                FromColor = fromColor,
                ToColor   = toColor,
                Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm,
                Size      = size
            };
            bool bOk = true;

            pColorRamp.CreateRamp(out bOk);
            return(pColorRamp.Colors);
        }
Exemplo n.º 16
0
 private IEnumColors method_1(IColorRamp icolorRamp_1, int int_0)
 {
     if (icolorRamp_1 == null)
     {
         IAlgorithmicColorRamp ramp = new AlgorithmicColorRampClass
         {
             FromColor = ColorManage.CreatColor(160, 0, 0),
             ToColor   = ColorManage.CreatColor(255, 200, 200),
             Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm
         };
         icolorRamp_1 = ramp;
     }
     return(ColorManage.CreateColors(icolorRamp_1, int_0));
 }
Exemplo n.º 17
0
        // 创建渐变色带
        public static IAlgorithmicColorRamp CreateColorRamp(IRgbColor fromColor, IRgbColor toColor, int size = 10)
        {
            IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass()
            {
                FromColor = fromColor, ToColor = toColor,               // 起止颜色
                Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm, // 梯度类型
                Size      = size                                        // 色带颜色数量
            };
            // 创建色带
            bool bture = true;

            pColorRamp.CreateRamp(out bture);
            return(pColorRamp);
        }
Exemplo n.º 18
0
        // 获取渐变颜色集
        public IColorRamp GetColorRamp(IRgbColor fromColor, IRgbColor toColor, int size)
        {
            IColorRamp pColorRamp = new AlgorithmicColorRampClass()
            {
                FromColor = fromColor,
                ToColor   = toColor,
                Size      = size,
                Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm
            };
            bool bOk = true;

            pColorRamp.CreateRamp(out bOk);
            return(pColorRamp);
        }
Exemplo n.º 19
0
        /// <summary>
        /// 根据容积率大小进行梯度颜色显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            //梯度颜色算法
            IAlgorithmicColorRamp pAlgoColorRamp = new AlgorithmicColorRampClass();

            pAlgoColorRamp.Size = MyArray.Length;

            IRgbColor pFromColor = new RgbColorClass(), pToColor = new RgbColorClass();

            pFromColor.Red   = 255;
            pFromColor.Green = 255;
            pFromColor.Blue  = 255;

            pToColor.Red   = 0;
            pToColor.Green = 255;
            pToColor.Blue  = 255;

            pAlgoColorRamp.FromColor = pFromColor;
            pAlgoColorRamp.ToColor   = pToColor;

            bool ok = true;

            pAlgoColorRamp.CreateRamp(out ok);


            IClassBreaksRenderer pRender = new ClassBreaksRendererClass();

            pRender.BreakCount = MyArray.Length;
            pRender.Field      = "Plot_Ratio";

            ISimpleFillSymbol pSym;

            System.Array.Sort(MyArray);

            for (int i = 0; i < MyArray.Length; i++)
            {
                pRender.set_Break(i, (double)MyArray.GetValue(i));
                pSym       = new SimpleFillSymbolClass();
                pSym.Color = pAlgoColorRamp.get_Color(i);
                pRender.set_Symbol(i, (ISymbol)pSym);
            }

            IGeoFeatureLayer pGeoLyr = (IGeoFeatureLayer)Form1.mainForm.axMapControl1.get_Layer(1);//确保先加入地块图层

            pGeoLyr.Renderer = (IFeatureRenderer)pRender;

            Form1.mainForm.axMapControl1.Refresh();
            Form1.mainForm.axTOCControl1.Update();
        }
Exemplo n.º 20
0
        /// <summary>
        /// 拉伸渲染模式(貌似)
        /// </summary>
        /// <param name="rasterDataset"></param>
        /// <returns></returns>
        private static IRasterRenderer StretchRenderer(ESRI.ArcGIS.Geodatabase.IRasterDataset rasterDataset, int graypos, int i)
        {
            try
            {
                //Define the from and to colors for the color ramp.
                IRgbColor fromColor = new RgbColorClass();
                fromColor.Red   = 255;
                fromColor.Green = 0;
                fromColor.Blue  = 0;
                IColor toColor = new RgbColorClass();
                //此处应该是写错了
                fromColor.Red   = 0;
                fromColor.Green = 255;
                fromColor.Blue  = 0;
                //Create the color ramp.
                IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass();
                colorRamp.Size      = 255;
                colorRamp.FromColor = fromColor;
                colorRamp.ToColor   = toColor;
                bool createColorRamp;
                colorRamp.CreateRamp(out createColorRamp);
                //Create a stretch renderer.
                IRasterStretchColorRampRenderer stretchRenderer = new
                                                                  RasterStretchColorRampRendererClass();

                //设置显示对比度和亮度
                //((IRasterDisplayProps)stretchRenderer).BrightnessValue = -90;
                IRasterRenderer rasterRenderer = (IRasterRenderer)stretchRenderer;


                //Set the renderer properties.
                IRaster raster = rasterDataset.CreateDefaultRaster();
                rasterRenderer.Raster = raster;
                rasterRenderer.Update();
                stretchRenderer.BandIndex = graypos;
                //stretchRenderer.ColorRamp = colorRamp;
                //Set the stretch type.
                IRasterStretch stretchType = (IRasterStretch)rasterRenderer;
                stretchType.StretchType             = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
                stretchType.StandardDeviationsParam = 2;
                return(rasterRenderer);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// 获取渐变色带
        /// </summary>
        /// <param name="size"></param>
        /// <returns></returns>
        public static IAlgorithmicColorRamp GetDefaultGradualColor(int size)
        {
            IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass();

            pColorRamp.FromColor = AeColor.GetRgbColor(0, 255, 0);
            pColorRamp.ToColor   = AeColor.GetRgbColor(0, 0, 255);
            if (size <= 1)
            {
                size = 2;
            }

            pColorRamp.Size = size; //渐变颜色带范围
            bool ok;

            pColorRamp.CreateRamp(out ok);
            return(pColorRamp);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 根据单波段灰度渲染
        /// </summary>
        /// <param name="rasterDataset">栅格数据集</param>
        /// <param name="graypos">第几波段</param>
        /// <returns></returns>
        public static IRasterRenderer StretchRenderer(ESRI.ArcGIS.Geodatabase.IRasterDataset rasterDataset, int graypos)
        {
            try
            {
                //Define the from and to colors for the color ramp.
                IRgbColor fromColor = new RgbColorClass();
                fromColor.Red = 255;
                fromColor.Green = 0;
                fromColor.Blue = 0;
                IColor toColor = new RgbColorClass();
                fromColor.Red = 0;
                fromColor.Green = 255;
                fromColor.Blue = 0;
                //Create the color ramp.
                IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass();
                colorRamp.Size = 255;
                colorRamp.FromColor = fromColor;
                colorRamp.ToColor = toColor;
                bool createColorRamp;
                colorRamp.CreateRamp(out createColorRamp);
                //Create a stretch renderer.
                IRasterStretchColorRampRenderer stretchRenderer = new
                RasterStretchColorRampRendererClass();

                //设置显示对比度和亮度
                //((IRasterDisplayProps)stretchRenderer).BrightnessValue = -90;
                IRasterRenderer rasterRenderer = (IRasterRenderer)stretchRenderer;

                //Set the renderer properties.
                IRaster raster = rasterDataset.CreateDefaultRaster();
                rasterRenderer.Raster = raster;
                rasterRenderer.Update();
                stretchRenderer.BandIndex = graypos;
                //stretchRenderer.ColorRamp = colorRamp;
                //Set the stretch type.
                IRasterStretch stretchType = (IRasterStretch)rasterRenderer;
                stretchType.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
                stretchType.StandardDeviationsParam = 2;
                return rasterRenderer;
            }
            catch
            {
                return null;
            }
        }
Exemplo n.º 23
0
        public static IRasterRenderer ClassifyRenderer(ESRI.ArcGIS.Geodatabase.IRasterDataset pRasterDataset)
        {
            try
            {
                //create the classify render:创建渲染器
                IRasterClassifyColorRampRenderer pClassifyRenderer = new RasterClassifyColorRampRendererClass();
                IRasterRenderer pRasterRenderer = (IRasterRenderer)pClassifyRenderer;
                IRaster         pRaster         = pRasterDataset.CreateDefaultRaster();
                pRasterRenderer.Raster       = pRaster;
                pClassifyRenderer.ClassCount = 10;
                pRasterRenderer.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  = 255;

                //set the color ramp for the symbology:生成色带
                IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass();
                pRamp.Size      = 10;
                pRamp.FromColor = pFromColor;
                pRamp.ToColor   = pToColor;
                bool pBoolColorRamp;
                pRamp.CreateRamp(out pBoolColorRamp);
                //create the symbol for the classes.:创建符号
                IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
                for (int i = 0; i < pClassifyRenderer.ClassCount; i++)
                {
                    pFillSymbol.Color = pRamp.get_Color(i);
                    pClassifyRenderer.set_Symbol(i, (ISymbol)pFillSymbol);
                    pClassifyRenderer.set_Label(i, Convert.ToString(i));
                }
                return(pRasterRenderer);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Exemplo n.º 24
0
 protected override void OnClick()
 {
     try
     {
         IAlgorithmicColorRamp colorRampe = new AlgorithmicColorRampClass();
         colorRampe.FromColor = (new RgbColorClass() { Red = 255, Green = 0, Blue = 255 }) as IColor;
         colorRampe.ToColor = (new RgbColorClass() { Red = 255, Green = 0, Blue = 0 }) as IColor;
         colorRampe.Size = 256;
         colorRampe.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
         bool ok = false;
         colorRampe.CreateRamp(out ok);
         MessageBox.Show(colorRampe.Color[255].RGB.ToString());
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Unfortunately, the application meets an error.\n\nSource: {0}\nSite: {1}\nMessage: {2}", ex.Source, ex.TargetSite, ex.Message), "Error");
     }
 }
Exemplo n.º 25
0
        /// <summary>
        /// 根据起点颜色、终点颜色和级别数目,产生色带
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="gradecount"></param>
        /// <returns></returns>
        private static IEnumColors ProduceEnumColors(Color start, Color end, int gradecount)
        {
            //创建一个新AlgorithmicColorRampClass对象
            IAlgorithmicColorRamp algColorRamp = new AlgorithmicColorRampClass();

            algColorRamp.ToColor   = ConvertColorToIColor(end);//从.net的颜色转换
            algColorRamp.FromColor = ConvertColorToIColor(start);
            //设置梯度类型
            algColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
            //设置颜色带颜色数量
            algColorRamp.Size = gradecount;
            //创建颜色带
            bool bture = true;

            algColorRamp.CreateRamp(out bture);
            //使用IEnumColors获取颜色带
            return(algColorRamp.Colors);
        }
Exemplo n.º 26
0
        public static void funColorForRaster_Classify(IRasterLayer pRasterLayer, int ClassNum)
        {
            IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRendererClass();
            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 = ClassNum;
            pRRend.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 colorRamp = new AlgorithmicColorRampClass();

            colorRamp.Size      = ClassNum;
            colorRamp.FromColor = pFromColor;
            colorRamp.ToColor   = pToColor;
            bool createColorRamp;

            colorRamp.CreateRamp(out createColorRamp);
            IFillSymbol fillSymbol = new SimpleFillSymbolClass();

            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, (i + 1).ToString());
            }
            pRasterLayer.Renderer = pRRend;
            MainFrom.m_mapControl.AddLayer(pRasterLayer);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Creates a renderer for output rasters.
        /// </summary>
        /// <param name="pRL"></param>
        /// <param name="pColor1"></param>
        /// <param name="pColor2"></param>
        private void CreateRasterStretchRenderer(IRasterLayer pRL, IRgbColor pColor1, IRgbColor pColor2)
        {
            try
            {
                IRaster pRaster = pRL.Raster;
                IRasterStretchColorRampRenderer pStretchRen = new RasterStretchColorRampRendererClass();
                IRasterRenderer       pRasRen;
                IAlgorithmicColorRamp pRamp    = new AlgorithmicColorRampClass();
                IStyleGallery         pGallery = new StyleGalleryClass();

                bool bCreate;

                //create renderer
                pRasRen        = (IRasterRenderer)pStretchRen;
                pRasRen.Raster = pRaster;
                pRasRen.Update();

                //create color ramp
                pRamp.Size      = 255;
                pRamp.FromColor = pColor1;
                pRamp.ToColor   = pColor2;
                pRamp.CreateRamp(out bCreate);

                //apply the color ramp
                pStretchRen.BandIndex = 0;
                pStretchRen.ColorRamp = pRamp;
                IRasterStretch pRasStretch = (IRasterStretch)pStretchRen;
                pRasStretch.Background = true;
                double dValue = 0;
                pRasStretch.set_BackgroundValues(ref dValue);

                pRasRen.Update();
                pRL.Renderer = (IRasterRenderer)pStretchRen;
                ArcMap.Document.ActiveView.Refresh();
                ArcMap.Document.UpdateContents();
            }

            catch (Exception ex)
            {
                clsStatic.ShowErrorMessage(ex.ToString());
            }
        }
Exemplo n.º 28
0
        public static IRasterRenderer StretchRender(IRasterDataset pRasterDataset)
        {
            try
            {
                //Define the from and to colors for the color ramp
                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 AlgorithmicColorRampClass();
                pRamp.Size      = 10;
                pRamp.FromColor = pFromColor;
                pRamp.ToColor   = pToColor;
                bool createColorRamp;
                pRamp.CreateRamp(out createColorRamp);
                //create a stretch renderer
                IRasterStretchColorRampRenderer pStrechRenderer = new RasterStretchColorRampRendererClass();
                IRasterRenderer pRasterRenderer = (IRasterRenderer)pStrechRenderer;
                //set the renderer properties
                IRaster pRaster = pRasterDataset.CreateDefaultRaster();
                pRasterRenderer.Raster = pRaster;
                pRasterRenderer.Update();
                //
                pStrechRenderer.BandIndex = 0;
                pStrechRenderer.ColorRamp = pRamp;
                IRasterStretch pStretchType = (IRasterStretch)pRasterRenderer;
                pStretchType.StretchType             = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
                pStretchType.StandardDeviationsParam = 2;
                return(pRasterRenderer);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// 打开adf文件格式栅格数据
        /// </summary>
        /// <param name="rasterPath"></param>
        /// <param name="fileName"></param>
        public static void OpenRasterLayer(string rasterPath, string fileName)
        {
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
            IWorkspace        SWorkspace       = workspaceFactory.OpenFromFile(rasterPath, 0);
            IRasterWorkspace  rasterWorkspace  = SWorkspace as IRasterWorkspace;
            IRasterDataset    pRasterDataset   = (IRasterDataset)rasterWorkspace.OpenRasterDataset(fileName);
            IRasterLayer      pRasterLayer     = new RasterLayerClass();

            pRasterLayer.CreateFromDataset(pRasterDataset);
            IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass()
            {
                FromColor = new RgbColorClass()
                {
                    Red = 197, Green = 68, Blue = 56
                },
                ToColor = new RgbColorClass()
                {
                    Red = 80, Green = 110, Blue = 207
                },
                Size = 100
            };//Red = 80, Green = 110, Blue = 207
            IMultiPartColorRamp multiPartColorRamp = new MultiPartColorRampClass();

            multiPartColorRamp.set_Ramp(0, colorRamp);
            bool outCreate = false;

            colorRamp.CreateRamp(out outCreate);
            //设置渲染参数
            IRasterStretchColorRampRenderer rasterStretchColorRampRenderer = new RasterStretchColorRampRendererClass();
            IRasterRenderer rasterRenderer = rasterStretchColorRampRenderer as IRasterRenderer;

            rasterRenderer.Raster = pRasterLayer.Raster;
            rasterRenderer.Update();
            rasterStretchColorRampRenderer.BandIndex = 0;
            rasterStretchColorRampRenderer.ColorRamp = multiPartColorRamp as IColorRamp;
            rasterRenderer.Update();
            pRasterLayer.Renderer = rasterRenderer;
            MainFrom.m_mapControl.AddLayer(pRasterLayer);
        }
        /// <summary>
        /// 依据色带渲染栅格
        /// </summary>
        /// <param name="pRasterLayer"></param>
        public void SetStretchColorRampRender(IRasterLayer pRasterLayer)
        {
            try
            {
                IRasterStretchColorRampRenderer pRampRenderer = new RasterStretchColorRampRendererClass();
                IRasterRenderer pRasterRenderer = pRampRenderer as IRasterRenderer;
                pRasterRenderer.Raster = pRasterLayer.Raster;
                pRasterRenderer.Update();
                //创建起始颜色
                IColor fromColor = GetColor(40, 146, 179);
                IColor toColor   = GetColor(255, 255, 100);
                //创建起止色带
                IAlgorithmicColorRamp pAlgorithmicColorRamp = new AlgorithmicColorRampClass();
                pAlgorithmicColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                pAlgorithmicColorRamp.Size      = 255;
                pAlgorithmicColorRamp.FromColor = fromColor;
                pAlgorithmicColorRamp.ToColor   = toColor;
                bool btrue = true;
                pAlgorithmicColorRamp.CreateRamp(out btrue);
                //选择拉伸颜色符号的波段
                pRampRenderer.BandIndex = 0;
                pRampRenderer.ColorRamp = pAlgorithmicColorRamp as IColorRamp;
                pRasterRenderer.Update();
                pRasterLayer.Renderer = pRasterRenderer;

                this._pMap.AddLayer(pRasterLayer);
                IActiveView pActiveView = _pMap as IActiveView;
                if (pActiveView != null)
                {
                    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                    pActiveView.Extent = pActiveView.FullExtent;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 31
0
        /// <summary>
        ///  创建色带
        /// </summary>
        /// <returns>IColorRamp 色带</returns>
        public static IColorRamp CreateAlgorithmicColorRamp()
        {
            // 创建一个新的AlgorithmicColorRampClass对象
            IAlgorithmicColorRamp algorithmicColorRamp = new AlgorithmicColorRampClass();
            // 创建起始终止颜色
            IRgbColor fromColor = GetRgbColor(255, 0, 0);
            IRgbColor toColor   = GetRgbColor(0, 255, 0);

            algorithmicColorRamp.FromColor = fromColor;
            algorithmicColorRamp.ToColor   = toColor;

            // 设置梯度类型
            algorithmicColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
            // 设置颜色色带数量
            algorithmicColorRamp.Size = 10;

            // 创建颜色带
            bool bTrue = true;

            algorithmicColorRamp.CreateRamp(out bTrue);

            return(algorithmicColorRamp);
        }
Exemplo n.º 32
0
 protected override void OnClick()
 {
     try
     {
         IAlgorithmicColorRamp colorRampe = new AlgorithmicColorRampClass();
         colorRampe.FromColor = (new RgbColorClass()
         {
             Red = 255, Green = 0, Blue = 255
         }) as IColor;
         colorRampe.ToColor   = (new RgbColorClass()
         {
             Red = 255, Green = 0, Blue = 0
         }) as IColor;
         colorRampe.Size      = 256;
         colorRampe.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
         bool ok = false;
         colorRampe.CreateRamp(out ok);
         MessageBox.Show(colorRampe.Color[255].RGB.ToString());
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Unfortunately, the application meets an error.\n\nSource: {0}\nSite: {1}\nMessage: {2}", ex.Source, ex.TargetSite, ex.Message), "Error");
     }
 }
Exemplo n.º 33
0
        //Ϊդ��ͼ�����ݽ���������ɫ
        public static IRasterLayer SetStretchRenderer(IRaster pRaster)
        {
            try
            {
                //������ɫ���QIդ����ɫ
                IRasterStretchColorRampRenderer pStretchRen = new RasterStretchColorRampRendererClass();
                IRasterRenderer pRasRen = pStretchRen as IRasterRenderer;
                //Ϊ��ɫ�͸�������դ������
                pRasRen.Raster = pRaster;
                pRasRen.Update();
                //���������յ���ɫ
                IColor pFromColor = new RgbColorClass();
                IRgbColor pRgbColor = pFromColor as IRgbColor;
                pRgbColor.Red = 255;
                pRgbColor.Green = 0;
                pRgbColor.Blue = 0;
                IColor pToColor = new RgbColorClass();
                pRgbColor = pToColor as IRgbColor;
                pRgbColor.Red = 0;
                pRgbColor.Green = 255;
                pRgbColor.Blue = 0;
                //������ɫ�ּ�
                IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass();
                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 RasterLayerClass();
                pRLayer.CreateFromRaster(pRaster);
                pRLayer.Renderer = pStretchRen as IRasterRenderer;
                return pRLayer;

            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                return null;
            }
        }
Exemplo n.º 34
0
        //Ϊդ��ͼ�����ݰ��մ���Сֵ�����ֵ�ķ�����ɫ
        public static IRasterLayer SetRsLayerClassifiedColor(IRaster pRaster)
        {
            IRasterClassifyColorRampRenderer pClassRen = new RasterClassifyColorRampRendererClass();
            IRasterRenderer pRasRen = pClassRen as RasterClassifyColorRampRendererClass;
            //Set raster for the render and update
            pRasRen.Raster = pRaster;
            pClassRen.ClassCount = 9;
            pRasRen.Update();
            //Create a color ramp to use
            //���������յ���ɫ
            IColor pFromColor = new RgbColorClass();
            IRgbColor pRgbColor = pFromColor as IRgbColor;
            pRgbColor.Red = 255;
            pRgbColor.Green = 200;
            pRgbColor.Blue = 0;
            IColor pToColor = new RgbColorClass();
            pRgbColor = pToColor as IRgbColor;
            pRgbColor.Red = 0;
            pRgbColor.Green = 0;
            pRgbColor.Blue = 255;
            //������ɫ�ּ�
            IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass();
            pRamp.Size = 9;
            pRamp.FromColor = pFromColor;
            pRamp.ToColor = pToColor;
            bool ok = true;
            pRamp.CreateRamp(out ok);
            //���դ��ͳ����ֵ
            IRasterBandCollection pRsBandCol = pRaster as IRasterBandCollection;
            IRasterBand pRsBand = pRsBandCol.Item(0);
            pRsBand.ComputeStatsAndHist();
            IRasterStatistics pRasterStatistic = pRsBand.Statistics;
            double dMaxValue = pRasterStatistic.Maximum;
            double dMinValue = pRasterStatistic.Minimum;
            //Create symbol for the classes
            IFillSymbol pFSymbol = new SimpleFillSymbolClass();

            double LabelValue = Convert.ToDouble((dMaxValue - dMinValue) / 9);
            for (int i = 0; i <= pClassRen.ClassCount - 1; i++)
            {
                pFSymbol.Color = pRamp.get_Color(i);
                pClassRen.set_Symbol(i, pFSymbol as ISymbol);
                double h1 = (LabelValue * i) + dMinValue;
                double h2 = (LabelValue * (i + 1)) + dMinValue;
                pClassRen.set_Label(i, h1.ToString() + "��" + h2.ToString());
            }
            //Update the renderer and plug into layer
            pRasRen.Update();
            IRasterLayer pRLayer = new RasterLayerClass();
            pRLayer.CreateFromRaster(pRaster);
            pRLayer.Renderer = pClassRen as IRasterRenderer;
            return pRLayer;
        }
Exemplo n.º 35
0
        private void btnClassBreakRender_Click(object sender, EventArgs e)
        {
            //先用一个ITableHistogram对象从一个要素类获取某一字段的所有值及频率,即dataValues和dataFrequency,这两个数组是分组的基本数据
            //取得两个数组后,系统用IClassGEN对象对它们进行分级,得到classes及classCount,前者是分级临界点值的数组,后者为分级数目
            //根据得到的分级数目和颜色带对象,可以分别设置ClassBreakRender对象的不同符号,产生不同的效果
            IGeoFeatureLayer pGeoFeatLyr;
            ITable pTable;

            object dataValues;
            object dataFrequency;
            string strOutput;

            pGeoFeatLyr = this.mainMapControl.get_Layer(0) as IGeoFeatureLayer;
            pTable = pGeoFeatLyr as ITable;
            //以下代码用TableHistogram和BasicHistogram统计出Table某一字段的值和值的频率
            ITableHistogram pTableHistogram;
            pTableHistogram = new BasicTableHistogramClass();
            pTableHistogram.Table = pTable;//需传入一个ITable
            pTableHistogram.Field = "GDP_1999(";//统计的字段
            IBasicHistogram pBasicHistogram;
            pBasicHistogram = pTableHistogram as IBasicHistogram;
            pBasicHistogram.GetHistogram(out dataValues, out dataFrequency);//关键

            //以下代码用IClassifyGEN和EqualInterval对象,基于分段数目,生成各段的临界值,并放在一个数组当中
            IClassifyGEN pClassifyGen = new EqualIntervalClass();
            double[] classes;
            int classCount = 5;
            pClassifyGen.Classify(dataValues, dataFrequency, ref classCount);//用到了上面ITableHistogram生成的值和值频率数组,关键!!!!!!
            classes = pClassifyGen.ClassBreaks as double[];//注意,此对象下标从1开始(我觉得0为最开头,所以临界值从1开始有意义),关键!!!!!!
            //classCount = classes.Length; 此处应该为6
            //for (int i = 0; i < classes.Length; i++)
            //{
            //    MessageBox.Show(classes[i].ToString());
            //}
            //MessageBox.Show(classCount.ToString());

            IClassBreaksRenderer pClassBreakRenderer = new ClassBreaksRendererClass();//设置分段着色属性
            pClassBreakRenderer.Field = "GDP_1999(";
            pClassBreakRenderer.BreakCount = 5;//分成5段
            pClassBreakRenderer.SortClassesAscending = true;

            //以下代码生成颜色带
            IHsvColor pFromColor = getHsvColor(60, 100, 96);
            IHsvColor pToColor = getHsvColor(0, 100, 96);
            IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass();
            pColorRamp.FromColor = pFromColor as IColor;
            pColorRamp.ToColor = pToColor as IColor;
            pColorRamp.Size = classCount;//生成颜色的数目
            //MessageBox.Show(classCount.ToString());
            bool ok;
            pColorRamp.CreateRamp(out ok);//创建颜色带,关键!!!

            if (ok)//如果颜色带成功生成的话
            {
                IEnumColors pEnumColors = pColorRamp.Colors;//存放生成颜色带的各颜色
                pEnumColors.Reset();//是必须吗?????关键!!!

                IColor pColor;
                ISimpleFillSymbol pSimpleFillSymbol;
                //ISimpleMarkerSymbol pSimpleMarkerSymbol;

                for (int i = 0; i < classCount; i++)//为每个值范围设置符号(此处为SimpleFillSymbol)
                {
                    pColor = pEnumColors.Next();
                    pSimpleFillSymbol = new SimpleFillSymbolClass();
                    pSimpleFillSymbol.Color = pColor;
                    pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                    //pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();
                    //pSimpleMarkerSymbol.Color = pColor;
                    pClassBreakRenderer.set_Symbol(i, (ISymbol)pSimpleFillSymbol);//设置Symbol,关键!!!
                    pClassBreakRenderer.set_Break(i, classes[i + 1]);//设置临界值,注意下标,关键!!!
                }

                pGeoFeatLyr.Renderer = pClassBreakRenderer as IFeatureRenderer;
                this.mainMapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
                //this.axTOCControl.SetBuddyControl(this.mainMapControl.Object);
                this.axTOCControl.Update();
            }
        }
Exemplo n.º 36
0
        private void InitialListViewSymbol(IList<double> lstBreakValues)
        {
            m_claasifiedInfo.lstColor.Clear();
            int classcount = Convert.ToInt32(cmbClasses.SelectedItem.ToString());
            Color fc = btnFromColor.IsNoColor == true ? Color.White : btnFromColor.SelectedSystemColor;
            IColor fromColor = Convert2ESRIColor(fc);
            Color tc = btnToColor.IsNoColor == true ? Color.Black : btnToColor.SelectedSystemColor;
            IColor toColor = Convert2ESRIColor(tc);

            m_claasifiedInfo.lstBreakValues.Clear();
            lvwSymbolEx.Items.Clear();
            lvwSymbolEx.BeginUpdate();

            IAlgorithmicColorRamp nx = new AlgorithmicColorRampClass();
            nx.ToColor = toColor;
            nx.FromColor = fromColor;
            nx.Size = classcount;
            nx.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;
            bool isCreated = true;
            nx.CreateRamp(out isCreated);

            IEnumColors hs = nx.Colors;
            IColor color = hs.Next();

            double dmin = lstBreakValues[0];

            int imax = lstBreakValues.Count-1;
            double dmax = lstBreakValues[imax];
            string sbreak=" - ";

            int i = 0;
            while (color != null)
            {
                Color somecolor = ConvertESRI2Color(color);
                m_claasifiedInfo.lstColor.Add(somecolor);

                double dfrom = frmSymbology.m_min;
                if (i>0)
                {
                    dfrom = lstBreakValues[i - 1];
                }
                double dto = lstBreakValues[i];
                if (dto > dmax)
                    dto = dmax;

                string sfrom = string.Format("{0:0.####}", dfrom);
                string sto = string.Format("{0:0.####}", dto);

                string[] strs = new string[] { null, i.ToString(), sfrom + sbreak + sto, sfrom + sbreak + sto };
                ListViewItem item = new ListViewItem(strs);
                item.SubItems[0].BackColor = somecolor;
                lvwSymbolEx.Items.Add(item);

                m_claasifiedInfo.lstBreakValues.Add(dto);

                i++;
                color = hs.Next();
            }

            lvwSymbolEx.EndUpdate();
        }
Exemplo n.º 37
0
        private void InitialListViewSymbol(int icounts)
        {
            m_UniqueValuesInfo.lstColor.Clear();
            Color fc = btnFromColor.IsNoColor == true ? Color.White : btnFromColor.SelectedSystemColor;
            IColor fromColor = Convert2ESRIColor(fc);
            Color tc = btnToColor.IsNoColor == true ? Color.Black : btnToColor.SelectedSystemColor;
            IColor toColor = Convert2ESRIColor(tc);

            IAlgorithmicColorRamp nx = new AlgorithmicColorRampClass();
            nx.ToColor = toColor;
            nx.FromColor = fromColor;
            nx.Size = icounts;
            nx.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;
            bool isCreated = true;
            nx.CreateRamp(out isCreated);

            IEnumColors hs = nx.Colors;
            IColor color = hs.Next();
            int i = 0;
            while (color != null)
            {
                Color somecolor = ConvertESRI2Color(color);
                m_UniqueValuesInfo.lstColor.Add(somecolor);
                lvwSymbolEx.Items[i++].SubItems[0].BackColor = somecolor;
                color = hs.Next();
            }

            lvwSymbolEx.EndUpdate();
        }
Exemplo n.º 38
0
        public ClassRender(AxMapControl pMapControl, IFeatureLayer pFtLayer, int ClassCount, string pFieldName)
        {
            IGeoFeatureLayer pGeolayer;

            IActiveView pActiveView;

            pGeolayer = pFtLayer as IGeoFeatureLayer;

            pActiveView = pMapControl.ActiveView;

            //������Ϊ��ͳ�ƺͷ�������Ҫ�Ķ���

            ITable pTable;

            IClassifyGEN pClassify;//C#Ҫ�������ͬ��VB�еģ��������

            ITableHistogram pTableHist;//�൱��һ��ͳ�Ʊ�

            IBasicHistogram pBasicHist;//���������һ������Ҫ�ķ���

            double[] ClassNum;

            int ClassCountResult;//���ط��������

            IHsvColor pFromColor;

            IHsvColor pToColor;//���ڹ�������һ����ɫ������

            IAlgorithmicColorRamp pAlgo;

            pTable = pGeolayer as ITable;

            IMap pMap;

            pMap = pMapControl.Map;

            pMap.ReferenceScale = 0;

            pBasicHist = new BasicTableHistogramClass();//Ҳ����ʵ���� pTableHist��ѧ���������˼ά

            pTableHist = pBasicHist as ITableHistogram;

            pTableHist.Table = pTable;

            pTableHist.Field = pFieldName;

            object datavalus;

            object Frenquen;

            pBasicHist.GetHistogram(out datavalus,out  Frenquen);//������ݺ���Ӧ��Ƶ����

            pClassify = new EqualIntervalClass();

            try
            {
                pClassify.Classify(datavalus, Frenquen, ref ClassCount);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            // �������

            ClassNum  = (double[])pClassify.ClassBreaks;

            ClassCountResult = ClassNum.GetUpperBound(0);//���طּ�������

            IClassBreaksRenderer pClassBreak;

            pClassBreak = new ClassBreaksRendererClass();

            pClassBreak.Field = pFieldName;

            pClassBreak.BreakCount = ClassCountResult;

            pClassBreak.SortClassesAscending = true;

            pAlgo = new AlgorithmicColorRampClass();

            pAlgo.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;

            pFromColor = Hsv(60, 100, 96);

            pToColor = Hsv(0, 100, 96);

            pAlgo.FromColor = pFromColor;

            pAlgo.ToColor = pToColor;

            pAlgo.Size = ClassCountResult;

            bool ok;

            pAlgo.CreateRamp(out ok);

            IEnumColors pEnumColor;

            pEnumColor = pAlgo.Colors;

            pEnumColor.Reset();

            IColor pColor;

            ISimpleFillSymbol pSimFill;

               /* IRgbColor[] pRgbColor;//���Թ�����ɫ

            pRgbColor = new IRgbColor[ClassCountResult];

            for (int j = 0; j < ClassCountResult; j++)
            {
                int R = 50;

                int G = 100;

                int B = 50;

                R = R + 50;

                if (R > 250)
                {
                    R = 50;
                }
                if (G > 250)
                {
                    G = 100;
                }
                if (B > 250)
                {
                    B = 50;
                }

                G = G + 100;

                B = B + 50;

                pRgbColor[j] = ColorRgb(R, G, B);

            }
            */

            for (int indexColor = 0; indexColor <= ClassCountResult - 1; indexColor++)
            {
                pColor = pEnumColor.Next();

                pSimFill = new SimpleFillSymbolClass();

                 pSimFill.Color = pColor;

               // pSimFill.Color = pRgbColor[indexColor ];

                pSimFill.Style = esriSimpleFillStyle.esriSFSSolid;

                //Ⱦɫ

                pClassBreak.set_Symbol(indexColor, pSimFill as ISymbol);

                pClassBreak.set_Break(indexColor, ClassNum[indexColor + 1]);

            }

            pGeolayer.Renderer = pClassBreak as IFeatureRenderer;

            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
Exemplo n.º 39
0
        /// <summary>
        /// Stretchդ����Ⱦ
        /// </summary>
        /// <param name="rasterLayer">դ��ͼ��</param>
        /// <param name="VlaueVMax">Value���ֵ</param>
        /// <param name="VlaueVMin">Value��Сֵ</param>
        /// <param name="fromColor">ɫ�׿�ʼ��ɫ</param>
        /// <param name="toColor">ɫ�׽�����ɫ</param>
        /// <param name="bDisplayBackGroundV">�Ƿ���ʾ����</param>
        /// <param name="BackGroundValue">��ʾ������ֵ</param>
        /// <param name="BackGroundColor">������ɫ</param>
        /// <param name="bUserHillShade">�Ƿ�����Ӱ</param>
        /// <param name="zScale">��ӰZֵ</param>
        /// <param name="nodataColor">Nodata��ɫ</param>
        /// <param name="StretchType">Stretch����</param>
        /// <param name="StretchN">Stretch Nֵ</param>
        /// <param name="bInvert">Stretchֵ�Ƿ�ת</param>
        /// <param name="StatisticsType">ͳ������</param>
        /// <returns></returns>
        private void StretchRenderer(IRasterLayer rasterLayer, string VlaueVMax, string VlaueVMin, string ValueMedium, IColor fromColor, IColor toColor,
            bool bDisplayBackGroundV, double BackGroundValue, IColor BackGroundColor, bool bUserHillShade, Double zScale, IColor nodataColor,
            string StretchType, double StretchN, bool bInvert, string StatisticsType)
        {
            try
            {
                //Create the color ramp.
                IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass();
                colorRamp.FromColor = fromColor;
                colorRamp.ToColor = toColor;
                colorRamp.Size = 10;
                bool createColorRamp;
                colorRamp.CreateRamp(out createColorRamp);

                //Create a stretch renderer.
                IRasterStretchColorRampRenderer stretchRenderer = new
                  RasterStretchColorRampRendererClass();
                IRasterRenderer rasterRenderer = (IRasterRenderer)stretchRenderer;

                //Set the renderer properties.
                IRaster raster = rasterLayer.Raster;
                rasterRenderer.Raster = raster;
                rasterRenderer.Update();

                stretchRenderer.BandIndex = 0;
                stretchRenderer.ColorRamp = colorRamp;
                stretchRenderer.LabelLow = VlaueVMin;
                stretchRenderer.LabelHigh =  VlaueVMax;
                stretchRenderer.LabelMedium = ValueMedium;

                (stretchRenderer as IRasterStretchMinMax).UseCustomStretchMinMax = true;

                (stretchRenderer as IHillShadeInfo).UseHillShade = bUserHillShade;
                if (bUserHillShade == true)
                    (stretchRenderer as IHillShadeInfo).ZScale = zScale;

                (stretchRenderer as IRasterStretch2).Background = bDisplayBackGroundV;
                //double dBackGroundValue = 0;
                if (bDisplayBackGroundV == true)
                {
                    (stretchRenderer as IRasterStretch2).BackgroundValue=BackGroundValue;
                    (stretchRenderer as IRasterStretch2).BackgroundColor = BackGroundColor;

                }

                 switch(StretchType)
                {

                    case "NONE":
                        (stretchRenderer as IRasterStretch2).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE;
                        break;
                    case "DefaultFromSource":
                        (stretchRenderer as IRasterStretch2).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_DefaultFromSource;
                        break;
                    case "Custom":
                        (stretchRenderer as IRasterStretch2).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_Custom;
                        break;
                    case "StandardDeviations":
                        (stretchRenderer as IRasterStretch2).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
                        break;
                    case "HistogramEqualize":
                        (stretchRenderer as IRasterStretch2).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_HistogramEqualize;
                        break;
                    case "MinimumMaximum":
                        (stretchRenderer as IRasterStretch2).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_MinimumMaximum;
                        break;
                    case "HistogramSpecification":
                        (stretchRenderer as IRasterStretch2).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_HistogramSpecification;
                        break;
                    case "Count":
                        (stretchRenderer as IRasterStretch2).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_Count;
                        break;
                     default:
                        (stretchRenderer as IRasterStretch2).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
                         break;

                }
                (stretchRenderer as IRasterStretch2).StandardDeviationsParam = StretchN;

                switch(StatisticsType)
                {
                    case "AreaOfView":
                        (stretchRenderer as IRasterStretch2).StretchStatsType
                            = esriRasterStretchStatsTypeEnum.esriRasterStretchStats_AreaOfView;
                        //IArray ary = (stretchRenderer as IRasterStretch2).StretchStats;

                        //frmSymbology.m_statistics_Min =(double) ary.get_Element(0);
                        //frmSymbology.m_statistics_Max =(double) ary.get_Element(1);
                        //frmSymbology.m_statistics_Mean = (double)ary.get_Element(2);
                        //frmSymbology.m_statistics_stdDev = (double)ary.get_Element(3);
                        break;
                    case "Dataset":
                        (stretchRenderer as IRasterStretch2).StretchStatsType
                            = esriRasterStretchStatsTypeEnum.esriRasterStretchStats_Dataset;
                        break;
                    case "GlobalStats":
                        (stretchRenderer as IRasterStretch2).StretchStatsType
                            = esriRasterStretchStatsTypeEnum.esriRasterStretchStats_GlobalStats;
                        break;
                }

                (stretchRenderer as IRasterStretch2).Invert = bInvert;
                //Set the stretch type.
                //IRasterStretch stretchType = (IRasterStretch)rasterRenderer;
                //stretchType.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
                //stretchType.StandardDeviationsParam = 2;

                rasterLayer.Renderer =stretchRenderer as IRasterRenderer;
                rasterLayer.Draw(esriDrawPhase.esriDPGeography,m_MainMap.ActiveView.ScreenDisplay, null);
                m_MainMap.ActiveView.Refresh();
                m_MainTOC.Update();
                //return rasterRenderer;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return ;
            }
        }
        public ESRI.ArcGIS.Carto.IRasterRenderer Pick(ESRI.ArcGIS.esriSystem.IArray pRenderers, ESRI.ArcGIS.Geodatabase.IRasterDataset pRasterDataset)
        {
            IRasterRenderer rasterRenderer = null;
            IRasterRGBRenderer rasterRGBRenderer = null;
            IRasterStretchColorRampRenderer rasterStretchColorRampRenderer = null;

            // Get the renderers
            int Count = pRenderers.Count;
            int i = 0;
            for (i = 0; i < Count; i++)
            {

                rasterRenderer = (IRasterRenderer)(pRenderers.get_Element(i));

                if (rasterRenderer is IRasterStretchColorRampRenderer)
                {
                    rasterStretchColorRampRenderer = (IRasterStretchColorRampRenderer)rasterRenderer;
                }
                else if (rasterRenderer is IRasterRGBRenderer)
                {
                    rasterRGBRenderer = (IRasterRGBRenderer)rasterRenderer;
                }

            }

            IRasterDataset2 rasterDataset2 = (IRasterDataset2)pRasterDataset;
            IRasterBandCollection rasterBandCollection = (IRasterBandCollection)rasterDataset2;

            if (rasterBandCollection.Count > 5)
            {

                // Use band 4,5 and 3 as red, green and blue
                rasterRenderer = (IRasterRenderer)rasterRGBRenderer;
                rasterRGBRenderer.SetBandIndices(3, 4, 2);
                return (IRasterRenderer)rasterRGBRenderer;

            }
            else // Special stretch
            {

                IRasterBand rasterBand = rasterBandCollection.Item(0);

                bool hasTable = false;
                rasterBand.HasTable(out hasTable);

                if (hasTable == false)
                {

                    // Simply change the color ramp for the stretch renderer
                    //IColor fromColor = new RgbColorClass();
                    //fromColor.RGB = Microsoft.VisualBasic.Information.RGB(255, 200, 50);
                    IColor fromColor = CreateRGBColor(255, 200, 50) as IColor;

                    //IColor toColor = new RgbColorClass();
                    //toColor.RGB = Microsoft.VisualBasic.Information.RGB(180, 125, 0);
                    IColor toColor = CreateRGBColor(180, 125, 0) as IColor;

                    // Create color ramp
                    IAlgorithmicColorRamp algorithmicColorRamp = new AlgorithmicColorRampClass();
                    algorithmicColorRamp.Size = 255;
                    algorithmicColorRamp.FromColor = fromColor;
                    algorithmicColorRamp.ToColor = toColor;
                    bool createRamp = false;
                    algorithmicColorRamp.CreateRamp(out createRamp);

                    if (createRamp == true)
                    {

                        rasterRenderer = (IRasterRenderer)rasterStretchColorRampRenderer;
                        rasterStretchColorRampRenderer.BandIndex = 0;
                        rasterStretchColorRampRenderer.ColorRamp = algorithmicColorRamp;
                        return (IRasterRenderer)rasterStretchColorRampRenderer;

                    }

                }

            }

            return rasterRenderer;
        }
Exemplo n.º 41
0
        private void DynamicCreateRamps(int count, IColor fc, IColor tc)
        {
            deleteTempControls(count);
            int dx = btnFromColor.Location.X + btnFromColor.Width;
            int dy = btnFromColor.Location.Y;

            int dWidth = btnToColor.Location.X - btnFromColor.Location.X - btnToColor.Width;
            int dHeight = btnFromColor.Height;

            int newHeight = dHeight;
            int newWidth = dWidth / count;

            IAlgorithmicColorRamp nx = new AlgorithmicColorRampClass();
            nx.ToColor = tc;
            nx.FromColor = fc;
            nx.Size = count;
            nx.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;

            bool isCreated = true;
            nx.CreateRamp(out isCreated);

            IEnumColors hs = nx.Colors;
            IColor color = hs.Next();
            int i = 0;
            while (color != null)
            {
                //Debug.WriteLine(color.RGB);
                int R = color.RGB & 0xff;
                int G = (color.RGB & 0xff00) / 0x100;
                int B = (color.RGB & 0xff0000) / 0x10000;
                Color somecolor = Color.FromArgb(R, G, B);

                Label p = new Label();
                p.Name = "MyUVPanels" + i.ToString();//���������ƣ������޷���ʾ
                p.Location = new System.Drawing.Point(dx + newWidth * i++, dy);

                p.Size = new System.Drawing.Size(newWidth, newHeight);
                p.BackColor = somecolor;
                this.Controls.Add(p);
                color = hs.Next();
            }
        }
Exemplo n.º 42
0
        //Ϊդ��ͼ�����ݽ��з�����ɫ
        public static IRasterLayer GetRLayerClassifyColor(IRaster pRaster, double dMaxDis)
        {
            IRasterClassifyColorRampRenderer pClassRen = new RasterClassifyColorRampRendererClass();
            IRasterRenderer pRasRen = pClassRen as RasterClassifyColorRampRendererClass;
            //Set raster for the render and update
            pRasRen.Raster = pRaster;
            pClassRen.ClassCount = 10;
            pRasRen.Update();
            //Create a color ramp to use
            //���������յ���ɫ
            IColor pFromColor = new RgbColorClass();
            IRgbColor pRgbColor = pFromColor as IRgbColor;
            pRgbColor.Red = 255;
            pRgbColor.Green = 0;
            pRgbColor.Blue = 0;
            IColor pToColor = new RgbColorClass();
            pRgbColor = pToColor as IRgbColor;
            pRgbColor.Red = 0;
            pRgbColor.Green = 255;
            pRgbColor.Blue = 0;
            //������ɫ�ּ�
            IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass();
            pRamp.Size = 10;
            pRamp.FromColor = pFromColor;
            pRamp.ToColor = pToColor;
            bool ok = true;
            pRamp.CreateRamp(out ok);
            //Create symbol for the classes
            IFillSymbol pFSymbol = new SimpleFillSymbolClass();

            double LabelValue = Convert.ToDouble(dMaxDis / 6);
            for (int i = 0; i <= pClassRen.ClassCount - 1; i++)
            {
                pFSymbol.Color = pRamp.get_Color(i);
                pClassRen.set_Symbol(i, pFSymbol as ISymbol);
                double h1 = LabelValue * i;
                double h2 = LabelValue * (i + 1);
                pClassRen.set_Label(i, h1.ToString() + "��" + h2.ToString());
            }
            //Update the renderer and plug into layer
            pRasRen.Update();
            IRasterLayer pRLayer = new RasterLayerClass();
            pRLayer.CreateFromRaster(pRaster);
            pRLayer.Renderer = pClassRen as IRasterRenderer;
            return pRLayer;
        }
Exemplo n.º 43
0
 //创建颜色带
 private IColorRamp CreateAlgorithmicColorRamp(int count)
 {
     //创建一个新AlgorithmicColorRampClass对象
     IAlgorithmicColorRamp algColorRamp = new AlgorithmicColorRampClass();
     IRgbColor fromColor = new RgbColorClass();
     IRgbColor toColor = new RgbColorClass();
     //创建起始颜色对象
     fromColor.Red = 255;
     fromColor.Green = 0;
     fromColor.Blue = 0;
     //创建终止颜色对象
     toColor.Red = 0;
     toColor.Green = 0;
     toColor.Blue = 255;
     //设置AlgorithmicColorRampClass的起止颜色属性
     algColorRamp.ToColor = fromColor;
     algColorRamp.FromColor = toColor;
     //设置梯度类型
     algColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
     //设置颜色带颜色数量
     algColorRamp.Size = count;
     //创建颜色带
     bool bture = true;
     algColorRamp.CreateRamp(out bture);
     return algColorRamp;
 }
Exemplo n.º 44
0
        public static IRasterRenderer StretchRender(IRasterDataset pRasterDataset)
        {
            try
            {
                //Define the from and to colors for the color ramp
                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 AlgorithmicColorRampClass();
                pRamp.Size=10;
                pRamp.FromColor=pFromColor;
                pRamp.ToColor=pToColor;
                bool createColorRamp;
                pRamp.CreateRamp(out createColorRamp);
                //create a stretch renderer
                IRasterStretchColorRampRenderer pStrechRenderer=new RasterStretchColorRampRendererClass();
                IRasterRenderer pRasterRenderer=(IRasterRenderer)pStrechRenderer;
                //set the renderer properties
                IRaster pRaster =pRasterDataset.CreateDefaultRaster();
                pRasterRenderer.Raster=pRaster;
                pRasterRenderer.Update();
                //
                pStrechRenderer.BandIndex=0;
                pStrechRenderer.ColorRamp=pRamp;
                IRasterStretch  pStretchType=(IRasterStretch)pRasterRenderer;
                pStretchType.StretchType=esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
                pStretchType.StandardDeviationsParam=2;
                return pRasterRenderer;

            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return null;
            }
        }
Exemplo n.º 45
0
        public static IRasterRenderer ClassifyRenderer(ESRI.ArcGIS.Geodatabase.IRasterDataset pRasterDataset)
        {
            try
            {
                //create the classify render:创建渲染器
                IRasterClassifyColorRampRenderer pClassifyRenderer=new RasterClassifyColorRampRendererClass();
                IRasterRenderer pRasterRenderer=(IRasterRenderer)pClassifyRenderer;
                IRaster pRaster=pRasterDataset.CreateDefaultRaster();
                pRasterRenderer.Raster=pRaster;
                pClassifyRenderer.ClassCount=10;
                pRasterRenderer.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=255;

                //set the color ramp for the symbology:生成色带
                IAlgorithmicColorRamp pRamp=new AlgorithmicColorRampClass();
                pRamp.Size=10;
                pRamp.FromColor=pFromColor;
                pRamp.ToColor=pToColor;
                bool pBoolColorRamp;
                pRamp.CreateRamp(out pBoolColorRamp);
                //create the symbol for the classes.:创建符号
                IFillSymbol pFillSymbol=new SimpleFillSymbolClass();
                for (int i=0;i<pClassifyRenderer.ClassCount;i++){

                    pFillSymbol.Color=pRamp.get_Color(i);
                    pClassifyRenderer.set_Symbol(i,(ISymbol)pFillSymbol);
                    pClassifyRenderer.set_Label(i,Convert.ToString(i));

                }
                return pRasterRenderer;

            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return null;
            }
        }
Exemplo n.º 46
0
        private IEnumColors CreateAlgColorRamp(IColor fromColor, IColor toColor, int count)
        {
            IAlgorithmicColorRamp pRampColor = new AlgorithmicColorRampClass();
            pRampColor.FromColor = fromColor;
            pRampColor.ToColor = toColor;
            pRampColor.Size = count;
            bool b = true;
            pRampColor.CreateRamp(out b);

            return pRampColor.Colors;
        }
Exemplo n.º 47
0
        private void InitialListViewSymbol(List<string> lstCounts,int icounts)
        {
            m_UniqueValuesInfo.lstColor.Clear();
            int classcount = icounts;
            Color fc = btnFromColor.IsNoColor == true ? Color.White : btnFromColor.SelectedSystemColor;
            IColor fromColor = Convert2ESRIColor(fc);
            Color tc = btnToColor.IsNoColor == true ? Color.Black : btnToColor.SelectedSystemColor;
            IColor toColor = Convert2ESRIColor(tc);

            lvwSymbolEx.Items.Clear();
            lvwSymbolEx.BeginUpdate();

            IAlgorithmicColorRamp nx = new AlgorithmicColorRampClass();
            nx.ToColor = toColor;
            nx.FromColor = fromColor;
            nx.Size = classcount;
            nx.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;
            bool isCreated = true;
            nx.CreateRamp(out isCreated);

            IEnumColors hs = nx.Colors;
            IColor color = hs.Next();
            int i = 0;
            while (color != null)
            {
                Color somecolor = ConvertESRI2Color(color);
                m_UniqueValuesInfo.lstColor.Add(somecolor);
                string strval = (frmSymbology.m_min +i).ToString();
                string[] strs = new string[] { null, strval, strval,lstCounts[i++]};
                ListViewItem item = new ListViewItem(strs);

                item.SubItems[0].BackColor = somecolor;
                lvwSymbolEx.Items.Add(item);
                color = hs.Next();
            }

            lvwSymbolEx.EndUpdate();
        }
Exemplo n.º 48
0
        private IEnumColors MultiPartColorRamp(string strColorRamp, string strAlgorithm, int intGCBreakeCount)
        {
            try
            {
                IEnumColors pEnumColors = null;

                if (strColorRamp == "Blue Light to Dark" || strColorRamp == "Green Light to Dark" || strColorRamp == "Orange Light to Dark" || strColorRamp == "Red Light to Dark")
                {
                    IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass();
                    switch (strAlgorithm)
                    {
                    case "HSV":
                        pColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
                        break;

                    case "CIE Lab":
                        pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        break;

                    case "Lab LCh":
                        pColorRamp.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;
                        break;

                    default:
                        pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        break;
                    }

                    IRgbColor pColor1 = new RgbColor();
                    IRgbColor pColor2 = new RgbColor();

                    switch (strColorRamp)
                    {
                    case "Blue Light to Dark":
                        pColor1 = pSnippet.getRGB(239, 243, 255);
                        pColor2 = pSnippet.getRGB(8, 81, 156);
                        break;

                    case "Green Light to Dark":
                        pColor1 = pSnippet.getRGB(237, 248, 233);
                        pColor2 = pSnippet.getRGB(0, 109, 44);
                        break;

                    case "Orange Light to Dark":
                        pColor1 = pSnippet.getRGB(254, 237, 222);
                        pColor2 = pSnippet.getRGB(166, 54, 3);
                        break;

                    case "Red Light to Dark":
                        pColor1 = pSnippet.getRGB(254, 229, 217);
                        pColor2 = pSnippet.getRGB(165, 15, 21);
                        break;

                    default:
                        pColor1 = pSnippet.getRGB(254, 229, 217);
                        pColor2 = pSnippet.getRGB(165, 15, 21);
                        break;
                    }

                    Boolean blnOK = true;

                    pColorRamp.FromColor = pColor1;
                    pColorRamp.ToColor   = pColor2;
                    pColorRamp.Size      = intGCBreakeCount;
                    pColorRamp.CreateRamp(out blnOK);


                    //arrColors = new int [intGCBreakeCount,3];
                    pEnumColors = pColorRamp.Colors;
                }
                else if (strColorRamp == "Custom")
                {
                    Boolean             blnOK           = true;
                    frmColorRamps       m_pColorRamps   = System.Windows.Forms.Application.OpenForms["frmColorRamps"] as frmColorRamps;
                    IMultiPartColorRamp pMultiColorRamp = m_pColorRamps.pMulitColorRampsResults;

                    pMultiColorRamp.Size = intGCBreakeCount;
                    pMultiColorRamp.CreateRamp(out blnOK);


                    pEnumColors = pMultiColorRamp.Colors;
                }
                else
                {
                    IAlgorithmicColorRamp pColorRamp1 = new AlgorithmicColorRampClass();
                    IAlgorithmicColorRamp pColorRamp2 = new AlgorithmicColorRampClass();


                    switch (strAlgorithm)
                    {
                    case "HSV":
                        pColorRamp1.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
                        pColorRamp2.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
                        break;

                    case "CIE Lab":
                        pColorRamp1.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        pColorRamp2.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        break;

                    case "Lab LCh":
                        pColorRamp1.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;
                        pColorRamp2.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;
                        break;

                    default:
                        pColorRamp1.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        pColorRamp2.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        break;
                    }

                    IRgbColor pColor1 = new RgbColor();
                    IRgbColor pColor2 = new RgbColor();
                    IRgbColor pColor3 = new RgbColor();

                    switch (strColorRamp)
                    {
                    case "Blue to Red":
                        pColor1 = pSnippet.getRGB(49, 54, 149);
                        pColor2 = pSnippet.getRGB(255, 255, 191);
                        pColor3 = pSnippet.getRGB(165, 0, 38);
                        break;

                    case "Green to Purple":
                        pColor1 = pSnippet.getRGB(0, 68, 27);
                        pColor2 = pSnippet.getRGB(247, 247, 247);
                        pColor3 = pSnippet.getRGB(64, 0, 75);
                        break;

                    case "Green to Red":
                        pColor1 = pSnippet.getRGB(0, 104, 55);
                        pColor2 = pSnippet.getRGB(255, 255, 191);
                        pColor3 = pSnippet.getRGB(165, 0, 38);
                        break;

                    case "Purple to Brown":
                        pColor1 = pSnippet.getRGB(45, 0, 75);
                        pColor2 = pSnippet.getRGB(247, 247, 247);
                        pColor3 = pSnippet.getRGB(127, 59, 8);
                        break;

                    default:
                        pColor1 = pSnippet.getRGB(49, 54, 149);
                        pColor2 = pSnippet.getRGB(255, 255, 191);
                        pColor3 = pSnippet.getRGB(165, 0, 38);
                        break;
                    }


                    pColorRamp1.FromColor = pColor1;
                    pColorRamp1.ToColor   = pColor2;
                    pColorRamp2.FromColor = pColor2;
                    pColorRamp2.ToColor   = pColor3;

                    Boolean blnOK = true;

                    IMultiPartColorRamp pMultiColorRamp = new MultiPartColorRampClass();
                    pMultiColorRamp.Ramp[0] = pColorRamp1;
                    pMultiColorRamp.Ramp[1] = pColorRamp2;
                    pMultiColorRamp.Size    = intGCBreakeCount;
                    pMultiColorRamp.CreateRamp(out blnOK);


                    pEnumColors = pMultiColorRamp.Colors;
                }
                pEnumColors.Reset();
                return(pEnumColors);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.Handle.ToString() + " Error:" + ex.Message);
                return(null);
            }
        }
Exemplo n.º 49
0
        //根据起点颜色、终点颜色和级别数目,产生色带
        public List<Color> ProduceColors(Color start, Color end, int gradecount)
        {
            //创建一个新AlgorithmicColorRampClass对象
            IAlgorithmicColorRamp algColorRamp = new AlgorithmicColorRampClass();
            algColorRamp.ToColor = this.ConvertColorToIColor(end);//从.net的颜色转换
            algColorRamp.FromColor = this.ConvertColorToIColor(start);
            //设置梯度类型
            algColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
            //设置颜色带颜色数量
            algColorRamp.Size = gradecount;
            //创建颜色带
            bool bture = true;
            algColorRamp.CreateRamp(out bture);
            //使用IEnumColors获取颜色带
            IEnumColors pEnumColors = algColorRamp.Colors;

            List<Color> result = new List<Color>();
            pEnumColors.Reset();//必须重设
            ESRI.ArcGIS.Display.IColor pC = pEnumColors.Next();
            while (pC != null)
            {
                result.Add(ColorTranslator.FromOle(pC.RGB));//ESRI颜色转换为.net颜色
                pC = pEnumColors.Next();
            }
            return result;
        }
Exemplo n.º 50
0
        //创建颜色带
        private IColorRamp CreateAlgorithmicColorRamp(int count)
        {
            IAlgorithmicColorRamp algColorRamp = new AlgorithmicColorRampClass();
            IRgbColor fromColor = new RgbColorClass();
            IRgbColor toColor = new RgbColorClass();

            fromColor.Red = 255;
            fromColor.Green = 255;
            fromColor.Blue = 255;

            toColor.Red = 255;
            toColor.Green = 0;
            toColor.Blue = 0;

            algColorRamp.ToColor = toColor;

            algColorRamp.FromColor = fromColor;

            algColorRamp.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;

            algColorRamp.Size = count;

            bool bture = true;
            algColorRamp.CreateRamp(out bture);
            return algColorRamp;
        }
Exemplo n.º 51
0
		//为栅格图层数据进行拉伸着色
		public static IRasterLayer SetStretchRenderer(IRaster pRaster)
		{
			try
			{
				//创建着色类和QI栅格着色
				IRasterStretchColorRampRenderer pStretchRen=new RasterStretchColorRampRendererClass();
				IRasterRenderer pRasRen=pStretchRen as IRasterRenderer;
				//为着色和更新设置栅格数据
				pRasRen.Raster=pRaster;
				pRasRen.Update();
				//定义起点和终点颜色
				IColor pFromColor=new RgbColorClass();
				IRgbColor pRgbColor=pFromColor as IRgbColor;
				pRgbColor.Red=255;
				pRgbColor.Green=0;
				pRgbColor.Blue=0;
				IColor pToColor=new RgbColorClass();
				pRgbColor=pToColor as IRgbColor;
				pRgbColor.Red=0;
				pRgbColor.Green=255;
				pRgbColor.Blue=0;
				//创建颜色分级
				IAlgorithmicColorRamp pRamp=new AlgorithmicColorRampClass();
				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 RasterLayerClass();
				pRLayer.CreateFromRaster(pRaster);
				pRLayer.Renderer = pStretchRen as IRasterRenderer ;
				return pRLayer;	


			}
			catch(Exception ex)
			{
				
				Console.WriteLine(ex.Message);
				return null;
			}
		}