Ejemplo n.º 1
0
        public static void classifyRender(IFeatureLayer featLayer, string classMethod, string fieldName, IColorRamp colorRamp, int count)
        {
            try
            {
                //值分级
                IBasicHistogram pBasicHis = new BasicTableHistogramClass();
                ITableHistogram pTabHis   = (ITableHistogram)pBasicHis;
                IClassifyGEN    pClassify = null;
                switch (classMethod)
                {
                case "等间距分级":
                    pClassify = new EqualIntervalClass();
                    break;

                case "自然断点分级":
                    pClassify = new NaturalBreaksClass();
                    break;
                }
                pTabHis.Field = fieldName;
                ILayer Layer = (ILayer)featLayer;
                ITable pTab  = (ITable)Layer;
                pTabHis.Table = pTab;
                object doubleArrVal, longArrFreq;
                pBasicHis.GetHistogram(out doubleArrVal, out longArrFreq);

                int nDes = count;
                pClassify.Classify(doubleArrVal, longArrFreq, ref nDes);
                double[] ClassNum;
                ClassNum = (double[])pClassify.ClassBreaks;
                int ClassCountResult         = ClassNum.GetUpperBound(0);
                IClassBreaksRenderer pRender = new ClassBreaksRendererClass();
                pRender.BreakCount = ClassCountResult;
                pRender.Field      = fieldName;
                ISimpleFillSymbol pSym;
                IColor            pColor;
                for (int j = 0; j < ClassCountResult; j++)
                {
                    pColor = colorRamp.get_Color(j * (colorRamp.Size - 1) / (ClassCountResult - 1));
                    pRender.set_Symbol(j, getISymbolByGeomType(featLayer, pColor));
                    pRender.set_Break(j, ClassNum[j + 1]);
                    pRender.set_Label(j, ClassNum[j].ToString("0.00") + " - " + ClassNum[j + 1].ToString("0.00"));
                }

                IGeoFeatureLayer pGeoLyr = (IGeoFeatureLayer)Layer;
                pGeoLyr.Renderer = (IFeatureRenderer)pRender;
            }
            catch {
                XtraMessageBox.Show("嗯,哪个,就一个值,别分级了好不好^_^");
            }
        }
Ejemplo n.º 2
0
 public void DeleteEntry(int index)
 {
     ClassNum.RemoveAt(index);
     ClassDept.RemoveAt(index);
 }
Ejemplo n.º 3
0
 public void AddEntry(string dept, string num)
 {
     ClassDept.Add(dept);
     ClassNum.Add(num);
 }
Ejemplo n.º 4
0
        public void LayerRender()
        {
            try
            {
                //值分级
                IBasicHistogram pBasicHis = new BasicTableHistogramClass();
                ITableHistogram pTabHis   = (ITableHistogram)pBasicHis;
                IClassifyGEN    pClassify = null;
                switch (classname)
                {
                case "自然断点分级":
                    pClassify = new NaturalBreaksClass();
                    break;

                case "等间距分级":
                    pClassify = new EqualIntervalClass();
                    break;
                }
                pTabHis.Field = FiledName;
                //IGeoFeatureLayer geolayer = (IGeoFeatureLayer)Layer;
                ITable pTab = (ITable)Layer;
                pTabHis.Table = pTab;
                object doubleArrVal, longArrFreq;
                pBasicHis.GetHistogram(out doubleArrVal, out longArrFreq);

                int nDes = count;
                pClassify.Classify(doubleArrVal, longArrFreq, ref nDes);
                object   classes = pClassify.ClassBreaks;
                double[] ClassNum;
                ClassNum = (double[])pClassify.ClassBreaks;
                int ClassCountResult         = ClassNum.GetUpperBound(0);
                IClassBreaksRenderer pRender = new ClassBreaksRendererClass();
                pRender.BreakCount = ClassCountResult;
                pRender.Field      = FiledName;
                ISimpleFillSymbol pSym;
                IColor            pColor;
                for (int j = 0; j < ClassCountResult; j++)
                {
                    pColor     = ramp.get_Color(j * (ramp.Size / ClassCountResult));
                    pSym       = new SimpleFillSymbolClass();
                    pSym.Color = pColor;
                    pRender.set_Symbol(j, (ISymbol)pSym);
                    pRender.set_Break(j, ClassNum[j + 1]);
                    if (ClassNum[j].ToString().Contains("."))
                    {
                        pRender.set_Label(j, ClassNum[j].ToString("0.000") + " - " + ClassNum[j + 1].ToString("0.000"));
                    }
                    else
                    {
                        pRender.set_Label(j, ClassNum[j].ToString() + " - " + ClassNum[j + 1].ToString());
                    }
                }

                IGeoFeatureLayer pGeoLyr = (IGeoFeatureLayer)Layer;
                pGeoLyr.Renderer = (IFeatureRenderer)pRender;
                axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                axtoccontrol.Update();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 5
0
        public ClassRender(AxMapControl pMapControl, String LayerName, int ClassCount, string Field)
        {
            IGeoFeatureLayer pGeolayer;

            ILayer pLayer;

            IActiveView pActiveView;

            IEnumLayer pEnumLayer;

            pEnumLayer = pMapControl.Map.get_Layers(null, true);

            if (pEnumLayer == null)
            {
                return;
            }

            pEnumLayer.Reset();

            int i = 0;

            int LayerIndex = -1;

            for (pLayer = pEnumLayer.Next(); pLayer != null; pLayer = pEnumLayer.Next())
            {
                i++;

                if (pLayer.Name == LayerName)
                {
                    LayerIndex = i - 1;

                    break;
                }
            }

            if (LayerIndex == -1)
            {
                MessageBox.Show("没有找到要渲染的图层");

                return;
            }

            pGeolayer = pMapControl.Map.get_Layer(LayerIndex) 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 = Field;

            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 = Field;

            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);

            new MainForm().axTOCControl1.Update();
        }