基于C#的ArcEngine二次开发教程(09):矢量图层点线面的渲染原理及代码实现

目录

1 ArcMap的点、线、面渲染操作

1.1 点渲染

1.2 线渲染

1.3 面渲染

2 利用AE的SimpleRender进行点线面渲染的通用接口

2.1 IGeoFeatureLayer接口

2.2 IFeatureRenderer接口

2.3 ISimpleRenderer接口

2.4 ISymbol接口

3 点渲染的接口及实现源码

3.1 SimpleMarkerSymbolClass类

3.2 ISimpleMarkerSymbol

3.3 点渲染实现源码

4  线渲染代码接口及实现源码

4.1 SimpleLineSymbolClass类

4.2 ISimpleLineSymbol接口

4.3 线渲染实现源码

5 面渲染的实现

5.1 ILineSymbol接口进行线要素的渲染

5.2 ISimpleFillSymbol进行面填充渲染

5.3 面渲染实现源码

6 总结


1 ArcMap的点、线、面渲染操作

1.1 点渲染

修改点符号的类型和颜色

1.2 线渲染

修改线型和颜色

1.3 面渲染

修改填充颜色和边线宽度及颜色

2 利用AE的SimpleRender进行点线面渲染的通用接口

2.1 IGeoFeatureLayer接口

IGeoFeatureLayer接口的成员如下所示:

AllPropertiesMethodsInheritedNon-inheritedDescription
Read/write propertyAnnotationPropertiesAnnotation properties.
Read/write propertyAnnotationPropertiesIDThe UID used for annotation properties.
Read-only propertyAreaOfInterestThe default area of interest for the layer.
Read/write propertyCachedIndicates if the layer needs its own display cache.
Write-only propertyCurrentMapLevelCurrent map level for drawing symbols.
Read/write propertyDataSourceTypeData source type.
Read/write propertyDisplayAnnotationIndicates if the layer displays annotation.
Read-only propertyDisplayFeatureClassFeature class used for display operations (may include joined fields).
Read/write propertyDisplayFieldPrimary display field.
MethodDrawDraws the layer to the specified display for the given draw phase.
Read/write propertyExclusionSetThe set of features that are excluded from drawing.
Read/write propertyFeatureClassThe layer's feature class.
Read/write propertyMaximumScaleMaximum scale (representative fraction) at which the layer will display.
Read/write propertyMinimumScaleMinimum scale (representative fraction) at which the layer will display.
Read/write propertyNameLayer name.
Read/write propertyRendererRenderer used to draw the layer.
Read/write propertyRendererPropertyPageClassIDClass id of the property page for the renderer.
Read/write propertyScaleSymbolsIndicates if symbols are scaled for the layer.
MethodSearchCreates a cursor based upon the search criteria.
MethodSearchDisplayFeaturesCreates a cursor from the display feature class based upon the search criteria.
Read/write propertySelectableIndicates if layer is selectable.
Read/write propertyShowTipsIndicates if the layer shows map tips.
Write-only propertySpatialReferenceSpatial reference for the layer.
Read-only propertySupportedDrawPhasesSupported draw phases.
Read-only propertyTipTextMap tip text at the specified location.
Read-only propertyValidIndicates if the layer is currently valid.
Read/write propertyVisibleIndicates if the layer is currently visible.

其中有可读可写的Render属性,用来对图层进行渲染;此外该接口继承自IFeatureLayer接口,可以使用as进行强制类型转换

 

打开Render属性发现其类型为IFeatureRenderer

2.2 IFeatureRenderer接口

发现对该接口进行实现的SimpleRender类

沿着SimpleRenderer接口继续向上追溯,发现其继承自接口ISimpleRenderer

2.3 ISimpleRenderer接口

ISimpleRenderer中包含可读可写的Symbol属性,类型为ISymbol;

2.4 ISymbol接口

对该接口进行实现的类中找到如下类:

3 点渲染的接口及实现源码

回溯到ISymbol接口发现,ISymbol中被没有任何对属性可供操作,但是SimpleMarkerSymbolClass类对其进行实现,继续追溯。

3.1 SimpleMarkerSymbolClass类

该类同时实现了接口ISymbol和ISimpleMarkerSymbol,利用接口查询技术实现这两个类的跳转;ISimpleMarkerSymbol提供了对对Symbol的操作

3.2 ISimpleMarkerSymbol

3.3 点渲染实现源码

        private void 点渲染ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFeatureLayer myfealyer = axMapControl1.get_Layer(0) as IFeatureLayer;//得到当前视图中的第一个图层
            IGeoFeatureLayer geofeature = myfealyer as IGeoFeatureLayer;
            ISimpleRenderer render = new SimpleRendererClass();//定义渲染器

            ISymbol symbol = new SimpleMarkerSymbolClass();//定义渲染符号
            ISimpleMarkerSymbol markSymbol = symbol as ISimpleMarkerSymbol;
            IColor color = new RgbColor();
            color.RGB = 251;
            markSymbol.Color = color;//定义标记符号的颜色
            markSymbol.Size = 10;//定义标记符号的大小
            markSymbol.Style = esriSimpleMarkerStyle.esriSMSX;//定义标记符号的风格
            
            render.Symbol = symbol;
            geofeature.Renderer = render as IFeatureRenderer;
            axTOCControl1.Update();
            axMapControl1.Refresh();
        }

4  线渲染代码接口及实现源码

4.1 SimpleLineSymbolClass类

4.2 ISimpleLineSymbol接口

4.3 线渲染实现源码

 private void 线渲染ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFeatureLayer myfealyer = axMapControl1.get_Layer(0) as IFeatureLayer;//得到当前视图中的第一个图层
            IGeoFeatureLayer geofeature = myfealyer as IGeoFeatureLayer;
            ISimpleRenderer render = new SimpleRendererClass();//定义渲染器

            ISymbol symbol = new SimpleLineSymbolClass();//定义渲染符号
            ISimpleLineSymbol linesymbol = symbol as ISimpleLineSymbol;

            IColor color = new RgbColor();
            color.RGB = 255;

            linesymbol.Color = color;
            linesymbol.Style = esriSimpleLineStyle.esriSLSDot;
            linesymbol.Width = 3;

            render.Symbol = symbol;
            geofeature.Renderer = render as IFeatureRenderer;
            
            axMapControl1.Update();
            axTOCControl1.Refresh();
        }

5 面渲染的实现

5.1 ILineSymbol接口进行线要素的渲染

5.2 ISimpleFillSymbol进行面填充渲染

有三个属性:

color用来设置面填充的颜色;

Ouline是为了设置轮廓线的颜色和线宽,使用线填充是用到的SimpleLineSymbolClass类;

Style设置填充风格

5.3 面渲染实现源码

 private void 面渲染ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFeatureLayer myfealyer = axMapControl1.get_Layer(0) as IFeatureLayer;//得到当前视图中的第一个图层
            IGeoFeatureLayer geofeature = myfealyer as IGeoFeatureLayer;
            ISimpleRenderer render = new SimpleRendererClass();//定义渲染器

            ILineSymbol linesymbol = new SimpleLineSymbolClass();
            IColor color = new RgbColor();
            color.RGB = 255;
            linesymbol.Color = color;//线的颜色
            linesymbol.Width = 5;//线宽

            ISymbol symbol = new SimpleFillSymbolClass();
            ISimpleFillSymbol fillSybol = symbol as ISimpleFillSymbol;
            fillSybol.Outline = linesymbol;
            IColor fillColor = new RgbColor();//设置填充色
            fillColor.RGB = 255;
            fillSybol.Color = fillColor;
            fillSybol.Style = esriSimpleFillStyle.esriSFSVertical;

            render.Symbol = symbol;
            geofeature.Renderer = render as IFeatureRenderer;

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

        }

6 总结

在使用AE进行二次开发时,要多多使用官方的帮助文档,训练快速根据帮助文档理顺可用接口及其之间的关系,以实现需要的功能。

在AE中有这样一个命名规律:

对一个类按照单词进行拆解,可依次发现其继承的接口,如下图:

本博文用到的接口和类如下:

接口描述官方描述
IFeatureLayer矢量图层接口Provides access to the properties and methods of a layer based on vector geographic data, which is typically a geodatabase, shapefile, or coverage feature class.
IGeoFeatureLayer

矢量图层符号和标记接口

Provides access to symbolization and labeling properties for layers based on vector geographic data. Also provides a method for returning a read-only feature cursor of layer features that includes joined fields.

IFeatureRenderer

矢量渲染器接口

All feature renderers implement this interface and it is used by the framework to draw features from a FeatureClass.

ISimpleRenderer

图层渲染接口

Provides access to members that control a renderer which draws the same symbol for each feature.

ISymbol

图层符号接口

Provides access to members that control symbols.

ISimpleMarkerSymbol点符号接口Provides access to members that control the simple marker symbol.
ISimpleLineSymbol符号接口

ISimpleLineSymbol is used to create a line symbol comprised of a predefinded set of styles. The availble styles are provided by the esriSimpleLineStyle enumeration. Use the ILineSymbol interface to set additional properties for ISimpleLineSymbols.

ISimpleFillSymbol

面符号接口

ISimpleFillSymbol is used to create a fill symbol comprised of a predefined set of styles. The available styles are provided by the esriSimpleFillStyle enumeration. Use the IFillSymbol interface to set additional properties for ISimpleFillSymbols.

更多精彩,欢迎关注个人微信公众帐号“学而立行”

 

  • 18
    点赞
  • 61
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小薛引路

喜欢的读者,可以打赏鼓励一下

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值