コード例 #1
0
        //.................................................
        //.................................................
        //.................................................
        private void AssignColorRamp(string fieldname, List <RiskRankingRange> pRiskRankingRanges)
        {
            // Get Statistics Values for the Selected Field
            GetRankingStatistics(fieldname);
            if (_minriskvalue >= _maxriskvalue)
            {
                return;
            }
            if (pRiskRankingRanges.Count == 0)
            {
                return;
            }
            if (m_styleGalleryItem == null)
            {
                return;
            }
            if (m_featureLayer == null)
            {
                return;
            }
            m_classBreaksRenderer.Field        = fieldname;
            m_classBreaksRenderer.BreakCount   = pRiskRankingRanges.Count;
            m_classBreaksRenderer.MinimumBreak = 0;

            //Calculate the class interval by a simple mean value
            double interval = (_maxriskvalue - _minriskvalue) / pRiskRankingRanges.Count;

            //Get the color ramp
            IColorRamp colorRamp = (IColorRamp)m_styleGalleryItem.Item;

            //Set the size of the color ramp and recreate it
            colorRamp.Size = Convert.ToInt32(pRiskRankingRanges.Count);
            bool createRamp;

            colorRamp.CreateRamp(out createRamp);

            //Get the enumeration of colors from the color ramp
            IEnumColors enumColors = colorRamp.Colors;

            enumColors.Reset();
            double currentBreak = m_classBreaksRenderer.MinimumBreak;

            ISimpleLineSymbol simpleLineSymbol;

            //Loop through each class break
            for (int i = 0; i <= pRiskRankingRanges.Count - 1; i++)
            {
                //Set class break
                m_classBreaksRenderer.set_Break(i, currentBreak);
                //Create simple fill symbol and set color
                simpleLineSymbol       = new SimpleLineSymbolClass();
                simpleLineSymbol.Color = enumColors.Next();
                //Add symbol to renderer
                m_classBreaksRenderer.set_Symbol(i, (ISymbol)simpleLineSymbol);
                currentBreak += interval;
            }
        }
コード例 #2
0
ファイル: Datamanagement.cs プロジェクト: gistop/aegis
        void ClassBreaksRenderer(IFeatureLayer featureLayer)
        {
            IClassBreaksRenderer classBreaksRenderer = new ClassBreaksRenderer();
            classBreaksRenderer.Field = "AREA";
            // 必须设置分类数量。
            classBreaksRenderer.BreakCount = 4;
            classBreaksRenderer.set_Break(0, 744366000);
            classBreaksRenderer.set_Break(1, 2049800000);
            classBreaksRenderer.set_Break(2, 3801580000);

            // 设置填充样式。
            IFillSymbol fillSymbol = new SimpleFillSymbol();
            fillSymbol.Color = new RgbColor() { Red = 255, Green = 0, Blue = 0 };
            classBreaksRenderer.set_Symbol(0, (ISymbol)fillSymbol);
            fillSymbol = new SimpleFillSymbol();
            fillSymbol.Color = new RgbColor() { Red = 0, Green = 255, Blue = 0 };
            classBreaksRenderer.set_Symbol(1, (ISymbol)fillSymbol);
            fillSymbol = new SimpleFillSymbol();
            fillSymbol.Color = new RgbColor() { Red = 0, Green = 0, Blue = 255 };
            classBreaksRenderer.set_Symbol(2, (ISymbol)fillSymbol);

            // 图层设置渲染。
            var featureRenderer = (IFeatureRenderer)classBreaksRenderer;
            var geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
            geoFeatureLayer.Renderer = featureRenderer;
        }
コード例 #3
0
        public void ApplyClsssBreaks(IGeoFeatureLayer geoLayer, string aFieldName, long numBreaks)
        {
            //Create a Table from the geofeature layer
            ITable table = geoLayer as ITable;
            //ITableHistogram tableHistogram=new TableHistogram(); that is error but canbe coded by following
            TableHistogram  tableHistogram2 = new TableHistogram();
            ITableHistogram tableHistogram  = tableHistogram2 as ITableHistogram;

            tableHistogram.Table = table;
            tableHistogram.Field = aFieldName;
            IHistogram histogram = tableHistogram as IHistogram;
            object     vValues;
            object     vFregs;

            //先统计每个值和各个值出现的次数
            histogram.GetHistogram(out vValues, out vFregs);

            //Classify the data
            IClassifyGEN classifyGEN = new EqualInterval();
            int          intBreaks   = Convert.ToInt32(numBreaks);

            classifyGEN.Classify(vValues, vFregs, ref intBreaks);

            double[] vBreaks = (double[])classifyGEN.ClassBreaks;
            //books
            int classCount = vBreaks.GetUpperBound(0);
            //Create the ClassBreaksRenderer
            IClassBreaksRenderer classBreaksRenderer = new ClassBreaksRenderer();

            //assigh a field as breaked
            classBreaksRenderer.Field = aFieldName;
            //passed as a string to the sub routine
            //classBreaksRenderer.BreakCount =classCount;
            classBreaksRenderer.BreakCount           = (int)(numBreaks);
            classBreaksRenderer.SortClassesAscending = false;


            IRgbColor fromColor = new RgbColor();

            fromColor.UseWindowsDithering = true;
            fromColor.RGB = Information.RGB(0, 0, 255);
            IRgbColor toColor = new RgbColor();

            toColor.UseWindowsDithering = true;
            toColor.RGB = Information.RGB(255, 0, 0);
            //Set up the fill symbol
            ISymbol pSym;
            //ISimpleFillSymbol sym = new SimpleFillSymbol();
            IColor fillColor;

            MessageBox.Show("vBreaks.Length: " + vBreaks.Length.ToString());

            IEnumColors colors = GetColors(fromColor.RGB, toColor.RGB, numBreaks);

            for (int i = 0; i <= (vBreaks.Length - 2); i++)
            {
                fillColor = colors.Next();
                //code by jin
                if (geoLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                {
                    ISimpleFillSymbol sym = new SimpleFillSymbol();
                    sym.Color = fillColor;
                    pSym      = sym as ISymbol;
                }
                else if (geoLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    ISimpleLineSymbol sym = new SimpleLineSymbol();
                    sym.Color = fillColor;
                    pSym      = sym as ISymbol;
                }
                else
                {
                    ISimpleMarkerSymbol sym = new SimpleMarkerSymbol();
                    sym.Color = fillColor;
                    pSym      = sym as ISymbol;
                }
                classBreaksRenderer.set_Break(i, vBreaks[i + 1]);
                classBreaksRenderer.set_Symbol(i, pSym);
                geoLayer.Renderer = classBreaksRenderer as IFeatureRenderer;
                axMapControl1.ActiveView.Refresh();
                axTOCControl1.Update();
            }
        }