Example #1
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);
            }
        }
Example #2
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);
            }
        }
Example #3
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);
            }
        }
        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);
        }