コード例 #1
0
 private void chooseNumericField()                                       //选择数值型字段
 {
     fieldChoose(field =>
     {
         if (field.Type == esriFieldType.esriFieldTypeDouble || field.Type == esriFieldType.esriFieldTypeSingle || field.Type == esriFieldType.esriFieldTypeInteger ||
             field.Type == esriFieldType.esriFieldTypeOID || field.Type == esriFieldType.esriFieldTypeSmallInteger)
         {
             IBasicHistogram pBasicHis = new BasicTableHistogramClass();
             ITableHistogram pTabHis   = (ITableHistogram)pBasicHis;
             pTabHis.Field             = field.Name;
             ILayer Layer  = (ILayer)featureLayer;
             ITable pTab   = (ITable)Layer;
             pTabHis.Table = pTab;
             object doubleArrVal, longArrFreq;
             pBasicHis.GetHistogram(out doubleArrVal, out longArrFreq);
             double[] ArrVal = (double[])doubleArrVal;
             if (ArrVal.Length == 1)
             {
                 return(false);
             }
             else
             {
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     });
 }
コード例 #2
0
        private void drawLine()                                                 //在表中画出值的频率分布线
        {
            IBasicHistogram pBasicHis = new BasicTableHistogramClass();
            ITableHistogram pTabHis   = (ITableHistogram)pBasicHis;

            pTabHis.Field = comboBoxEdit1.Text;
            ILayer Layer = (ILayer)featureLayer;
            ITable pTab  = (ITable)Layer;

            pTabHis.Table = pTab;
            object doubleArrVal, longArrFreq;

            pBasicHis.GetHistogram(out doubleArrVal, out longArrFreq);

            double[]       ArrVal  = (double[])doubleArrVal;
            System.Int32[] ArrFreq = (System.Int32[])longArrFreq;
            if (ArrVal.Length < 50)
            {
                valueChooseInChart1.drawLine(ArrVal, ArrFreq, Convert.ToInt16(spinEdit1.Text));
            }
            else
            {
                valueChooseInChart1.drawline(ArrVal.Min(), ArrVal.Max(), Convert.ToInt16(spinEdit1.Text));
            }
        }
コード例 #3
0
ファイル: QueryTable.cs プロジェクト: mateo41/mapmaker
    public void calcFrequencies(ITable table)
    {
        IBasicHistogram basicHist = new BasicTableHistogramClass();
        ITableHistogram tableHist = (ITableHistogram)basicHist;
        tableHist.Table = table;
        tableHist.Field = "Measure";

        object uniqueValues;
        object valueCounts;

        basicHist.GetHistogram(out uniqueValues, out  valueCounts);
        m_histogramValues = (double[])uniqueValues;
        m_histogramCounts = (int[])valueCounts;
    }
コード例 #4
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("嗯,哪个,就一个值,别分级了好不好^_^");
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
0
ファイル: ClassRender.cs プロジェクト: xmter/learning_summary
        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();
        }
コード例 #7
0
        /// <summary>
        /// 分级色彩渲染
        /// </summary>
        /// <param name="pMapControl"></param>
        /// <param name="pFtLayer"></param>
        /// <param name="ClassCount"></param>
        /// <param name="pFieldName"></param>
        public static void ClassRender(IActiveView activeView, IFeatureLayer pFtLayer, int ClassCount, string pFieldName)

        {
            IGeoFeatureLayer pGeolayer;

            IActiveView pActiveView;

            pGeolayer = pFtLayer as IGeoFeatureLayer;


            //以下是为了统计和分类所需要的对象 ITable pTable;

            IClassifyGEN    pClassify;  //C\#要作为分类对象。
            ITableHistogram pTableHist; //相当于一个统计表
            IBasicHistogram pBasicHist; //这个对象有一个很重要的方法

            double[] ClassNum = new double[6];

            int ClassCountResult; //返回分类个数。 IHsvColor pFromColor;

            IRgbColor pToColor;   //用于构建另外一个颜色带对象。 IAlgorithmicColorRamp pAlgo;

            ITable pTable = pGeolayer as ITable;

            pBasicHist = new BasicTableHistogramClass();  //也可以实例化pTableHist
            pTableHist = pBasicHist as ITableHistogram;

            pTableHist.Table = pTable;
            pTableHist.Field = pFieldName;
            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;\
            ClassNum[0] = 10.0;
            ClassNum[1] = 50.0;
            ClassNum[2] = 100.0;
            ClassNum[3] = 1000.0;
            ClassNum[4] = 10000.0;
            ClassNum[5] = 80000.0;

            ClassCountResult = ClassNum.GetUpperBound(0);  //返回分级个数。
            IClassBreaksRenderer pClassBreak;

            pClassBreak                      = new ClassBreaksRendererClass();
            pClassBreak.Field                = pFieldName;
            pClassBreak.BreakCount           = ClassCountResult;
            pClassBreak.SortClassesAscending = true;

            IAlgorithmicColorRamp pAlgo = new AlgorithmicColorRampClass();

            pAlgo.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
            IColor pFromColor = GetRgbColor(255, 240, 240);

            pToColor        = GetRgbColor(255, 0, 0);
            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;

            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;

            activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
コード例 #8
0
        public static void Symbology_GraduatedColors(IFeatureLayer featureLayer, string fieldName, int numClasses, IMapControl2 mapControl, AxTOCControl tocControl)
        {
            // 获取渲染字段的值及其出现的频率
            ITable          pTable          = featureLayer as ITable;
            IBasicHistogram pBasicHistogram = new BasicTableHistogramClass()
            {
                Field = fieldName,
                Table = pTable
            };
            object dataFrequency, dataValue; // 频率和值

            pBasicHistogram.GetHistogram(out dataValue, out dataFrequency);
            // 数据分级
            IClassifyGEN pClassifyGEN = new EqualIntervalClass(); // 等间隔

            //IClassifyGEN pClassifyGEN = new GeometricalIntervalClass(); // 几何间隔
            //IClassifyGEN pClassifyGEN = new NaturalBreaksClass(); // 自然裂变
            //IClassifyGEN pClassifyGEN = new QuantileClass(); // 分位数
            //IClassifyGEN pClassifyGEN = new StandardDeviationClass(); // 标准偏差
            try { pClassifyGEN.Classify(dataValue, dataFrequency, numClasses); }
            catch { }
            double[]             Classes      = pClassifyGEN.ClassBreaks as double[];
            int                  ClassesCount = Classes.GetUpperBound(0);
            IClassBreaksRenderer pRenderer    = new ClassBreaksRendererClass()
            {
                // 分类字段 分类数目 升序
                Field                = fieldName,
                BreakCount           = ClassesCount,
                SortClassesAscending = true
            };
            // 生成颜色色带
            IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRamp()
            {
                FromColor = GetRgbColor(255, 200, 200),
                ToColor   = GetRgbColor(255, 0, 0),
                Size      = ClassesCount
            };
            bool bOk = false;

            pColorRamp.CreateRamp(out bOk);
            IEnumColors pColors = pColorRamp.Colors;

            // 逐一设置填充符号及每一分级的分级断点
            for (int index = 0; index < ClassesCount; index++)
            {
                IColor  pColor  = pColors.Next();
                ISymbol pSymbol = null;
                switch (featureLayer.FeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPoint:
                    pSymbol = new SimpleMarkerSymbolClass()
                    {
                        Color = pColor
                    };
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    pSymbol = new SimpleLineSymbolClass()
                    {
                        Color = pColor
                    };
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    pSymbol = new SimpleFillSymbolClass()
                    {
                        Color = pColor
                    };
                    break;
                }
                pRenderer.set_Symbol(index, pSymbol);           // 每级的符号
                pRenderer.set_Break(index, Classes[index + 1]); // 每级的断点
            }
            (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer;
            mapControl.Refresh();
            tocControl.Update();
        }
コード例 #9
0
        public ClassRender(AxMapControl pMapControl, IFeatureLayer pFtLayer, int ClassCount, string pFieldName)
        {
            IGeoFeatureLayer pGeolayer;

            IActiveView pActiveView;

            pGeolayer = pFtLayer 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 = pFieldName;

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

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