예제 #1
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;
        }
예제 #2
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;
        }
예제 #3
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;
        }
예제 #4
0
        //public void RasterClassify(IRasterLayer rastlayer, string classMethod, int count, IColorRamp ramp,double minValue)
        //{
        //    IRasterBand band = GetBand(rastlayer);
        //    if (band.Histogram == null)
        //    {
        //        band.ComputeStatsAndHist();
        //    }
        //    IRasterClassifyColorRampRenderer rasClassifyRender = new RasterClassifyColorRampRendererClass();
        //    IRasterRenderer rasRender = rasClassifyRender as IRasterRenderer;
        //    rasRender.Raster = rastlayer.Raster;
        //    rasRender.Update();
        //    int numClasses = count;
        //    IRasterHistogram pRasterHistogram = band.Histogram;
        //    double[] dblValues = pRasterHistogram.Counts as double[];
        //    int intValueCount = dblValues.GetUpperBound(0) + 1;
        //    double[] vValues = new double[intValueCount];
        //    IRasterStatistics pRasterStatistic = band.Statistics;
        //    //double dMaxValue = pRasterStatistic.Maximum;
        //    double dMaxValue = minValue;
        //    double dMinValue = pRasterStatistic.Minimum;
        //    double BinInterval = Convert.ToDouble((dMaxValue - dMinValue) / intValueCount);
        //    for (int i = 0; i < intValueCount; i++)
        //    {
        //        vValues[i] = i * BinInterval + pRasterStatistic.Minimum;
        //    }
        //    long[] longvalues = new long[dblValues.Length];
        //    for (int i = 0; i <= dblValues.Length - 1; i++)
        //    {
        //        longvalues[i] = long.Parse(Convert.ToString(dblValues[i]));
        //    }
        //    //IClassifyGEN classify = null;
        //    IClassify classify = null;
        //    switch (classMethod)
        //    {
        //        case "等间距分级":
        //            EqualInterval eqclassify = new EqualIntervalClass();
        //            eqclassify.Classify(vValues, longvalues, ref numClasses);
        //            classify = eqclassify as IClassify;
        //            break;
        //        case "自然断点分级":
        //            NaturalBreaks naclassify = new NaturalBreaksClass();
        //            naclassify.Classify(vValues, longvalues, ref numClasses);
        //            classify = naclassify as IClassify;
        //            break;
        //    }
        //    //switch (classMethod)
        //    //{
        //    //    case "等间距分级":
        //    //        classify = new EqualIntervalClass();
        //    //        break;
        //    //    case "自然断点分级":
        //    //        classify = new NaturalBreaksClass();
        //    //        break;
        //    //}
        //    //classify.Classify(vValues, longvalues, ref numClasses);
        //    double[] Classes = classify.ClassBreaks as double[];
        //    UID pUid = classify.ClassID;
        //    IRasterClassifyUIProperties rasClassifyUI = rasClassifyRender as IRasterClassifyUIProperties;
        //    rasClassifyUI.ClassificationMethod = pUid;
        //    rasClassifyRender.ClassCount = count;
        //    IColor pColor;
        //    ISimpleFillSymbol pSym;
        //    for (int j = 0; j < count; j++)
        //    {
        //        pColor = ramp.get_Color(j * (ramp.Size / count));
        //        pSym = new SimpleFillSymbolClass();
        //        pSym.Color = pColor;
        //        rasClassifyRender.set_Symbol(j, (ISymbol)pSym);
        //        rasRender.Update();
        //        if (Classes[j] == 0)
        //        {
        //            rasClassifyRender.set_Label(j, Classes[j].ToString() + "-" + Classes[j + 1].ToString("0.000"));
        //            rasRender.Update();
        //        }
        //        else
        //        {
        //            rasClassifyRender.set_Label(j, Classes[j].ToString("0.000") + "-" + Classes[j + 1].ToString("0.000"));
        //            rasRender.Update();
        //        }
        //    }
        //    rastlayer.Renderer = rasClassifyRender as IRasterRenderer;
        public void RasterClassify(IRasterLayer rastlayer, string classMethod, int count, IColorRamp ramp)
        {
            try
            {  //进行唯一值判断
                IUniqueValues values = new UniqueValuesClass();
                IRasterCalcUniqueValues unique = new RasterCalcUniqueValuesClass();
                unique.AddFromRaster(rastlayer.Raster, 0, values);
                int uniquecount = values.get_UniqueCount(0);
                //计算统计图
                IRasterBand band = GetBand(rastlayer);
                if (band.Histogram == null)
                {
                    band.ComputeStatsAndHist();
                }
                IRasterClassifyColorRampRenderer rasClassifyRender = new RasterClassifyColorRampRendererClass();
                IRasterRenderer rasRender = rasClassifyRender as IRasterRenderer;
                rasRender.Raster = rastlayer.Raster;
                rasRender.Update();

                int numClasses = count;
                IRasterHistogram pRasterHistogram = band.Histogram;
                double[] dblValues = pRasterHistogram.Counts as double[];
                int intValueCount = dblValues.GetUpperBound(0) + 1;
                double[] vValues = new double[intValueCount];
                IRasterStatistics pRasterStatistic = band.Statistics;
                double dMaxValue = pRasterStatistic.Maximum;
                double dMinValue = pRasterStatistic.Minimum;
                if (dMinValue == 0)
                {
                    pRasterStatistic.IgnoredValues = pRasterStatistic.Minimum;
                    pRasterStatistic.Recalculate();
                    dMinValue = pRasterStatistic.Minimum;
                }
                double BinInterval = Convert.ToDouble((dMaxValue - dMinValue) / intValueCount);
                for (int i = 0; i < intValueCount; i++)
                {
                    vValues[i] = i * BinInterval + pRasterStatistic.Minimum;
                }
                long[] longvalues = new long[dblValues.Length];
                for (int i = 0; i <= dblValues.Length - 1; i++)
                {
                    longvalues[i] = long.Parse(Convert.ToString(dblValues[i]));
                }
                //IClassifyGEN classify = null;
                IClassify classify = null;
                switch (classMethod)
                {
                    case "等间距分级":
                        EqualInterval eqclassify = new EqualIntervalClass();
                        eqclassify.Classify(vValues, longvalues, ref numClasses);
                        classify = eqclassify as IClassify;
                        break;
                    case "自然断点分级":
                        NaturalBreaks naclassify = new NaturalBreaksClass();
                        naclassify.Classify(vValues, longvalues, ref numClasses);
                        classify = naclassify as IClassify;
                        break;
                }
                #region
                //switch (classMethod)
                //{
                //    case "等间距分级":
                //        classify = new EqualIntervalClass();
                //        break;
                //    case "自然断点分级":
                //        classify = new NaturalBreaksClass();
                //        break;
                //}
                //classify.Classify(vValues, longvalues, ref numClasses);
                #endregion
                double[] Classes = classify.ClassBreaks as double[];
                UID pUid = classify.ClassID;
                IRasterClassifyUIProperties rasClassifyUI = rasClassifyRender as IRasterClassifyUIProperties;
                rasClassifyUI.ClassificationMethod = pUid;
                rasClassifyRender.ClassCount = count;
                IColor pColor;
                ISimpleFillSymbol pSym;
                //排除数值
                double[] exdouble = new double[2] { 0, Classes[0] };
                IRasterDataExclusion ex = rasClassifyRender as IRasterDataExclusion;
                ex.ExcludeValues = exdouble;
                ex.ExcludeColor = GET(255, 255, 255);
                for (int j = 0; j < count; j++)
                {
                    pColor = ramp.get_Color(j * (ramp.Size / count));
                    pSym = new SimpleFillSymbolClass();
                    pSym.Color = pColor;
                    rasClassifyRender.set_Symbol(j, (ISymbol)pSym);
                    rasRender.Update();
                    rasClassifyRender.set_Break(j, rasClassifyRender.get_Break(j));
                    rasClassifyRender.set_Label(j, Classes[j].ToString("0.000") + "-" + Classes[j + 1].ToString("0.000"));
                    rasRender.Update();
                }

                //IRasterProps rasterProps = (IRasterProps)rastlayer.Raster;
                //rasterProps.NoDataValue = 0;
                //IRasterDisplayProps props = rasClassifyRender as IRasterDisplayProps;
                //props.NoDataColor = GET(255, 255, 255);
                //rasRender.Update();
                rastlayer.Renderer = rasClassifyRender as IRasterRenderer;
            }
            catch(Exception ex)
            {
                //MessageBox.Show(ex.ToString());
                if (ex.ToString().Contains("唯一值过多"))
                {
                    MessageBox.Show("唯一值数量已达到限制(65536)");
                }
                else
                {
                    MessageBox.Show("还未计算唯一值,进行唯一值计算!");
                }
            }

            //catch
            //{
            //    MessageBox.Show("数据需要先计算统计值,请点击确定进行计算!");
            //}
        }
예제 #5
0
        public void RasterClassify(IRasterLayer rastlayer, string classMethod, int count, IColorRamp ramp)
        {
            IRasterBand band = GetBand(rastlayer);
            if (band.Histogram == null)
            {
                band.ComputeStatsAndHist();
            }
            IRasterClassifyColorRampRenderer rasClassifyRender = new RasterClassifyColorRampRendererClass();
            IRasterRenderer rasRender = rasClassifyRender as IRasterRenderer;
            rasRender.Raster = rastlayer.Raster;
            rasRender.Update();

            int numClasses = count;
            IRasterHistogram pRasterHistogram = band.Histogram;
            double[] dblValues = pRasterHistogram.Counts as double[];
            int intValueCount = dblValues.GetUpperBound(0) + 1;
            double[] vValues = new double[intValueCount];
            IRasterStatistics pRasterStatistic = band.Statistics;
            double dMaxValue = pRasterStatistic.Maximum;
            double dMinValue = pRasterStatistic.Minimum;
            if (dMinValue == 0)
            {
                pRasterStatistic.IgnoredValues = pRasterStatistic.Minimum;
                pRasterStatistic.Recalculate();
                dMinValue = pRasterStatistic.Minimum;
            }
            double BinInterval = Convert.ToDouble((dMaxValue - dMinValue) / intValueCount);
            for (int i = 0; i < intValueCount; i++)
            {
                vValues[i] = i * BinInterval + pRasterStatistic.Minimum;
            }
            long[] longvalues = new long[dblValues.Length];
            for (int i = 0; i <= dblValues.Length - 1; i++)
            {
                longvalues[i] = long.Parse(Convert.ToString(dblValues[i]));
            }
            //IClassifyGEN classify = null;
            IClassify classify = null;
            switch (classMethod)
            {
                case "等间距分级":
                    EqualInterval eqclassify = new EqualIntervalClass();
                    eqclassify.Classify(vValues, longvalues, ref numClasses);
                    classify = eqclassify as IClassify;
                    break;
                case "自然断点分级":
                    NaturalBreaks naclassify = new NaturalBreaksClass();
                    naclassify.Classify(vValues, longvalues, ref numClasses);
                    classify = naclassify as IClassify;
                    break;
            }
            //switch (classMethod)
            //{
            //    case "等间距分级":
            //        classify = new EqualIntervalClass();
            //        break;
            //    case "自然断点分级":
            //        classify = new NaturalBreaksClass();
            //        break;
            //}
            //classify.Classify(vValues, longvalues, ref numClasses);
            double[] Classes = classify.ClassBreaks as double[];
            UID pUid = classify.ClassID;
            IRasterClassifyUIProperties rasClassifyUI = rasClassifyRender as IRasterClassifyUIProperties;
            rasClassifyUI.ClassificationMethod = pUid;
            rasClassifyRender.ClassCount = count;
            IColor pColor;
            ISimpleFillSymbol pSym;
            for (int j = 0; j < count; j++)
            {
                IRasterProps rasterProps = (IRasterProps)rastlayer.Raster;
                rasterProps.NoDataValue = 0;
                pColor = ramp.get_Color(j * (ramp.Size / count));
                pSym = new SimpleFillSymbolClass();
                pSym.Color = pColor;
                rasClassifyRender.set_Symbol(j, (ISymbol)pSym);
                rasRender.Update();
                rasClassifyRender.set_Break(j,rasClassifyRender.get_Break(j));
                rasClassifyRender.set_Label(j, Classes[j].ToString("0.000") + "-" + Classes[j + 1].ToString("0.000"));
                rasRender.Update();
            }
            rastlayer.Renderer = rasClassifyRender as IRasterRenderer;
        }
예제 #6
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;
            }
        }
예제 #7
0
        /// <summary>
        /// ������Ⱦ
        /// </summary>
        /// <param name="rasterLayer">դ��ͼ��</param>
        /// <param name="VlaueFieldName">ֵ�ֶ�</param>
        /// <param name="NormalLizeFieldName">��һ���ֶΣ���ѡ��</param>
        /// <param name="classesCount">��������</param>
        /// <param name="fromColor">ɫ�׿�ʼ��ɫ</param>
        /// <param name="toColor">ɫ�׽�����ɫ</param>
        /// <param name="bShowClassBreaks">Whether or Not Show class breaks using cell values</param>
        /// <param name="NodataColor">��ֵ��ɫ</param>
        /// <param name="bUserHillShade">Whether or Not Use hillshade effect</param>
        /// <param name="zScale">IF Use hillshade effect Set the Z value</param>
        /// <returns></returns>
        private void ClassifyRenderer(IRasterLayer rasterLayer, string VlaueFieldName, string NormalLizeFieldName,
            int classesCount,IList<Color> lstColor,IList<double> lstBreakVal,IList<string> lstBreakLbl/*IColor fromColor, IColor toColor*/, bool bShowClassBreaks, IColor nodataColor, bool bUserHillShade,Double zScale)
        {
            try
            {
                //create the classify renderer
                IRasterClassifyColorRampRenderer classifyRenderer = new RasterClassifyColorRampRendererClass();
                IRasterRenderer rasterRenderer = (IRasterRenderer)classifyRenderer;

                //setup renderer properties
                IRaster raster = rasterLayer.Raster;
                rasterRenderer.Raster = raster;
                classifyRenderer.ClassCount = classesCount;
                rasterRenderer.Update();

                //create symbol for the classes
                IFillSymbol fillSymbol = new SimpleFillSymbolClass();
                for (int i = 0; i < classifyRenderer.ClassCount; i++)
                {
                    fillSymbol.Color = Convert2ESRIColor(lstColor[i]);
                    classifyRenderer.set_Break(i, lstBreakVal[i]);
                    classifyRenderer.set_Symbol(i, (ISymbol)fillSymbol);
                    classifyRenderer.set_Label(i, lstBreakLbl[i]);

                }
                if (VlaueFieldName.Length > 0 && VlaueFieldName.ToUpper() != "NONE")
                    classifyRenderer.ClassField = VlaueFieldName;

                if (NormalLizeFieldName.Length > 0 && NormalLizeFieldName.ToUpper()!= "NONE")
                    classifyRenderer.NormField = NormalLizeFieldName;

                (classifyRenderer as IHillShadeInfo).UseHillShade = bUserHillShade;
                if(bUserHillShade==true)
                {
                    (classifyRenderer as IHillShadeInfo).ZScale = zScale;
                }

                if(nodataColor!=null)
                    (classifyRenderer as IRasterDisplayProps).NoDataColor = nodataColor;

                rasterLayer.Renderer = rasterRenderer;
                rasterLayer.Draw(esriDrawPhase.esriDPGeography, m_MainMap.ActiveView.ScreenDisplay, null);
                m_MainMap.ActiveView.Refresh();
                m_MainTOC.Update();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return ;
            }
        }