当前位置: 首页 > news >正文

ArcEngine标注和注记(-)

       标注和注记是ArcEngine中提供的两种使用文字信息标注地图要素的方式.其中标注是作为图层的属性存在的,可以动态创建,注记作为地理要素被存储.需要注意的是Shp文件不支持注记.  绘制标注的方式有两种.让我们先看第一种:

    1.使用TextElment绘制标注.

    这种方法的原理就是把属性表中的某个属性创建TextElment对象,然后使用IGraphicsContainer 的AddElement方法添加标注.实例代码:

        //使用TextElment绘制标注, fieldName为要绘制的属性
public static void AddLable(AxMapControl axMapControl, ILayer layer, string fieldName)
{
IRgbColor pColor
= new RgbColorClass()
{
Red
= 255,
Blue
= 0,
Green
= 0
};
IFontDisp pFont
= new StdFont()
{
Name
= "宋体",
Size
= 5
}
as IFontDisp;
 
            ITextSymbol pTextSymbol = new TextSymbolClass()
{
Color
= pColor,
Font
= pFont,
Size
= 11
};

IGraphicsContainer pGraContainer
= axMapControl.Map as IGraphicsContainer;

//遍历要标注的要素
IFeatureLayer pFeaLayer = layer as IFeatureLayer;
IFeatureClass pFeaClass
= pFeaLayer.FeatureClass;
IFeatureCursor pFeatCur
= pFeaClass.Search(null, false);
IFeature pFeature
= pFeatCur.NextFeature();
int index = pFeature.Fields.FindField(fieldName);//要标注的字段的索引
IEnvelope pEnv = null;
ITextElement pTextElment
= null;
IElement pEle
= null;
while (pFeature != null)
{
//使用地理对象的中心作为标注的位置
pEnv = pFeature.Extent;
IPoint pPoint
= new PointClass();
pPoint.PutCoords(pEnv.XMin
+ pEnv.Width * 0.5, pEnv.YMin + pEnv.Height * 0.5);

pTextElment
= new TextElementClass()
{
Symbol
= pTextSymbol,
ScaleText
= true,
Text
= pFeature.get_Value(index).To\String()
};
pEle
= pTextElment as IElement;
pEle.Geometry
= pPoint;
//添加标注
pGraContainer.AddElement(pEle, 0);
pFeature
= pFeatCur.NextFeature();
}
(axMapControl.Map
as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, axMapControl.Extent);
}

     2.使用ArcEngine中的标注对象口.LabelEngineLayerProperties来标注要素

        IGeoFeatureLayer中的AnnotationProperties是一个包含LabelEngineLayerProperties对象的标注集合.而 LabelEngineLayerProperties实现了:

     IAnnotateProperties,  //
IAnnotateLayerProperties, //可以控制标注的显示比例尺,过滤条件等
ILabelEngineLayerProperties,
IAnnotateLayerTransformationProperties
//控制标注的参考比例尺,单位,标注边界和缩放比率等

等几个主要的接口.LabelEngineLayerProperties可以操作标注要素的多个属性和行为,如设置文本的标注位置,标注尺寸,设置脚本,文字符号等.该类实现了大量操作标注的属性和方法,对于复杂的标注非常有用,而TextElment适合简单的标注. ILabelEngineLayerProperties2是LabelEngineLayerPropertiesClass 的主接口.他的Expression和IsExpressionSimple用法如下:

        IsExpressionSimple=true,Expression为简单表达式,其形式为: "["+属性字段名+"]"+其他,

        IsExpressionSimple=true=false,Expression为复杂表达式,其内容也为一个字符串,但是一个完整的VBScript or JScript 函数或者表达式.

 ExpressionParser属性是一个Expression解析器,它支持更复杂的JS和Vbs代码.

  

        //添加标注,比TextElment功能更强大
public static void AddAnnotate(ILayer layer,string fieldName)
{
IGeoFeatureLayer pGeoLayer
= layer as IGeoFeatureLayer;
IAnnotateLayerPropertiesCollection IPALPColl
= pGeoLayer.AnnotationProperties;
IPALPColl.Clear();

IRgbColor pColor
= GetColor(255, 0, 0, 255);
IFontDisp pFont
= new StdFont()
{
Name
= "宋体",
Bold
= true
}
as IFontDisp;

ITextSymbol pTextSymbol
= new TextSymbolClass()
{
Color
= pColor,
Font
= pFont,
Size
= 12
};

//用来控制标注和要素的相对位置关系
ILineLabelPosition pLineLpos = new LineLabelPositionClass()
{
Parallel
= false, //修改标注的属性
Perpendicular = true,
InLine
= true
};
//用来控制标注冲突
ILineLabelPlacementPriorities pLinePlace = new LineLabelPlacementPrioritiesClass()
{
AboveStart
= 5, //让above 和start的优先级为5
BelowAfter = 4
};
//用来实现对ILineLabelPosition 和 ILineLabelPlacementPriorities以及更高级属性的控制
IBasicOverposterLayerProperties pBOLP = new BasicOverposterLayerPropertiesClass()
{
FeatureType
= esriBasicOverposterFeatureType.esriOverposterPolygon,
LineLabelPlacementPriorities
= pLinePlace,
LineLabelPosition
= pLineLpos
};

//创建标注对象
ILabelEngineLayerProperties pLableEngine = new LabelEngineLayerPropertiesClass()
{
Symbol
= pTextSymbol,
BasicOverposterLayerProperties
= pBOLP,
IsExpressionSimple
= true,
Expression
= "["+fieldName+"]"
};

//设置标注的参考比例尺
IAnnotateLayerTransformationProperties pAnnoLyrPros = pLableEngine as IAnnotateLayerTransformationProperties;
pAnnoLyrPros.ReferenceScale
= 2500000;

//设置标注可见的最大最小比例尺
IAnnotateLayerProperties pAnnoPros = pLableEngine as IAnnotateLayerProperties;
pAnnoPros.AnnotationMaximumScale
= 2500000;
pAnnoPros.AnnotationMinimumScale
= 25000000;
//pAnnoPros.WhereClause属性 设置过滤条件

IPALPColl.Add(pAnnoPros);
pGeoLayer.DisplayAnnotation
= true;
}

  


转载于:https://www.cnblogs.com/LoveLyre/archive/2011/09/10/2173310.html

相关文章:

  • cucumber安装可能发生的错误
  • Java获取本地IP地址
  • vue的路由传值query方法
  • Linux 安装python3.7.0
  • TensorFlow教程03:针对机器学习初学者的MNIST实验——回归的实现、训练和模型评估...
  • 云计算人才观念更重要
  • 以流动债务为例论指标的合理使用
  • 初学python,感受和C的不同
  • RANSAC 剔除错误匹配 估计模型
  • OpenLDAP在LINUX下的安装说明
  • 快速搭建企业subversion
  • asp.net 2.0 导出DataTable到Excel中
  • PAT 大数运算
  • UVA 11991 - Easy Problem from Rujia Liu?
  • Hadoop概念学习系列之关于hadoop-2.2.0和hadoop2.6.0的winutils.exe、hadoop.dll版本混用(易出错)(四十三)...
  • 实现windows 窗体的自己画,网上摘抄的,学习了
  • 【跃迁之路】【585天】程序员高效学习方法论探索系列(实验阶段342-2018.09.13)...
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • jdbc就是这么简单
  • JWT究竟是什么呢?
  • Protobuf3语言指南
  • TiDB 源码阅读系列文章(十)Chunk 和执行框架简介
  • V4L2视频输入框架概述
  • 包装类对象
  • 服务器之间,相同帐号,实现免密钥登录
  • 浅谈JavaScript的面向对象和它的封装、继承、多态
  • 如何在GitHub上创建个人博客
  • 微信开源mars源码分析1—上层samples分析
  • 栈实现走出迷宫(C++)
  • 湖北分布式智能数据采集方法有哪些?
  • ​MPV,汽车产品里一个特殊品类的进化过程
  • ​云纳万物 · 数皆有言|2021 七牛云战略发布会启幕,邀您赴约
  • (26)4.7 字符函数和字符串函数
  • (读书笔记)Javascript高级程序设计---ECMAScript基础
  • (二)什么是Vite——Vite 和 Webpack 区别(冷启动)
  • (附源码)springboot宠物管理系统 毕业设计 121654
  • (九)信息融合方式简介
  • (四)Android布局类型(线性布局LinearLayout)
  • (转)真正的中国天气api接口xml,json(求加精) ...
  • (转载)微软数据挖掘算法:Microsoft 时序算法(5)
  • ***微信公众号支付+微信H5支付+微信扫码支付+小程序支付+APP微信支付解决方案总结...
  • .Net Web项目创建比较不错的参考文章
  • .NET Windows:删除文件夹后立即判断,有可能依然存在
  • .NET 中创建支持集合初始化器的类型
  • .NET(C#) Internals: as a developer, .net framework in my eyes
  • .NET/C# 使窗口永不激活(No Activate 永不获得焦点)
  • .net安装_还在用第三方安装.NET?Win10自带.NET3.5安装
  • .net和php怎么连接,php和apache之间如何连接
  • .NET精简框架的“无法找到资源程序集”异常释疑
  • .NET微信公众号开发-2.0创建自定义菜单
  • .NET学习全景图
  • @hook扩展分析
  • @property括号内属性讲解
  • @RequestBody与@ModelAttribute
  • @RequestMapping处理请求异常