【GIS】点图层符号的方向和大小

方向:根据属性字段设置点图层中每个要素的符号方向和大小,

1 所有要素使用同一种符号---简单渲染

在图层属性---符号系统---单一符号中进行设置,首先设置符号,在后面的【高级】选项按钮中分别设置【旋转】和【大小】

【旋转】下拉框中选择对应字段,以及旋转方式,确定即可

【大小】下拉框中选择对应符号大小的字段,确认即可

 

2 要素根据字段值得不同采用不同的符号---使用唯一值渲染

图层属性中设置唯一值渲染,根据字段值得不同选择不同的符号,并在【高级】选项中设置【旋转】和【大小】,方法同上

 显示效果如下:

 

 

ArcEngine提供了相应的接口进行设置,

IRotationRenderer设置旋转参数

ISizeRenderer设置大小参数

比如

  IRotationRenderer pRotationRender = pSimRender as IRotationRenderer;
  pRotationRender.RotationField = "ANGEL";
  pRotationRender.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;

  ISizeRenderer pSizeRender = pSimRender as ISizeRenderer;
  pSizeRender.SizeRendererFlags = (int)esriSizeRendererFlags.esriSizeRendererUseExpression;
  pSizeRender.SizeRendererExpression = "[SIZE]";      

 

简单渲染

        /// <summary>
        /// 单一符号化
        /// </summary>
        /// <param name="pFeatLyr">渲染图层</param>
        /// <param name="pRgbColor">渲染颜色</param>
        private void SimpleRenderer(IFeatureLayer pFeatLyr, IMarkerSymbol markerSymbol)
        {
            try
            {
                esriGeometryType type = pFeatLyr.FeatureClass.ShapeType;
                ISimpleRenderer pSimRender = new SimpleRendererClass();
                
                IColor pColor = this.GetColor(255, 0, 0);
                if (type == esriGeometryType.esriGeometryPoint)
                {
                    markerSymbol.Color = pColor;
                    markerSymbol.Size = 50;
                    pSimRender.Symbol = markerSymbol as ISymbol;
                    IRotationRenderer pRotationRender = pSimRender as IRotationRenderer;
                    pRotationRender.RotationField = "ANGEL";
                    pRotationRender.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;

                    ISizeRenderer pSizeRender = pSimRender as ISizeRenderer;
                    pSizeRender.SizeRendererFlags = (int)esriSizeRendererFlags.esriSizeRendererUseExpression;
                    pSizeRender.SizeRendererExpression = "[SIZE]";                    

                }
              
                IGeoFeatureLayer pGeoFeatLyr = pFeatLyr as IGeoFeatureLayer;
                pGeoFeatLyr.Renderer = pSimRender as IFeatureRenderer;
                this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                this.axTOCControl1.Update();
            }
            catch (Exception ex)
            {
            }
        }

唯一值渲染

        /// <summary>
        /// 多符号
        /// </summary>
        /// <param name="pFeaLyr"></param>
        /// <param name="fieldname"></param>
        private void UniqueValueRender(IFeatureLayer pFeaLyr, string fieldname)
        {
            IGeoFeatureLayer pGeoFeatLyr = pFeaLyr as IGeoFeatureLayer;
            ITable pTable = pFeaLyr as ITable;
            IUniqueValueRenderer pUniqueValueRender = new UniqueValueRendererClass();

            int intFieldNumber = pTable.FindField(fieldname);
            pUniqueValueRender.FieldCount = 1;//设置唯一值符号化的关键字段为一个
            pUniqueValueRender.set_Field(0, fieldname);//设置唯一值符号化的第一个关键字段

            //根据渲染字段的值的个数,设置一组随机颜色,如某一字段有5个值,则创建5个随机颜色与之匹配
            IQueryFilter pQueryFilter = new QueryFilterClass();
            bool bSuccess = false;
            IColor pNextUniqueColor = this.GetColor(255, 0, 0);
            //查询字段的值
            pQueryFilter = new QueryFilterClass();
            pQueryFilter.AddField(fieldname);
            ICursor pCursor = pTable.Search(pQueryFilter, true);
            IRow pNextRow = pCursor.NextRow();
            int codeValue = 0;
            IRowBuffer pNextRowBuffer = null;

            while (pNextRow != null)
            {
                pNextRowBuffer = pNextRow as IRowBuffer;
                codeValue = Convert.ToInt32(pNextRowBuffer.get_Value(intFieldNumber));//获取渲染字段的每一个值
                IMarkerSymbol pMarkerSymbol = null;

                switch (pGeoFeatLyr.FeatureClass.ShapeType)
                {
                    case esriGeometryType.esriGeometryPoint:
                        {
                            string symbolname = "";
                            switch (codeValue)
                            {
                                case 1:
                                    symbolname = "飞机场";
                                    break;
                                case 2:
                                    symbolname = "箭头";
                                    break;
                                case 3:
                                    symbolname = "房屋";
                                    break;

                            }
                            pMarkerSymbol = ServerSymbolUtilty.GetItemFromServerStyle(symbolFile, "Marker Symbols", symbolname).Item as IMarkerSymbol;
                            pMarkerSymbol.Color = pNextUniqueColor;
                            pUniqueValueRender.AddValue(codeValue.ToString(), "", pMarkerSymbol as ISymbol);//添加渲染字段的值和渲染样式
                            pNextRow = pCursor.NextRow();
                            break;
                        }
                }
            }
            IRotationRenderer pRotationRender = pUniqueValueRender as IRotationRenderer;
            pRotationRender.RotationField = "ANGEL";
            pRotationRender.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;

            ISizeRenderer pSizeRender = pUniqueValueRender as ISizeRenderer;
            pSizeRender.SizeRendererFlags = (int)esriSizeRendererFlags.esriSizeRendererUseExpression;
            pSizeRender.SizeRendererExpression = "[SIZE]";

            pGeoFeatLyr.Renderer = pUniqueValueRender as IFeatureRenderer;
            axMapControl1.Refresh();
            axTOCControl1.Update();
        }

 

这里仅是点符号的渲染,其他渲染类似,代码比较乱,仅供参考,

 

posted @ 2017-05-08 17:43  vichang  阅读(2822)  评论(0编辑  收藏  举报