转自chanyinhelv原文Annotation研究的一些学习资料 mysql
下面是我最近对Annotation研究的一些学习资料,收集于此,供你们学习之用。算法
1、Annotation要素类介绍sql
在GeoDatabase中有五种类型的要素类,即点、线、面、标注要素类和注记要素类。注记要素类涉及的较少,这里不谈。本文主要讨论标注要素类的特征,即Annotation FeatureClass的特性。数据库
标注要素类是一种专门用于存储和显示文本或图形元素的数据结构,在这以前,咱们只谈过文本或图像只能经过MXD的方式来存储。标注要素类能够是独立的,也能够与一个要素类相关联。若是是独立standalone的要素类,它就是其它要素类的一种背景;一旦与某个要素类相联系link,那么标注要素显示的内容就取决于与之相关的要素。c#
若是要新建一个标注要素类,不管是直接在工做空间中仍是在一个要素数据集中,都须要使用到IFeatureWorkspaceAnno的接口,下面咱们经过这个接口的CreateAnnotationClass方法来介绍标注要素类的一系列特性:数据结构
public IFeatureClass CreateAnnotationClass (
string Name,
IFields Fields,
UID CLSID,
UID EXTCLSID,
string ShapeFieldName,
string ConfigKeyword,
IFeatureDataset dstFeatureDataset,
IFeatureClass srcFeatureClass,
object annoProperties,
object referenceScale,
object symbolCollection,
bool autoCreate
);post
Name是新建的标注要素类的名称,这个字符串能够随意设置。
Fields是标注要素类的字段,与其它要素类不一样的是,标注要素类的系统字段至关的多,这是由于标注字段涉及到存储字符和修饰字符的Symbol样式,所以,咱们也不建议用户本身添加这些难以记忆的字段,在这种状况下,咱们可使用一种简单的方式实现:
IObjectClassDescription pOCDesc=New AnnotationFeatureClassDescription;
Fields=pOCDesc.RequiredFields;
也许有人会问,若是除了这些系统字段外,咱们还有本身的字段怎么办?这个很简单,使用IFieldsEdit的方法再加自定义字段就能够了。学习
CLSID和EXTCLSID两个参数也是必须的,它们的含义很是有趣。咱们知道,GeoDatabase中的每一个对象都有个惟一标识符UID,系统是靠认证这个64位的随机值来区分不一样对象的,一样的,要素类和要素类的扩展部分也有这么个标识,只不过在通常状况下咱们没法看到这个UID值而已。如何产生这两个值呢,也很简单,使用:
CLSID=pOCDesc.InstanceCLSID;
EXTCLSID=pOCDesc.ClassExtensionCLSID;字体
ShapeFieldName是指一个要素类的Shape字段名,通常都是"SHAPE"。ui
ConfigKeyword通常不用设置,能够设置为空字符串。
dstFeatureDataset是指一个标注要素类被放置的要素数据集,固然,若是这个标注要素类直接放在工做空间中,这个参数将被设置为null便可。
srcFeatureClass是标注要素类关联的要素类,若是标注要素类是独立的,则这个参数也能够为null。
接下来的四个参数的前三个就是关键了,能够说,整个要素类的正常显示就是依赖它们。
2、使用Annotation对象进行要素标注并设置标注位置
AO中有两种方法实现要素标注,一种是本身添加TextElement对象到文档对象中,另外一种就是使用AO提供的Annotation对象,它的功能更增强大和丰富,它以更复杂的方法和属性对要素图层进行标注,标注的内容能够保存到地理数据库中。实现这个要素标注涉及到的对象包括IAnnotateLayerPropertiesCollection对象、IAnnotateLayerProperties对象和ILabelEngineLayerProperties对象,其实现代码以下:(c#)
public void CreateAnno(IFeatureLayer pFeatureLayer )
{
IGeoFeatureLayer pGeoFLayer = pFeatureLayer as IGeoFeatureLayer;
//获得图层的标注属性集合对象
IAnnotateLayerPropertiesCollection pAnnoLayerpRropColl = new AnnotateLayerPropertiesCollectionClass();
pAnnoLayerpRropColl = pGeoFLayer.AnnotationProperties;
//清空这个集合中的对象
pAnnoLayerpRropColl.Clear();
//新建一个图层标注引擎对象,设置它的属性
ILabelEngineLayerProperties pLabelEngineLayerProp = new LabelEngineLayerPropertiesClass();
pLabelEngineLayerProp.Expression = "[DYP]";
//建立注记文本的文本符号
ITextSymbol pTextSym = new TextSymbolClass();
pTextSym.Color = GeoTool.GetColor(255, 0, 0);
pTextSym.Size = 10;
IFont font = new StdFontClass();
font.Name = "Times New Roman";
pTextSym.Font = (IFontDisp)font;
pLabelEngineLayerProp.Symbol = pTextSym;
//设置注记文本的位置
IBasicOverposterLayerProperties pBasicOverposeterLayerProp = new BasicOverposterLayerPropertiesClass();
pBasicOverposeterLayerProp.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
pBasicOverposeterLayerProp.FeatureWeight = esriBasicOverposterWeight.esriNoWeight;
pBasicOverposeterLayerProp.LabelWeight = esriBasicOverposterWeight.esriHighWeight;
pBasicOverposeterLayerProp.BufferRatio = 0;
//方式一:标注位于点特征顶部
//pBasicOverposeterLayerProp.PointPlacementOnTop = true;
//方式二:标注环绕点特征
pBasicOverposeterLayerProp.PointPlacementMethod = esriOverposterPointPlacementMethod.esriAroundPoint;
IPointPlacementPriorities pPointPlacement = new PointPlacementPrioritiesClass();
pPointPlacement.AboveCenter = 0;
pPointPlacement.AboveLeft = 0;
pPointPlacement.AboveRight = 0;
pPointPlacement.BelowCenter = 1;
pPointPlacement.BelowLeft = 0;
pPointPlacement.BelowRight = 0;
pPointPlacement.CenterLeft = 0;
pPointPlacement.CenterRight = 0;
pBasicOverposeterLayerProp.PointPlacementPriorities = pPointPlacement;
//方式三:标准旋转必定角度
//pBasicOverposeterLayerProp.PointPlacementMethod = esriOverposterPointPlacementMethod.esriSpecifiedAngles;
//double[] angle = new double[2];
//angle[0] = 45;
//angle[1] = 90;
//pBasicOverposeterLayerProp.PointPlacementAngles = angle;
pLabelEngineLayerProp.BasicOverposterLayerProperties = pBasicOverposeterLayerProp;
IAnnotateLayerProperties pAnnoLayerProp = (IAnnotateLayerProperties)pLabelEngineLayerProp;
pAnnoLayerpRropColl.Add(pAnnoLayerProp);
pGeoFLayer.DisplayField = pLabelEngineLayerProp.Expression;
pGeoFLayer.DisplayAnnotation = true;
}
3、使用TextElement对象进行要素标注
使用TextElement对象进行要素标注能够控制标注字体的样式,标注的流程是首先获取要素图层中全部要进行标注的要素,而后对各个要素建立TextElement对象,并将其Text设为要素的某个字段属性,而Geometry是要素包括线的中间点。一下是在三维GlobeControl中的实现代码如:(c#)
//获取图层要素对象
IFeatureCursor pFeatCurso = new FeatureCursorClass();
pFeatCurso = pFeatClass.Search(null, true);
IFeature pFeature = null;
pFeature = pFeatCurso.NextFeature();
while (pFeature != null)
{
//读取要素
.........................
pFeature = pFeatCurso.NextFeature();
}
以上是有关读取图层要素的过程,这里省略。
添加标注代码:
说明:pArray中存放的是IGeometry对象
public void AddElement(ArrayList pArray, IGlobeGraphicsLayer pGlobeGraphicsLayer)
{
//删除上次添加的element
IGraphicsContainer pGraphicsContainer = pGlobeGraphicsLayer as IGraphicsContainer;
pGraphicsContainer.DeleteAllElements();
pGlobeGraphicsLayer.UpdateAllElements();
//设置显示属性
IGlobeGraphicsElementProperties pGlobeGraphicsElementProperties = new GlobeGraphicsElementPropertiesClass();
pGlobeGraphicsElementProperties.DrapeElement = true;
pGlobeGraphicsElementProperties.FixedScreenSize = true;
pGlobeGraphicsElementProperties.DrapeQuality = true;
pGlobeGraphicsElementProperties.OrientationMode = esriGlobeGraphicsOrientation.esriGlobeGraphicsOrientationLocal;
int hh;
for (int i = 0; i < pArray.Count; i = i + 2)
{
IGeometry pGeometry = (IGeometry)pArray[i + 1];
IPoint point = new PointClass();
point = GeoTool.GetGeo(pGeometry);
//添加点element对象(设置标注对象形状)
IElement pElement = new MarkerElementClass(); //定义为标注性对象方便后续设置
ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); //设置形状
pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
IMarkerSymbol pMarkerSymbol = pSimpleMarkerSymbol as IMarkerSymbol; //设置颜色大小
pMarkerSymbol.Color = GeoTool.GetColor(0, 255, 0);
pMarkerSymbol.Size = 5;
pElement.Geometry = point as IGeometry;
IMarkerElement pMarkerElement = pElement as IMarkerElement;
pMarkerElement.Symbol = pMarkerSymbol;
pGlobeGraphicsLayer.AddElement(pElement as IElement, pGlobeGraphicsElementProperties, out hh);
//添加文本element对象(标注的文字部分)
ITextElement pTextElement = new TextElementClass();
ITextSymbol pTextSymbol = new TextSymbolClass();
pTextSymbol.Color = GeoTool.GetColor(255, 0, 0);
pTextSymbol.Size = 10;
IFontDisp pFontDisp = (IFontDisp)new StdFontClass(); //设置字体
pFontDisp.Name = "Times New Roman";
pFontDisp.Bold = true;
pFontDisp.Size = 10;
pTextSymbol.Font = pFontDisp;
pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
pTextElement.Symbol = pTextSymbol;
pTextElement.Text = pArray[i].ToString();
((IElement)pTextElement).Geometry = point as IGeometry;
pGlobeGraphicsLayer.AddElement(pTextElement as IElement, pGlobeGraphicsElementProperties, out hh);
}
}
对于二维中要加载TextElement标注,其建立TextElement的方法相同,主要是在于后面加载的方式不一样而已,加载到的对象不一样而已,三维GlobeControl中是加载到一个IGlobeGraphicsLayer中,二维中则是加载到MapControl的Map对象中。其核心代码以下:
IMap pMap = axMapControl1.Map;
IActiveView pActiveView = pMap as IActiveView;
IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;
//将元素添加进Map对象中
pGraphicsContainer.AddElement(pElement,0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);