Exemplo n.º 1
0
        //新地科学分类方法 [没有使用]
        public double[] getDivEquestStringArray2(int breakNum)
        {
            List <double> DivItemList = new List <double>();

            if (breakNum != 0)
            {
                for (int ib = 0; ib < this.RasterLayerClass.BandCount; ib++)
                {
                    IUniqueValues uv = new UniqueValuesClass();

                    IRasterCalcUniqueValues rcuv = new RasterCalcUniqueValuesClass();
                    rcuv.AddFromRaster(this.RasterLayerClass.Raster, ib, uv);

                    object valueArray = null, freq = null;
                    ;
                    IClassify classify = null;


                    uv.GetHistogram(out valueArray, out freq);

                    //--
                    EqualIntervalClass eq = new EqualIntervalClass();
                    eq.Classify(valueArray, freq, ref breakNum);
                    classify = (IClassify)eq;
                    //object o = classify.ClassBreaks;
                    ////--
                    //Quantile qc = new QuantileClass();
                    //qc.Classify(valueArray, freq, ref breakNum);
                    //classify = (IClassify)qc;
                    //o = classify.ClassBreaks;
                    ////--
                    //NaturalBreaksClass nb = new NaturalBreaksClass();
                    //nb.Classify(valueArray, freq, ref breakNum);
                    //classify = nb as IClassify;
                    //o = classify.ClassBreaks;
                    ////--
                    ////DefinedIntervalClass di = new DefinedIntervalClass();
                    ////di.IntervalRange = this.m_classBreaksParam.Interval;
                    ////di.Classify(valueArray, freq, ref breakNum);
                    ////--
                    ////StandardDeviationClass sd = new StandardDeviationClass();
                    ////IStatisticsResults stat = histogram as IStatisticsResults;
                    ////classify = sd as IClassify;
                    ////classify.SetHistogramData(valueArray, freq);
                    ////IDeviationInterval di = sd as IDeviationInterval;
                    ////di.DeviationInterval = 1;
                    ////di.Mean = stat.Mean;
                    ////di.StandardDev = stat.StandardDeviation;
                    ////classify.Classify(ref breakNum);
                    ////--

                    object       o          = classify.ClassBreaks;
                    System.Array breakArray = o as System.Array;

                    for (int i = breakArray.Length - 1; i >= 0; i--)
                    {
                        DivItemList.Add(double.Parse(breakArray.GetValue(i).ToString()));
                    }
                }
            }
            return(DivItemList.ToArray());
        }
Exemplo n.º 2
0
        private void btRender_Click(object sender, EventArgs e)
        {
            int number = 0;

            if (cbColorRamp.SelectedIndex == -1)
            {
                if (lang == Language.Chinese)
                {
                    MessageBox.Show("请先选择一种色带");
                }
                else if (lang == Language.English)
                {
                    MessageBox.Show("Please choose a color ribbon first");
                }
                return;
            }
            try
            {
                number = int.Parse(txtNumber.Text);
                if (number <= 1)
                {
                    if (lang == Language.Chinese)
                    {
                        MessageBox.Show("类别数量只能为>1的正整数");
                    }
                    else if (lang == Language.English)
                    {
                        MessageBox.Show("The class number can only be a positive integer of >1");
                    }
                }
            }
            catch
            {
                if (lang == Language.Chinese)
                {
                    MessageBox.Show("类别数量只能为整数");
                }
                else if (lang == Language.English)
                {
                    MessageBox.Show("The class number can only be an integer");
                }
            }
            IRasterClassifyColorRampRenderer pRasterClassifyRenderer = new RasterClassifyColorRampRendererClass();
            IRasterRenderer          pRasterRenderer = pRasterClassifyRenderer as IRasterRenderer;
            IUniqueValues            uniVal          = new UniqueValuesClass();
            IRasterCalcUniqueValues2 calValues       = new RasterCalcUniqueValuesClass();

            calValues.MaxUniqueValueCount = 10000000;
            calValues.AddFromRaster(rasterLayer.Raster, cbSelectedBand.SelectedIndex, uniVal);
            object vValues, vFrequences;

            uniVal.GetHistogram(out vValues, out vFrequences);
            double[] doubleArray = (double[])vValues;
            int[]    longArray   = (int[])vFrequences;
            int      order       = SortTool.CheckInOrder(doubleArray, doubleArray.Length);

            if (order == 0)
            {
                SortTool.QuickSort3(doubleArray, 0, doubleArray.Length - 1, longArray);
            }
            else if (order == -1)
            {
                SortTool.Reverse(doubleArray, doubleArray.Length, longArray);
            }
            IClassifyGEN classify = GetMethod(cbMethod.Text);

            classify.Classify((double[])vValues, (int[])vFrequences, ref number);
            double[] classes = classify.ClassBreaks as double[];

            pRasterRenderer.Raster             = rasterLayer.Raster;
            pRasterClassifyRenderer.ClassCount = number;
            for (int i = 0; i < classes.Length; i++)
            {
                pRasterClassifyRenderer.set_Break(i, classes[i]);
            }
            pRasterRenderer.Update();

            IStyleGalleryItem galleryItem = symbol.GetItem(cbColorRamp.SelectedIndex);
            IColorRamp        colorRamp   = galleryItem.Item as IColorRamp;
            IFillSymbol       fill        = new SimpleFillSymbolClass() as IFillSymbol;
            int increase = colorRamp.Size / (number - 1);

            for (int i = 0; i < pRasterClassifyRenderer.ClassCount - 1; i++)
            {
                fill.Color = colorRamp.get_Color(i * increase);
                pRasterClassifyRenderer.set_Symbol(i, fill as ISymbol);
                pRasterClassifyRenderer.set_Label(i, pRasterClassifyRenderer.get_Break(i).ToString() + "-" + pRasterClassifyRenderer.get_Break(i + 1).ToString());
            }
            fill.Color = colorRamp.get_Color(colorRamp.Size - 1);
            pRasterClassifyRenderer.set_Symbol(pRasterClassifyRenderer.ClassCount - 1, fill as ISymbol);
            pRasterClassifyRenderer.set_Label(pRasterClassifyRenderer.ClassCount - 1, pRasterClassifyRenderer.get_Break(pRasterClassifyRenderer.ClassCount - 1).ToString() + "-" + pRasterClassifyRenderer.get_Break(pRasterClassifyRenderer.ClassCount).ToString());
            rasterLayer.Renderer = pRasterRenderer;
            succeed = true;
            this.Close();
        }