Example #1
0
        private void ChangeStrechRender(IRasterLayer rasterLayer /*, double dbMaxValue, double dbMinValue*/)
        {
            IRaster pRaster = rasterLayer.Raster;
            IRasterBandCollection pRasterBandCollection = pRaster as IRasterBandCollection;
            IRasterBand           pRasterBand           = pRasterBandCollection.Item(0);

            if (pRasterBand == null)
            {
                return;
            }

            bool bFlag = false;

            pRasterBand.HasStatistics(out bFlag);
            if (!bFlag)
            {
                pRasterBand.ComputeStatsAndHist();
            }

            double dbMaxValue = double.NaN;
            double dbMinValue = double.NaN;

            IRasterStatistics pStaticts = pRasterBand.Statistics;

            dbMaxValue = pStaticts.Maximum;
            dbMinValue = pStaticts.Minimum;

            //设置最大最小渲染方式
            IRasterStretch       pRasterStretch       = new RasterStretchColorRampRendererClass();
            IRasterStretchMinMax pRasterStretchMinMax = pRasterStretch as IRasterStretchMinMax;

            pRasterStretchMinMax.UseCustomStretchMinMax = true;
            pRasterStretchMinMax.CustomStretchMin       = dbMinValue;
            pRasterStretchMinMax.CustomStretchMax       = dbMaxValue;
            pRasterStretch.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_MinimumMaximum;

            //update
            IRasterStretchColorRampRenderer pStretchColorRasterRenderer = (IRasterStretchColorRampRenderer)pRasterStretch;;
            IRasterRenderer pRasterRenderer = pStretchColorRasterRenderer as IRasterRenderer;

            pRasterRenderer.Raster = rasterLayer.Raster;
            pRasterLayer.Renderer  = pStretchColorRasterRenderer as IRasterRenderer;
            pRasterRenderer.Update();
        }
Example #2
0
        /// <summary>
        /// Ge the render color of the input layer rendering with stretched color ramp.
        /// </summary>
        /// <param name="layer">Input raster layer</param>
        /// <param name="value">Pixel value</param>
        /// <returns></returns>
        private static IColor GetRenderColor_Stretched(ILayer layer, double value)
        {
            IRasterLayer rasterLayer = (IRasterLayer)layer;

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

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

            IRasterRendererColorRamp colorRamp     = (IRasterRendererColorRamp)rasterLayer.Renderer;
            IRasterStretchMinMax     stretchMinMax = (IRasterStretchMinMax)rasterLayer.Renderer;

            double min = 0;
            double max = 0;

            if (stretchMinMax.UseCustomStretchMinMax)
            {
                min = stretchMinMax.CustomStretchMin;
                max = stretchMinMax.CustomStretchMax;
            }
            else
            {
                min = stretchMinMax.StretchMin;
                max = stretchMinMax.StretchMax;
            }

            if (value >= max)
            {
                return(colorRamp.ColorRamp.Color[255]);
            }

            if (value <= min)
            {
                return(colorRamp.ColorRamp.Color[0]);
            }

            return(colorRamp.ColorRamp.Color[Convert.ToInt32(System.Math.Round(255 * (value - min)))]);
        }
Example #3
0
        public static IRasterRenderer CreateESRIDefinedContinuousRenderer(GCDConsoleLib.Raster gRaster, int iClassCount, string sColorRampName, bool bInvert = false)
        {
            try
            {
                gRaster.ComputeStatistics();
                decimal maxValue        = gRaster.GetStatistics()["max"];
                int     iRound          = GetMagnitude(maxValue);
                double  maxValueRounded = Math.Round((double)maxValue, Math.Abs(iRound));

                RasterStretchColorRampRenderer stretchRenderer = new RasterStretchColorRampRendererClass();
                IRasterRenderer rasterRenderer = (IRasterRenderer)stretchRenderer;
                IRasterDataset  rasterDataset  = ArcMapUtilities.GetRasterDataset(gRaster);
                IRaster         raster         = rasterDataset.CreateDefaultRaster();
                rasterRenderer.Raster = raster;
                IColorRamp               pColorRamp       = null;
                IStyleGalleryItem        pStyleItem       = GetESRIStyleColorRamp(out pColorRamp, sColorRampName);
                IRasterRendererColorRamp pRenderColorRamp = (IRasterRendererColorRamp)rasterRenderer;
                pRenderColorRamp.ColorScheme = pStyleItem.Name;
                IRasterStretchMinMax pStretchInfo = (IRasterStretchMinMax)stretchRenderer;
                pStretchInfo.CustomStretchMin       = 0;
                pStretchInfo.CustomStretchMax       = maxValueRounded;
                pStretchInfo.UseCustomStretchMinMax = true;
                stretchRenderer.LabelHigh           = maxValueRounded.ToString();
                stretchRenderer.LabelLow            = "0.0";
                if (bInvert)
                {
                    IRasterStretch2 pStretch = (IRasterStretch2)stretchRenderer;
                    pStretch.Invert = true;
                }

                rasterRenderer.Update();
                return(rasterRenderer);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Example #4
0
        private void btnuse_Click(object sender, EventArgs e)
        {
            if (treeshow.SelectedIndex == 1)
            {
                IRasterRGBRenderer2 pRRGBRenderUse = new RasterRGBRendererClass();
                if ((bool)gridsymbol.Rows[0].Cells[0].Value == true)
                {
                    pRRGBRenderUse.UseRedBand = true;
                }
                else
                {
                    pRRGBRenderUse.UseRedBand = false;
                }

                if ((bool)gridsymbol.Rows[1].Cells[0].Value == true)
                {
                    pRRGBRenderUse.UseGreenBand = true;
                }
                else
                {
                    pRRGBRenderUse.UseGreenBand = false;
                }
                if ((bool)gridsymbol.Rows[2].Cells[0].Value == true)
                {
                    pRRGBRenderUse.UseBlueBand = true;
                }
                else
                {
                    pRRGBRenderUse.UseBlueBand = false;
                }
                if ((bool)gridsymbol.Rows[3].Cells[0].Value == true)
                {
                    pRRGBRenderUse.UseAlphaBand = true;
                }
                else
                {
                    pRRGBRenderUse.UseAlphaBand = false;
                }

                pRRGBRenderUse.RedBandIndex   = cmbred.SelectedIndex;
                pRRGBRenderUse.GreenBandIndex = cmbgreen.SelectedIndex;
                pRRGBRenderUse.BlueBandIndex  = cmbblue.SelectedIndex;
                pRRGBRenderUse.AlphaBandIndex = cmbalpha.SelectedIndex;

                pRLayer.Renderer = (IRasterRenderer)pRRGBRenderUse;
            }
            else
            {
                if (pRStretch.StretchType == esriRasterStretchTypesEnum.esriRasterStretch_MinimumMaximum)
                {
                    if (txtmin.Text == "" && txtmax.Text != "")
                    {
                        MessageBox.Show("请设置拉伸的最小值", "提示", MessageBoxButtons.OK);
                    }
                    else if (txtmax.Text == "" && txtmin.Text != "")
                    {
                        MessageBox.Show("请设置拉伸的最大值", "提示", MessageBoxButtons.OK);
                    }
                    else if (txtmax.Text == "" && txtmin.Text == "")
                    {
                        MessageBox.Show("请设置拉伸的最大值以及最小值", "提示", MessageBoxButtons.OK);
                    }
                    else
                    {
                        pRasterStretchMinMax = (IRasterStretchMinMax)pRStretch;
                        pRasterStretchMinMax.UseCustomStretchMinMax = true;
                        pRasterStretchMinMax.CustomStretchMin       = double.Parse(txtmin.Text);
                        pRasterStretchMinMax.CustomStretchMax       = double.Parse(txtmax.Text);
                        pRStretch             = (IRasterStretch)pRasterStretchMinMax;
                        pRStretch.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_MinimumMaximum;
                    }
                }

                if (chkdisplay.Checked == true)
                {
                    pRStretch.Background      = true;
                    pRStretch.BackgroundColor = ClsGDBDataCommon.ColorToIColor(colbackg.SelectedColor);
                    pRStretch.set_BackgroundValues(Convert.ToDouble(backvalue.Text));
                }
                else
                {
                    pRStretch.Background = false;
                }

                IRasterStretchColorRampRenderer pStretchColorRasterRenderer = (IRasterStretchColorRampRenderer)pRStretch;;
                IRasterRenderer pRasterRenderer = pStretchColorRasterRenderer as IRasterRenderer;
                pRasterRenderer.Raster = pRLayer.Raster;
                pRasterRenderer.Update();

                pStretchColorRasterRenderer.BandIndex = cmbBand.SelectedIndex;
                pStretchColorRasterRenderer.ColorRamp = PColorramp as IColorRamp;
                pRasterRenderer.Update();
                pRLayer.Renderer = pStretchColorRasterRenderer as IRasterRenderer;
            }


            if (pTocContral.Buddy == pMapContral.Object)
            {
                pTocContral.SetBuddyControl(pMapContral);
                pMapContral.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                pTocContral.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            else if (pTocContral.Buddy.Equals(pSceneControl.Object))
            {
                pTocContral.SetBuddyControl(pSceneControl);
                IActiveView pActiveView = pSceneControl.Scene as IActiveView;
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pRLayer, null);
                pTocContral.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
        }