private void simpleButton1_Click(object sender, EventArgs e)            //渲染图层
 {
     if (comboBoxEdit2.Text == "分级渲染")
     {
         if (comboBoxEdit3.Text != "自定义分级")
         {
             Classifly.classifyRender(featureLayer, comboBoxEdit3.Text, comboBoxEdit1.Text,
                                      getRamp(), Convert.ToInt16(spinEdit1.Text));
         }
         else
         {
             Classifly.userRender(featureLayer, comboBoxEdit3.Text, comboBoxEdit1.Text,
                                  getRamp(), Convert.ToInt16(spinEdit1.Text), valueChooseInChart1.getValues());
         }
     }
     else if (comboBoxEdit2.Text == "圆大小渲染")
     {
         Classifly.ProportionalRenderer(featureLayer, comboBoxEdit1.Text,
                                        ColorToIColor(colorPickEdit3.Color), Convert.ToDouble(spinEdit2.Text));
     }
     else
     {
         Classifly.uniqueRender(featureLayer, comboBoxEdit1.Text);
     }
     axMapControl1.Refresh();
     axTOCControl1.Update();
 }
Beispiel #2
0
 private void simpleButton1_Click(object sender, EventArgs e)
 {
     if (comboBoxEdit2.Text == "分级渲染")
     {
         if (comboBoxEdit1.Text != "自定义分级")
         {
             Classifly.classifyRender(rasterLayer, comboBoxEdit1.Text,
                                      Convert.ToInt16(spinEdit1.Text), getRamp());
         }
         else
         {
             Console.WriteLine("自定义");
             Classifly.userRender(rasterLayer, getRamp(), Convert.ToInt32(spinEdit1.Text), valueChooseInChart1.getValues());
         }
     }
     else if (comboBoxEdit2.Text == "连续渲染")
     {
         Classifly.stretchRender(rasterLayer, getRamp());
     }
     else
     {
         Classifly.uniqueRender(rasterLayer);
     }
     axMapControl1.Refresh();
     axTOCControl1.Update();
 }
Beispiel #3
0
        public static void Symbology_Proportional(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl)
        {
            // 获取渲染字段统计值
            IStatisticsResults pStatResult = GetDataSataResults(featureLayer, fieldName);

            // 比例符号渲染
            if (pStatResult != null)
            {
                IFillSymbol pFillSymbol = new SimpleFillSymbolClass()
                {
                    Color = GetRgbColor(155, 255, 0)
                };
                ISymbol pMarkerSymbol = new SimpleMarkerSymbolClass()
                {
                    Style = esriSimpleMarkerStyle.esriSMSDiamond,
                    Size  = 3,
                    Color = GetRgbColor(255, 90, 0)
                };
                IProportionalSymbolRenderer pRenderer = new ProportionalSymbolRendererClass()
                {
                    ValueUnit            = esriUnits.esriUnknownUnits, // 渲染单位
                    Field                = fieldName,                  // 渲染字段
                    FlanneryCompensation = false,
                    MinDataValue         = pStatResult.Minimum,        // 最小值
                    MaxDataValue         = pStatResult.Maximum,        // 最大值
                    BackgroundSymbol     = pFillSymbol,                // 背景颜色
                    MinSymbol            = pMarkerSymbol,              // 最小渲染符号
                    LegendSymbolCount    = 5                           // TOC控件中的显示条目
                };
                pRenderer.CreateLegendSymbols();
                (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer;
                mapControl.Refresh();
                tocControl.Update();
            }
        }
Beispiel #4
0
        //退出程序
        public void ExitProgram(AxMapControl axMapControl1, AxTOCControl axTOCControl1)
        {
            DialogResult dialogResult = MessageBox.Show("保存文件?", "关闭文件", MessageBoxButtons.YesNoCancel);

            if (dialogResult == DialogResult.Yes)
            {
                SaveDocument(axMapControl1);
                mapDocument.Close();
                axMapControl1.ClearLayers();
                axMapControl1.Refresh();
                axTOCControl1.Update();
                Application.Exit();
            }
            if (dialogResult == DialogResult.No)
            {
                //mapDocument.Close();
                //axMapControl1.ClearLayers();
                //axMapControl1.Refresh();
                //axTOCControl1.Update();
                Application.Exit();
            }
            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }
        }
 private void btnRasterOK_Click(object sender, EventArgs e)
 {
     try
     {
         RasterRender render = new RasterRender();
         pListRamp = style.pListRamp;
         render.RasterClassify(rasterlayer, cmbClassifyMethod.SelectedItem.ToString(), Convert.ToInt32(cmbClassifyCount.SelectedItem), (IColorRamp)pListRamp[cmbSymClassify.SelectedIndex]);
         //axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
         axmapcontrol.Refresh();
         axtoccontrol.Update();
         axmapcontrol.Extent = rasterlayer.AreaOfInterest;
     }
     catch (Exception ec)
     {
         MessageBox.Show(ec.Message);
     }
 }
Beispiel #6
0
        private void btnRasterOK_Click(object sender, EventArgs e)
        {
            switch (tabControl1.SelectedIndex)
            {
            case 0:
                try
                {
                    IRasterStretchColorRampRenderer rasStreRen = new RasterStretchColorRampRendererClass();
                    IRasterRenderer rasRen = rasStreRen as IRasterRenderer;
                    rasRen.Raster = rasterlayer.Raster;
                    rasRen.Update();
                    rasStreRen.BandIndex = cmbBand.SelectedIndex;
                    pListRamp            = style.pListRamp;
                    rasStreRen.ColorRamp = (IColorRamp)pListRamp[cmbsymRaster.SelectedIndex];
                    rasRen.Update();
                    rasterlayer.Renderer = rasStreRen as IRasterRenderer;
                    IRasterStretch2 stretch = rasStreRen as IRasterStretch2;
                    stretch.BackgroundValue = 0;
                    stretch.Background      = true;
                    stretch.BackgroundColor = RasterRender.GET(255, 255, 255) as IColor;
                    axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                    axtoccontrol.Update();
                    axmapcontrol.Extent = rasterlayer.AreaOfInterest;
                    this.Close();
                }
                catch (Exception ec)
                {
                    MessageBox.Show(ec.Message);
                }
                break;

            case 1:
                RasterRender render = new RasterRender();
                pListRamp = style.pListRamp;
                render.RasterClassify(rasterlayer, cmbClassifyMethod.SelectedValue.ToString(), Convert.ToInt32(cmbClassifyCount.SelectedValue), (IColorRamp)pListRamp[cmbSymClassify.SelectedIndex]);
                axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                axtoccontrol.Update();
                axmapcontrol.Extent = rasterlayer.AreaOfInterest;
                break;
            }
        }
        private void ChangeRender2RasterStretchColorRampRender(IRasterLayer rasterLayer)
        {
            if (rasterlayer == null)
            {
                return;
            }

            //计算统计图
            IRasterBand band = GetBand(rasterLayer);

            if (band.Histogram == null)
            {
                band.ComputeStatsAndHist();
            }

            IRaster raster = rasterLayer.Raster;
            IRasterStretchColorRampRenderer rasterStretchColorRampRenderer = new RasterStretchColorRampRendererClass();
            IRasterRenderer rasterRenderer = rasterStretchColorRampRenderer as IRasterRenderer;

            rasterRenderer.Raster = raster;
            rasterRenderer.Update();

            //IAlgorithmicColorRamp algorithmicColorRamp = new AlgorithmicColorRampClass();
            //algorithmicColorRamp.Size = 255;
            //algorithmicColorRamp.FromColor = getRGBColor(255, 0, 0);
            //algorithmicColorRamp.ToColor = getRGBColor(0, 255, 0);
            //bool btrue;
            //algorithmicColorRamp.CreateRamp(out btrue);

            rasterStretchColorRampRenderer.BandIndex = cmbRasterBands.SelectedIndex;
            IColorRamp pColorRamp = (IColorRamp)EnumStyleItem[colorComboBox.SelectedIndex];

            rasterStretchColorRampRenderer.ColorRamp = pColorRamp;
            rasterRenderer.Update();
            rasterLayer.Renderer = rasterStretchColorRampRenderer as IRasterRenderer;

            axmapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            axtoccontrol.Update();
            axmapcontrol.Extent = rasterlayer.AreaOfInterest;
        }
Beispiel #8
0
 private void CloseFile()
 {
     cbxActiveMap.Items.Clear();
     cbxFeatureLayer.Items.Clear();
     cbxField.Items.Clear();
     districtList.Items.Clear();
     chkBoxLabel.IsChecked        = false;
     labelClrPicker.SelectedColor = null;
     rbtnBarCht.IsChecked         = false;
     rbtnPieCht.IsChecked         = false;
     m_map.ClearLayers();
     m_toc.Update();
     m_toolbar.Update();
     m_map.Refresh();
 }
Beispiel #9
0
        // 比例符号化
        public static void Proportional(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl)
        {
            ITable  pTable  = featureLayer as ITable;
            ICursor pCursor = pTable.Search(null, false);
            // 利用IDataStatistics和IStatisticsResults获取渲染字段的统计值(最大值 and 最小值)
            IDataStatistics pDataStat = new DataStatisticsClass()
            {
                Cursor = pCursor, Field = fieldName
            };
            IStatisticsResults pStatResult = pDataStat.Statistics;

            if (pStatResult != null)
            {
                // 设置渲染背景色
                IFillSymbol pFillSymbol = new SimpleFillSymbolClass()
                {
                    Color = GetRgbColor(155, 255, 0)
                };
                ISimpleMarkerSymbol pSimpleMaskerSymbol = new SimpleMarkerSymbolClass()
                {
                    Style = esriSimpleMarkerStyle.esriSMSDiamond,
                    Size  = 3,
                    Color = GetRgbColor(255, 90, 0)
                };
                IProportionalSymbolRenderer pRenderer = new ProportionalSymbolRendererClass()
                {
                    ValueUnit            = esriUnits.esriUnknownUnits,     // 渲染单位
                    Field                = fieldName,                      // 渲染字段
                    FlanneryCompensation = false,                          // 是否使用Flannery补偿
                    MinDataValue         = pStatResult.Minimum,            // 获取渲染字段的最小值
                    MaxDataValue         = pStatResult.Maximum,            // 获取渲染字段的最大值
                    BackgroundSymbol     = pFillSymbol,
                    MinSymbol            = pSimpleMaskerSymbol as ISymbol, // 渲染字段最小值的渲染符号
                    LegendSymbolCount    = 5                               // 设置TOC控件中的显示条目
                };
                pRenderer.CreateLegendSymbols();                           // 生成图例
                (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer;
            }
            mapControl.Refresh();
            tocControl.Update();
        }
Beispiel #10
0
 public static void UpdateTOCControl()
 {
     m_tocControl.Update();
 }
        //单一或多字段符号化
        private void UniqueValueRenderer(IFeatureLayer pFeatLyr, string[] sFieldName)
        {
            IFeatureLayer pFLayer = pLayer as IFeatureLayer;

            IGeoFeatureLayer geoLayer = pLayer as IGeoFeatureLayer;

            IFeatureClass fcls = pFLayer.FeatureClass;

            IQueryFilter pQueryFilter = new QueryFilterClass();

            IFeatureCursor fCursor = fcls.Search(pQueryFilter, false);

            IRandomColorRamp rx = new RandomColorRampClass();

            rx.MinSaturation = 15;

            rx.MaxSaturation = 30;

            rx.MinValue = 85;

            rx.MaxValue = 100;

            rx.StartHue = 0;

            rx.EndHue = 360;

            rx.Size = 100;

            bool ok;;

            rx.CreateRamp(out ok);

            IEnumColors RColors = rx.Colors;

            RColors.Reset();

            IUniqueValueRenderer pRender = new UniqueValueRendererClass();

            pRender.FieldCount = 1;

            pRender.set_Field(0, sFieldName[0]);

            IFeature pFeat = fCursor.NextFeature();

            int index = pFeat.Fields.FindField(sFieldName[0]);

            while (pFeat != null)

            {
                ISimpleFillSymbol symd = new SimpleFillSymbolClass();

                symd.Style = esriSimpleFillStyle.esriSFSSolid;

                symd.Outline.Width = 1;

                symd.Color = RColors.Next();

                string valuestr = pFeat.get_Value(index).ToString();

                pRender.AddValue(valuestr, valuestr, symd as ISymbol);

                pFeat = fCursor.NextFeature();
            }

            geoLayer.Renderer = pRender as IFeatureRenderer;
            //刷新地图和TOOCotrol
            IActiveView pActiveView = _MapControl.Map as IActiveView;

            pActiveView.Refresh();
            axTOCControl1.Update();
        }
Beispiel #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (cbLayer.Text == null || symbolizationWay == null)
            {
                MessageBox.Show("需要先选择图层和方法哦!");
                return;
            }
            ILayer pLayer = getLayersByName(cbLayer.Text);

            switch (symbolizationWay)
            {
            case "简单着色":

                if (type == CURRENT_LAYER_POLYGON)
                {
                    simpleDye(pLayer);
                }
                else if (type == CURRENT_LAYER_LINE)
                {
                    lineSimpleDye(pLayer);
                }
                break;

            case "分级着色":
                if (type == CURRENT_LAYER_POLYGON)
                {
                    polygonClassificationDye(pLayer);
                }
                else if (type == CURRENT_LAYER_LINE)
                {
                    polygonClassificationDye(pLayer);
                }
                break;

            case "唯一值着色":
                if (type == CURRENT_LAYER_POLYGON)
                {
                    polygonUniqueDye(pLayer);
                }
                else if (type == CURRENT_LAYER_LINE)
                {
                    polygonUniqueDye(pLayer);
                }
                break;

            case "质量图着色":
                if (type == CURRENT_LAYER_POLYGON)
                {
                    polygonQualityDye(pLayer);
                }
                else if (type == CURRENT_LAYER_LINE)
                {
                    polygonQualityDye(pLayer);
                }
                break;

            case "点密度":
                try
                {
                    int intRendererDensity = int.Parse(RendererDensity.Text);
                    DotDensity(pLayer as IFeatureLayer, cbField1.Text, intRendererDensity);
                }
                catch {
                }
                break;

            default:
                break;
            }
            axToccontrol1.Update();
        }
Beispiel #13
0
 //在OnviewRfeshed事件下使用(联动)
 public static void Use_OnViewRefreshed(AxTOCControl toccControl, AxMapControl mapControl, AxPageLayoutControl axPageLayoutControl)
 {
     toccControl.Update();
     OperateFile.CopyAndOverwriteMap(mapControl, axPageLayoutControl);
 }
        // 唯一值符号化
        public static void UniqueValueRenderer(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl)
        {
            ITable pTable = featureLayer as ITable;
            IUniqueValueRenderer pRenderer = new UniqueValueRendererClass();

            pRenderer.FieldCount = 1;          // 设置唯一值符号化的关键字段为一个
            pRenderer.set_Field(0, fieldName); // 设置唯一值符号化的第一个关键字段
            IRandomColorRamp pColorRamp = new RandomColorRampClass()
            {
                StartHue      = 0,
                MinValue      = 0,
                MinSaturation = 0,
                EndHue        = 100,
                MaxValue      = 100,
                MaxSaturation = 100
            };

            // 根据渲染字段的值的个数,设置一组随机颜色
            pColorRamp.Size = featureLayer.FeatureClass.FeatureCount(new QueryFilterClass());
            bool bSuccess = false;

            pColorRamp.CreateRamp(out bSuccess);
            IEnumColors pEnumColors      = pColorRamp.Colors;
            IColor      pNextUniqueColor = null;
            // 查询字段的值
            IQueryFilter pQueryFilter = new QueryFilterClass();

            pQueryFilter.AddField(fieldName);
            int        fieldNumber    = pTable.FindField(fieldName); // 获取渲染字段索引
            ICursor    pCursor        = pTable.Search(pQueryFilter, true);
            IRow       pNextRow       = pCursor.NextRow();
            object     codeValue      = null;
            IRowBuffer pNextRowBuffer = null;

            while (pNextRow != null)
            {
                pNextRowBuffer = pNextRow as IRowBuffer;
                // 获取渲染字段的每一个值
                codeValue        = pNextRowBuffer.get_Value(fieldNumber);
                pNextUniqueColor = pEnumColors.Next();
                if (pNextUniqueColor == null)
                {
                    pEnumColors.Reset();
                    pNextUniqueColor = pEnumColors.Next();
                }
                ISymbol pSymbol = null;
                switch (featureLayer.FeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPolygon:
                    pSymbol = new SimpleFillSymbolClass()
                    {
                        Color = pNextUniqueColor
                    };
                    break;

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

                case esriGeometryType.esriGeometryPoint:
                    pSymbol = new SimpleMarkerSymbolClass()
                    {
                        Color = pNextUniqueColor
                    };
                    break;
                }
                pRenderer.AddValue(codeValue.ToString(), "", pSymbol);
                pNextRow = pCursor.NextRow();
            }
            (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer;
            mapControl.Refresh();
            tocControl.Update();
        }
Beispiel #15
0
        // 唯一值符号化
        public static void Symbology_UniqueValue(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl)
        {
            IUniqueValueRenderer pRenderer = new UniqueValueRendererClass()
            {
                FieldCount = 1
            };
            // 随机色带
            IColorRamp pColorRamp = new RandomColorRampClass()
            {
                StartHue = 0, MinSaturation = 0, MinValue = 0,
                EndHue   = 360, MaxSaturation = 100, MaxValue = 100,
                Size     = featureLayer.FeatureClass.FeatureCount(new QueryFilterClass())
            };
            bool bOk = false;

            pColorRamp.CreateRamp(out bOk);
            IEnumColors  pColors      = pColorRamp.Colors;
            ITable       pTable       = featureLayer as ITable;
            int          fieldIndex   = pTable.FindField(fieldName);
            IQueryFilter pQueryFilter = new QueryFilterClass();

            pQueryFilter.AddField(fieldName);
            ICursor pCursor = pTable.Search(pQueryFilter, true);
            IRow    pRow    = pCursor.NextRow();

            while (pRow != null)
            {
                IRowBuffer pRowBuffer = pRow as IRowBuffer;
                string     value      = pRowBuffer.get_Value(fieldIndex).ToString();
                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.AddValue(value, "", pSymbol);
                pRow = pCursor.NextRow();
            }
            (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer;
            mapControl.Refresh();
            tocControl.Update();
        }
Beispiel #16
0
        // 分级色彩符号化
        public static void GraduatedColors(IFeatureLayer featureLayer, string fieldName, int numClasses, IMapControl2 mapControl, AxTOCControl tocControl)
        {
            object          dataFrequency;
            object          dataValue;
            int             breakIndex;
            ITable          pTable          = featureLayer.FeatureClass as ITable;
            ITableHistogram pTableHistogram = new BasicTableHistogramClass()
            {
                Field = fieldName, Table = pTable
            };
            IBasicHistogram pBasicHistogram = (IBasicHistogram)pTableHistogram;

            // 获取渲染字段的值及其出现的频率
            pBasicHistogram.GetHistogram(out dataValue, out dataFrequency);
            IClassifyGEN pClassifyGEN = new EqualIntervalClass();

            try { pClassifyGEN.Classify(dataValue, dataFrequency, ref numClasses); }
            catch { }
            // 返回一个数组
            double[]             Classes      = pClassifyGEN.ClassBreaks as double[];
            int                  ClassesCount = Classes.GetUpperBound(0);
            IClassBreaksRenderer pRenderer    = new ClassBreaksRendererClass()
            {
                // 分级字段 分级数目 分级后的图例是否按升级顺序排序
                Field = fieldName, BreakCount = ClassesCount, SortClassesAscending = true
            };
            // 设置分级说色所需颜色带的起止颜色
            //IHsvColor pFromColor = GetHsvColor(0, 50, 96);
            //IHsvColor pToColor = GetHsvColor(80, 100, 96);
            IRgbColor pFromColor = GetRgbColor(255, 200, 200);
            IRgbColor pToColor   = GetRgbColor(255, 0, 0);
            // 生成颜色带对象
            IAlgorithmicColorRamp pColorRamp = CreateColorRamp(pFromColor, pToColor, ClassesCount);
            // 获取色带颜色集
            IEnumColors pEnumColors = pColorRamp.Colors;

            // 逐一设置填充符号及每一分级的分级断点
            for (breakIndex = 0; breakIndex < ClassesCount; breakIndex++)
            {
                IColor  pColor  = pEnumColors.Next();
                ISymbol pSymbol = null;
                switch (featureLayer.FeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPolygon:
                    pSymbol = new SimpleFillSymbolClass()
                    {
                        Color = pColor, Style = esriSimpleFillStyle.esriSFSSolid
                    };
                    break;

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

                case esriGeometryType.esriGeometryPoint:
                    pSymbol = new SimpleMarkerSymbolClass()
                    {
                        Color = pColor
                    };
                    break;
                }
                // 设置填充符号
                pRenderer.set_Symbol(breakIndex, pSymbol);
                // 设置每一级的分级断点
                pRenderer.set_Break(breakIndex, Classes[breakIndex + 1]);
            }
            (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer;
            mapControl.Refresh();
            tocControl.Update();
        }
Beispiel #17
0
        void ClassifyColor()
        {
            IGeoFeatureLayer geoFeatureLayer = mapControl.Map.get_Layer(17) as IGeoFeatureLayer;
            string           a = geoFeatureLayer.Name;
            object           dataFrequency, dataValues;


            ITableHistogram tableHistogram = new BasicTableHistogramClass();
            IBasicHistogram basicHistogram = (IBasicHistogram)tableHistogram;

            tableHistogram.Field = cmbSelField.Text;
            tableHistogram.Table = geoFeatureLayer.FeatureClass as ITable;



            basicHistogram.GetHistogram(out dataValues, out dataFrequency);
            IClassifyGEN classifyGEN = new EqualIntervalClass();

            classifyGEN.Classify(dataValues, dataFrequency, Convert.ToInt32(cmbnumclasses.Text));


            double[]             classes             = classifyGEN.ClassBreaks as double[];
            int                  classesCount        = classes.GetUpperBound(0);
            IClassBreaksRenderer classBreaksRenderer = new ClassBreaksRendererClass();



            classBreaksRenderer.Field                = cmbSelField.Text;
            classBreaksRenderer.BreakCount           = classesCount;
            classBreaksRenderer.SortClassesAscending = true;



            IHsvColor fromColor = new HsvColorClass();

            fromColor.Hue   = 0; fromColor.Saturation = 50;
            fromColor.Value = 96;
            IHsvColor toColor = new HsvColorClass();

            toColor.Hue        = 80;
            toColor.Saturation = 100;
            toColor.Value      = 96;
            bool ok;



            //产生色带
            IAlgorithmicColorRamp algorithmicCR = new AlgorithmicColorRampClass();

            algorithmicCR.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
            algorithmicCR.FromColor = fromColor;
            algorithmicCR.ToColor   = toColor;
            algorithmicCR.Size      = classesCount;
            algorithmicCR.CreateRamp(out ok);



            //获得颜色
            IEnumColors enumColors = algorithmicCR.Colors;

            for (int breakIndex = 0; breakIndex <= classesCount - 1; breakIndex++)
            {
                IColor            color      = enumColors.Next();
                ISimpleFillSymbol simpleFill = new SimpleFillSymbolClass();
                simpleFill.Color = color;
                simpleFill.Style = esriSimpleFillStyle.esriSFSSolid;
                classBreaksRenderer.set_Symbol(breakIndex, (ISymbol)simpleFill);
                classBreaksRenderer.set_Break(breakIndex, classes[breakIndex + 1]);
            }

            geoFeatureLayer.Renderer = (IFeatureRenderer)classBreaksRenderer;
            mapControl.Refresh();
            mapControl.ActiveView.Refresh();


            tocControl.Update();
        }
Beispiel #18
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();
        }