注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

快乐小屋

 
 
 

日志

 
 

ArcEngine实现唯一值多字段符号化  

2013-06-08 12:22:07|  分类: ArcGIS Engine开 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
 我们通过AE开发帮助可以获得唯一值单字段的开发示例代码。但没有相关的AE唯一值多字段的开发代码。由于开发的需要我整理并总结了AE实现唯一值多字段的实例。
  本实例以某一图层中的2个或3个字段的唯一值对地图进行颜色的渲染。
实例界面:


ArcEngine实现唯一值多字段符号化

 

下面给出唯一值多字段渲染的核心代码:

    private void UniqueValueRenderer(IFeatureLayer pFeatLyr, string[] sFieldName) 

        {

            IUniqueValueRenderer pUniqueValueRender;

            IColor pNextUniqueColor;

            IEnumColors pEnumRamp;

            ITable pTable;

            IRow pNextRow;

            ICursor pCursor;

            IQueryFilter pQueryFilter;

            IRandomColorRamp pRandColorRamp new RandomColorRampClass();

            pRandColorRamp.StartHue 0;

            pRandColorRamp.MinValue 0;

            pRandColorRamp.MinSaturation 15;

            pRandColorRamp.EndHue 360;

            pRandColorRamp.MaxValue 100;

            pRandColorRamp.MaxSaturation 30;

            IQueryFilter pQueryFilter1 new QueryFilterClass();

            pRandColorRamp.Size pFeatLyr.FeatureClass.FeatureCount(pQueryFilter1);

            bool bSuccess false;

            pRandColorRamp.CreateRamp(out bSuccess);

            if (sFieldName.Length==2) 

            {

                string sFieldName1 sFieldName[0];

                string sFieldName2 sFieldName[1];

                IGeoFeatureLayer pGeoFeatureL (IGeoFeatureLayer)pFeatLyr;

                pUniqueValueRender new UniqueValueRendererClass();

                pTable (ITable)pGeoFeatureL;

                int pFieldNumber pTable.FindField(sFieldName1);

                int pFieldNumber2 pTable.FindField(sFieldName2);

                pUniqueValueRender.FieldCount 2;

                pUniqueValueRender.set_Field(0, sFieldName1);

                pUniqueValueRender.set_Field(1, sFieldName2);

                pEnumRamp pRandColorRamp.Colors;

                pNextUniqueColor null;

                pQueryFilter new QueryFilterClass();

                pQueryFilter.AddField(sFieldName1);

                pQueryFilter.AddField(sFieldName2);

                pCursor pTable.Search(pQueryFilter, true);

                pNextRow pCursor.NextRow();

                string codeValue;

                while (pNextRow != null)

                {

                    codeValue pNextRow.get_Value(pFieldNumber).ToString() pUniqueValueRender.FieldDelimiter pNextRow.get_Value(pFieldNumber2).ToString();

                    pNextUniqueColor pEnumRamp.Next();

                    if (pNextUniqueColor == null)

                    {

                        pEnumRamp.Reset();

                        pNextUniqueColor pEnumRamp.Next();

                    }

                    IFillSymbol pFillSymbol;

                    ILineSymbol pLineSymbol;

                    IMarkerSymbol pMarkerSymbol;

                    switch (pGeoFeatureL.FeatureClass.ShapeType)

                    {

                        case esriGeometryType.esriGeometryPolygon:

                            {

                                pFillSymbol new SimpleFillSymbolClass();

                                pFillSymbol.Color pNextUniqueColor;

                                pUniqueValueRender.AddValue(codeValue, sFieldName1 " sFieldName2, (ISymbol)pFillSymbol);

                                break;

                            }

                        case esriGeometryType.esriGeometryPolyline:

                            {

                                pLineSymbol new SimpleLineSymbolClass();

                                pLineSymbol.Color pNextUniqueColor;

                                pUniqueValueRender.AddValue(codeValue, sFieldName1 " sFieldName2, (ISymbol)pLineSymbol);

                                break;

                            }

                        case esriGeometryType.esriGeometryPoint:

                            {

                                pMarkerSymbol new SimpleMarkerSymbolClass();

                                pMarkerSymbol.Color pNextUniqueColor;

                                pUniqueValueRender.AddValue(codeValue, sFieldName1 " sFieldName2, (ISymbol)pMarkerSymbol);

                                break;

                            }

                    }

                    pNextRow pCursor.NextRow();

                }

                pGeoFeatureL.Renderer (IFeatureRenderer)pUniqueValueRender;

                axMapControl1.Refresh();

            }

            else if (sFieldName.Length == 3)

            {

                string sFieldName1 sFieldName[0];

                string sFieldName2 sFieldName[1];

                string sFieldName3 sFieldName[2];

                IGeoFeatureLayer pGeoFeatureL (IGeoFeatureLayer)pFeatLyr;

                pUniqueValueRender new UniqueValueRendererClass();

                pTable (ITable)pGeoFeatureL;

                int pFieldNumber pTable.FindField(sFieldName1);

                int pFieldNumber2 pTable.FindField(sFieldName2);

                int pFieldNumber3 pTable.FindField(sFieldName3);

                pUniqueValueRender.FieldCount 3;

                pUniqueValueRender.set_Field(0, sFieldName1);

                pUniqueValueRender.set_Field(1, sFieldName2);

                pUniqueValueRender.set_Field(2, sFieldName3);              

                pEnumRamp pRandColorRamp.Colors;

                pNextUniqueColor null;

                pQueryFilter new QueryFilterClass();

                pQueryFilter.AddField(sFieldName1);

                pQueryFilter.AddField(sFieldName2);

                pQueryFilter.AddField(sFieldName3);

                pCursor pTable.Search(pQueryFilter, true);

                pNextRow pCursor.NextRow();

                string codeValue;

                while (pNextRow != null)

                {

                    codeValue pNextRow.get_Value(pFieldNumber).ToString() pUniqueValueRender.FieldDelimiter pNextRow.get_Value(pFieldNumber2).ToString() pUniqueValueRender.FieldDelimiter pNextRow.get_Value(pFieldNumber3).ToString();

                    pNextUniqueColor pEnumRamp.Next();

                    if (pNextUniqueColor == null)

                    {

                        pEnumRamp.Reset();

                        pNextUniqueColor pEnumRamp.Next();

                    }

                    IFillSymbol pFillSymbol;

                    ILineSymbol pLineSymbol;

                    IMarkerSymbol pMarkerSymbol;

                    switch (pGeoFeatureL.FeatureClass.ShapeType)

                    {

                        case esriGeometryType.esriGeometryPolygon:

                            {

                                pFillSymbol new SimpleFillSymbolClass();

                                pFillSymbol.Color pNextUniqueColor;

                                pUniqueValueRender.AddValue(codeValue, sFieldName1 " sFieldName2 "" sFieldName3, (ISymbol)pFillSymbol);

                                break;

                            }

                        case esriGeometryType.esriGeometryPolyline:

                            {

                                pLineSymbol new SimpleLineSymbolClass();

                                pLineSymbol.Color pNextUniqueColor;

                                pUniqueValueRender.AddValue(codeValue, sFieldName1 " sFieldName2 "" sFieldName3, (ISymbol)pLineSymbol);

                                break;

                            }

                        case esriGeometryType.esriGeometryPoint:

                            {

                                pMarkerSymbol new SimpleMarkerSymbolClass();

                                pMarkerSymbol.Color pNextUniqueColor;

                                pUniqueValueRender.AddValue(codeValue, sFieldName1 " sFieldName2 "" sFieldName3, (ISymbol)pMarkerSymbol);

                                break;

                            }

                    }

                    pNextRow pCursor.NextRow();

                }

                pGeoFeatureL.Renderer (IFeatureRenderer)pUniqueValueRender;

                axMapControl1.Refresh();

            }

        }

代码中的string[] sFieldName数组中存储着所选取的字段,通过这个数组可以实现2个字段和3个字段的多值渲染,与ArcGIS软件相对应。

  评论这张
 
阅读(468)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018