[转] AE之分级颜色专题图渲染

原文 AE之分级颜色专题图渲染

参考代码1

        private void 分级渲染ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            //值分级

            IBasicHistogram pBasicHis = new BasicTableHistogramClass();
            ITableHistogram pTabHis = (ITableHistogram)pBasicHis;
            pTabHis.Field = "w1";

            ITable pTab = (ITable)axMapControl1.get_Layer(0);
            pTabHis.Table = pTab;

            object doubleArrVal, longArrFreq;
            pBasicHis.GetHistogram(out doubleArrVal, out longArrFreq);

            IClassifyGEN pClassify = new EqualIntervalClass();  //NaturalBreaksClass

            int nDes = 5;

            pClassify.Classify(doubleArrVal, longArrFreq, ref nDes);

            object classes = pClassify.ClassBreaks;

            System.Array pArr = (System.Array)classes;

            //算法梯度颜色

            IAlgorithmicColorRamp pAlgoColorRamp = new AlgorithmicColorRampClass();
            pAlgoColorRamp.Size = pArr.Length;
            IRgbColor pFromColor = new RgbColorClass(), pToColor = new RgbColorClass();
            pFromColor.Red = 0;
            pFromColor.Green = 255;
            pFromColor.Blue = 0;
            pToColor.Red = 255;
            pToColor.Green = 0;
            pToColor.Blue = 255;

            pAlgoColorRamp.FromColor = pFromColor;
            pAlgoColorRamp.ToColor = pToColor;
            bool ok = true;
            pAlgoColorRamp.CreateRamp(out ok);

            //颜色梯度结束

            IClassBreaksRenderer pRender = new ClassBreaksRendererClass();
            pRender.BreakCount = pArr.Length;
            pRender.Field = "w1";
            ISimpleFillSymbol pSym;

            for (int i = 0; i < pArr.Length; i++)
            {

                pRender.set_Break(i, (double)pArr.GetValue(i));

                pSym = new SimpleFillSymbolClass();

                pSym.Color = pAlgoColorRamp.get_Color(i);

                pRender.set_Symbol(i, (ISymbol)pSym);

            }

            IGeoFeatureLayer pGeoLyr = (IGeoFeatureLayer)axMapControl1.get_Layer(0);
            pGeoLyr.Renderer = (IFeatureRenderer)pRender;

            axMapControl1.Refresh();
            axTOCControl1.Update();

        }

参考代码2

 private void 分层设色ToolStripMenuItem_Click(object sender, EventArgs e)
{

            //获取当前图层 ,并把它设置成IGeoFeatureLayer的实例
            IMap pMap = axMapControl1.Map;
            ILayer pLayer = pMap.get_Layer(0) as IFeatureLayer;
            IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
            IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;

            //获取图层上的feature
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
            IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
            IFeature pFeature = pFeatureCursor.NextFeature();

            //
            IFeatureRenderer PR=pGeoFeatureLayer.Renderer;
            //JoinData("县级区域", "DZGB", "sectioncode");   //join外部表
            // int DC ;
            int  desiredClasses = 5;
            string fieldName = "w1";
            int classesCount;
            double[] classes;
            string strOutput = "";
            bool ok;

            object dataFrequency;
            object dataValues;
            ITable pTable ;

            //IClassify pClassify;
            EqualIntervalClass pClassify;

            //IBasicHistogram pTableHistogram = new BasicTableHistogramClass();
            //IHistogram pTableHistogram = new BasicTableHistogramClass();
            ITableHistogram pTableHistogram = new BasicTableHistogramClass() as ITableHistogram;
            IBasicHistogram pHistogram;
            IClassBreaksRenderer pClassBreaksRenderer;
            IHsvColor pFromColor;
            IHsvColor pToColor;
            IAlgorithmicColorRamp pAlgorithmicColorRamp;
            IEnumColors pEnumColors;
            IColor pColor;
            ISimpleFillSymbol pSimpleFillSymbol;

            pLayer = (IFeatureLayer)axMapControl1.get_Layer(0);
            pGeoFeatureLayer = (IGeoFeatureLayer)pLayer;
            pTable = (ITable)pGeoFeatureLayer;
            pHistogram = (IBasicHistogram)pTableHistogram;

            // Get values and frequencies for the field
            pTableHistogram.Field = fieldName;
            pTableHistogram.Table = pTable;
            pHistogram.GetHistogram(out dataValues, out dataFrequency);

            // Put values and frequencies into an Equal Interval Classify Object
            pClassify = new EqualIntervalClass();

            //pClassify = new NaturalBreaksClass();
            pClassify.SetHistogramData(dataValues, dataFrequency);
            pClassify.Classify(dataValues, dataFrequency, ref desiredClasses);

            //pClassify.Classify(ref desiredClasses);
            classes = (double[])pClassify.ClassBreaks;
            classesCount = classes.Length;

            // Initialise a new Class Breaks renderer
            // Supply the number of Class Breaks and the field to perform. the class breaks on
            pClassBreaksRenderer = new ClassBreaksRendererClass();
            pClassBreaksRenderer.Field = fieldName;
            pClassBreaksRenderer.BreakCount = classesCount;
            pClassBreaksRenderer.SortClassesAscending = true;

            // Use algorithmic color ramp to generate an range of colors between YELLOW to RED
            // Initial color: YELLOW
            pFromColor = new HsvColorClass();
            pFromColor.Hue = 60;
            pFromColor.Saturation = 100;
            pFromColor.Value = 96;

            // Final color: RED
            pToColor = new HsvColorClass();
            pToColor.Hue = 0;
            pToColor.Saturation = 100;
            pToColor.Value = 96;
            // Set up HSV Color ramp to span from YELLOW to RED
            pAlgorithmicColorRamp = new AlgorithmicColorRampClass();
            pAlgorithmicColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
            pAlgorithmicColorRamp.FromColor = pFromColor;
            pAlgorithmicColorRamp.ToColor = pToColor;
            pAlgorithmicColorRamp.Size = classesCount;
            pAlgorithmicColorRamp.CreateRamp(out ok);

            pEnumColors = pAlgorithmicColorRamp.Colors;
            for (int index = 0; index < classesCount - 1; index++)
            {

                pColor = pEnumColors.Next();
                pSimpleFillSymbol = new SimpleFillSymbolClass();
                pSimpleFillSymbol.Color = pColor;
                pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                pClassBreaksRenderer.set_Symbol(index, (ISymbol)pSimpleFillSymbol);
                pClassBreaksRenderer.set_Break(index, classes[index + 1]);
                // Store each break value for user output
                strOutput += "-" + classes[index + 1] + "\n";

            }

            pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer;
            //this.axMapControl1.Refresh();
           /////////////////////////////////////////////////////////////////////////////////////////
           //////////////////////////////////////////////////////////////////////////////////////////

            //get the custom property from which is supposed to be the layer to be saved
            object customProperty = null;
            //IMapControl3 mapControl = null;
            customProperty = axMapControl1.CustomProperty;

            //ask the user to set a name for the new layer file
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Layer File|*.lyr|All Files|*.*";
            saveFileDialog.Title = "生成专题图";
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.FileName = System.IO.Path.Combine(saveFileDialog.InitialDirectory, pGeoFeatureLayer.Name + ".lyr");

            //get the layer name from the user
            DialogResult dr = saveFileDialog.ShowDialog();
            if (saveFileDialog.FileName != "" && dr == DialogResult.OK)
            {

                if (System.IO.File.Exists(saveFileDialog.FileName))
                {

                    //try to delete the existing file
                    System.IO.File.Delete(saveFileDialog.FileName);

                }

                //create a new LayerFile instance
                ILayerFile layerFile = new LayerFileClass();
                //create a new layer file
                layerFile.New(saveFileDialog.FileName);
                //attach the layer file with the actual layer
                layerFile.ReplaceContents((ILayer)pGeoFeatureLayer);
                //save the layer file
                layerFile.Save();

                //ask the user whether he‘d like to add the layer to the map
                if (DialogResult.Yes == MessageBox.Show("Would you like to add the layer to the map?", "Message", MessageBoxButtons.YesNo,MessageBoxIcon.Question))
                {
                    axMapControl1.AddLayerFromFile(saveFileDialog.FileName, 0);
                }
            }

            IActiveView pActiveView = axMapControl1.Map as IActiveView;
            pActiveView.Refresh();
            axTOCControl1.Update();
}

参考代码3

private void 等级专题图ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            // 获取当前图层,并把它设置成IGeoFeatureLayer的实例

            ILayer pLayer = axMapControl1.get_Layer(0);

            IFeatureLayer pFeatLayer = (IFeatureLayer)pLayer;

            IGeoFeatureLayer pGeoFeatLayer = (IGeoFeatureLayer)pLayer;

            IFeatureClass pFeatClass = pFeatLayer.FeatureClass;

            // We‘re going to retrieve frequency data from a population

            // field and then clasify this data

            ITable pTable = (ITable)pFeatClass;

            IBasicHistogram pBasicHistogram = new BasicTableHistogramClass();

            ITableHistogram pTableHistogram = (ITableHistogram)pBasicHistogram;

            // Get values and frequencies for the population field into a table histogram object

            string fieldName = "w1";

            pTableHistogram.Field = fieldName;

            pTableHistogram.Table = pTable;

            object dataValues;

            object dataFrequency;

            pBasicHistogram.GetHistogram(out dataValues, out dataFrequency);

            IClassifyGEN pClassifyGEN = new QuantileClass();

            int numClass = 3;

            pClassifyGEN.Classify(dataValues, dataFrequency, ref numClass);

            double[] classes = (double[])pClassifyGEN.ClassBreaks;

            long classesCount = long.Parse(classes.GetUpperBound(0).ToString());

            // Initialize a new class breaks renderer and supply the number of class breaks

            // and the field to perform the class breaks on

            IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass();

            pClassBreaksRenderer.Field = fieldName;

            pClassBreaksRenderer.MinimumBreak = classes[0];

            pClassBreaksRenderer.SortClassesAscending = true;

            // 设置着色对象的分级数目

            pClassBreaksRenderer.BreakCount = int.Parse(classesCount.ToString());

            // 创建并设置随机色谱

            IAlgorithmicColorRamp pAlgorithmicColorRamp = new AlgorithmicColorRampClass();

            pAlgorithmicColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;

            IEnumColors pEnumColors;

            IRgbColor pColor1 = new RgbColorClass();

            IRgbColor pColor2 = new RgbColorClass();

            pColor1.Red = 255;

            pColor1.Green = 210;

            pColor1.Blue = 210;

            pColor2.Red = 190;

            pColor2.Green = 0;

            pColor2.Blue = 170;

            pAlgorithmicColorRamp.FromColor = pColor1;

            pAlgorithmicColorRamp.ToColor = pColor2;

            pAlgorithmicColorRamp.Size = numClass;

            bool ok = true;

            pAlgorithmicColorRamp.CreateRamp(out ok);

            pEnumColors = pAlgorithmicColorRamp.Colors;

            pEnumColors.Reset();

            IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pClassBreaksRenderer;

            pUIProperties.ColorRamp = "Custom";

            ISimpleFillSymbol pSimpleMarkerSymbol = new SimpleFillSymbolClass();

            IColor pColor;

            int[] colors = new int[numClass];

            // be careful, indices are different for the different lists

            for (int breakIndex = 0; breakIndex < classesCount; breakIndex++)

            {

                pClassBreaksRenderer.set_Label(breakIndex, classes[breakIndex] + "-" + classes[breakIndex + 1]);

                pUIProperties.set_LowBreak(breakIndex, classes[breakIndex]);

                ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass();

                pColor = pEnumColors.Next();

                pFillSymbol.Color = pColor;

                colors[breakIndex] = pColor.RGB;

                pClassBreaksRenderer.set_Symbol(breakIndex, (ISymbol)pFillSymbol);

                pClassBreaksRenderer.set_Break(breakIndex, classes[breakIndex + 1]);

            }

            // 将等级图渲染对象与渲染图层挂钩

            pGeoFeatLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer;

            axMapControl1.ActiveView.Refresh();

            axTOCControl1.Update();

        }

参考代码4

 private void 等级图ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            //获取当前图层 ,并把它设置成IGeoFeatureLayer的实例

            IMap pMap = axMapControl1.Map;

            ILayer pLayer = pMap.get_Layer(0) as IFeatureLayer;

            IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;

            IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;

            //获取图层上的feature

            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;

            IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);

            IFeature pFeature = pFeatureCursor.NextFeature();

            //////////////////////////////////////////////////////////////////////

            //定义所需的接口对象和相关变量

            IClassBreaksUIProperties pUIProperties;

            object dataValues;

            object dataFrequency;

            //double[] cb;

            int breakIndex;

            long ClassesCount;

            int numClass;

            numClass = 10;

            double[] Classes;

            //////////////////////////////////////////////////////////////////////

            ITable pTable;

            pTable = pFeatureClass as ITable;

            IBasicHistogram pBasicHist = new BasicTableHistogramClass();

            ITableHistogram pTableHist;

            pTableHist = (ITableHistogram)pBasicHist;

            //Get values and frequencies for the population field into a table histogram object

            pTableHist.Field = "w1";

            pTableHist.Table = pTable;

            pBasicHist.GetHistogram(out dataValues, out dataFrequency);

            IClassifyGEN pClassifyGEN = new QuantileClass();

            pClassifyGEN.Classify(dataValues, dataFrequency, ref numClass);

            Classes = (double[])pClassifyGEN.ClassBreaks;

            ClassesCount = long.Parse(Classes.GetUpperBound(0).ToString());

            //Initialise a new class breaks renderer and supply the number of class breaks and the field to perform. the class breaks on.

            IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass();

            pClassBreaksRenderer.Field = "w1";

            //pClassBreaksRenderer.BreakCount = ClassesCount;

            pClassBreaksRenderer.MinimumBreak = Classes[0];

            pClassBreaksRenderer.SortClassesAscending = true;

            //设置着色对象的分级数目

            pClassBreaksRenderer.BreakCount = int.Parse(ClassesCount.ToString());

            //创建并设置随机色谱

            IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass();

            pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;

            IEnumColors pEnumColors;

            IRgbColor pColor1 = new RgbColorClass();

            IRgbColor pColor2 = new RgbColorClass();

            pColor1.Red = 255;

            pColor1.Green = 210;

            pColor1.Blue = 210;

            pColor2.Red = 190;

            pColor2.Green = 0;

            pColor2.Blue = 170;

            pColorRamp.FromColor = pColor1;

            pColorRamp.ToColor = pColor2;

            pColorRamp.Size = numClass;

            bool ok = true;

            //pColorRamp.CreateRamp(out ok);

             pColorRamp.CreateRamp(out ok);

            pEnumColors = pColorRamp.Colors;

            pEnumColors.Reset();// use this interface to set dialog properties

            pUIProperties = pClassBreaksRenderer as IClassBreaksUIProperties;

            pUIProperties.ColorRamp = "Custom";

            ISimpleFillSymbol pSimpleMarkerSymbol = new SimpleFillSymbolClass();

            IColor pColor;

            int[] colors = new int[numClass];

            // be careful, indices are different for the diff lists   

            for (breakIndex = 0; breakIndex < ClassesCount; breakIndex++)

            {

                pClassBreaksRenderer.set_Label(breakIndex, Classes[breakIndex] + " - " + Classes[breakIndex + 1]);

                pUIProperties.set_LowBreak(breakIndex, Classes[breakIndex]);

                pSimpleMarkerSymbol = new SimpleFillSymbolClass();

                pColor = pEnumColors.Next();

                pSimpleMarkerSymbol.Color = pColor;

                colors[breakIndex] = pColor.RGB;

                pClassBreaksRenderer.set_Symbol(breakIndex, (ISymbol)pSimpleMarkerSymbol);

                pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]);

            }

            //将等级图渲染对象与渲染图层挂钩

            pGeoFeatureLayer.Renderer = (IFeatureRenderer)pClassBreaksRenderer;

            //刷新地图和TOOCotrol

            IActiveView pActiveView = axMapControl1.Map as IActiveView;

            pActiveView.Refresh();

            axTOCControl1.Update();

        }

时间: 2024-10-21 20:51:24

[转] AE之分级颜色专题图渲染的相关文章

分级专题图制作

第一步:打开数据  第二歩:制作等级图 选择图层 第三歩:选择字段第四歩:设置条带第五步:生成评价第六歩:生成专题图 分级专题图制作

arcpy.mapping实战-专题图制图自动化

by 李远祥 最初对arcpy.mapping感兴趣是因为一次大规模的专题地图调整的需要,由于某某单位利用ArcEngine编写的专题图出图系统,出现了一些小问题,导致地图整饰元素的位置出现了误差.由于最终的生产任务已经到了尾声才发现一些问题,所以需要在出图系统之外使用ArcMap进行修改,这样针对上千幅成果文档进行修改,是个不小的工作量.后来决定使用arcpy.mapping,使用Python进行递归查询mxd文档,最终实现自动化修改和重新出图.虽然当时只是使用了很少的功能,基本上就是对整饰元

Supermap 组合单值专题图与标签专题图演示样例

效果图例如以下:单值专题图并显示每一个区域的相关文字信息 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc29uZ2hmdQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" > 代码: <!DOCTYPE> <html> <head> <meta http-equiv="Content-Type

Android Shader 颜色、图像渲染 paint.setXfermode

Shader Shader是一个基类,表示在绘制期间颜色的水平跨度 它的子类被嵌入在Paint中使用,调用paint.setShader(shader). 除Bitmap外的其他对象,使用该Paint进行绘制时.将从shader中获得颜色 Shader.TileMode 渲染模式 public enum TileMode { CLAMP (0), REPEAT (1), MIRROR (2); TileMode(int nativeInt) { this.nativeInt = nativeIn

Android Shader 颜色、图像渲染

Shader Shader是一个基类,表示在绘制期间颜色的水平跨度 它的子类被嵌入在Paint中使用,调用paint.setShader(shader). 除Bitmap外的其它对象,使用该Paint进行绘制时,将从shader中获得颜色 Shader.TileMode 渲染模式 public enum TileMode { CLAMP (0), REPEAT (1), MIRROR (2); TileMode(int nativeInt) { this.nativeInt = nativeIn

Supermap iclient 专题图制作,关联外表,并条件过滤

之前做的专题图只是关联外表,并没有根据属性条件过滤数据,网上也没有更好的示例程序,自己捣鼓了几次iserver搞崩溃了,以下是搞成功的关键代码留存备用. 效果图: //关联关系 var joinItem=new SuperMap.REST.JoinItem({ foreignTableName: "V_REGION_LAND", joinFilter: "BBS_PARCEL.CADASTRALNO = V_REGION_LAND.CADASTRALNO ", jo

Supermap 组合单值专题图与标签专题图示例

效果图如下:单值专题图并显示每个区域的相关文字信息 代码: <!DOCTYPE> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>单值专题图</title> <style type="text/css"> body{ margin:

【原】高光贴图参数放入颜色贴图的alpha通道中

今天美术想把高光贴图参数合成到Main贴图中,减少贴图数,挺好,知道省内存了. 于是简单改了改surface着色器. Shader "Custom/HighLightByAlphaPass" {    Properties {         _MainTex ("Base (RGBA A--HighLight)", 2D) = "white" {}         _MainColor("Diffuse",Color) =

基于色彩调和的专题图自动生成系统

position:static(静态定位) 当position属性定义为static时,可以将元素定义为静态位置,所谓静态位置就是各个元素在HTML文档流中应有的位置 podisition定位问题.所以当没有定义position属性时,并不说明该元素没有自己的位置,它会遵循默认显示为静态位置,在静态定位状态下无法通过坐标值(top,left,right,bottom)来改变它的位置. position:absolute(绝对定位) 当position属性定义为absolute时,元素会脱离文档流