添加现有注释图层

时间:2013-03-06 16:19:23

标签: c# annotations layer arcgis

我的程序的目的是遍历给定目录中的每个.mxd文件,删除旧的和破坏的注释图层,并为特定要素类添加新文件。地理数据库中的旧注释源将按要素类类型合并为单个注释文件。 (因此,没有bAnno1,bAnno2 ......它将是bAnnos。这样可以节省空间并减少ArcGIS编辑时间。)

我的问题是创建新的注释图层。我的原始代码是沿着这些行(仅在外部循环中创建前五个变量):

IMapDocument mapdoc = new MapDocumentClass();
IWorkspaceFactory iwf = new FileGDBWorkspaceFactoryClass();
IFeatureWorkspace workspace = (IFeatureWorkspace)iwf.OpenFromFile(path, 0);
IFeatureDataset dataset = workspace.OpenFeatureDataset(datasetName);
IFeatureClassContainer container = (IFeatureClassContainer)dataset;

// Here is where it enters the loop for .mxd files

IMap pMap = mapdoc.get_Map(0);

// Here it removes old annotation layers first

IFeatureLayer newlayer = new FeatureLayerClass();
newlayer.DataSourceType = "File Geodatabase Feature Class";
newlayer.Name = "Anno Name";
newlayer.FeatureClass = container.get_ClassByName(annoName);
pMap.AddLayer((ILayer)newlayer);

添加的图层与符号系统中的所有内容都匹配原始注记图层。换句话说,ArcGIS将这些添加的文件视为多边形的要素类,而不是带有单词的注记类。看看我的代码,我明白为什么。

那么如何将其专门设为注释图层呢?或者如何使用地理数据库中数据集中的现有源创建注记图层?

尝试失败包括使用:

AnnotationFeatureClass tempLayer = new AnnotationFeatureClass();
IAnnoClass newlayer = (IAnnoClass)tempLayer;

IAnnotationLayerFactory annofactory = new FDOGraphicsLayerFactoryClass();
IAnnotationLayer annoLayer = annofactory.CreateAnnotationLayer(...);

上述方法之一实际上可能就是答案;我可能做错了。

其他详细信息:使用ArcGIS 10,使用由ArcGIS 9.3和10制作的.mxd文件。

1 个答案:

答案 0 :(得分:0)

我找到了答案。

我有这个:

IFeatureLayer newlayer = new FeatureLayerClass();

需要这样:

ILayer nlayer = (ILayer)(new FDOGraphicsLayer());
IFeatureLayer newlayer = (IFeatureLayer)nlayer;

不幸的是,在我做了深度复制预先存在的注释类并编辑源代码的解决方法后,我发现了这一点。所以还有另一种方式,如果有人对kludging感兴趣。

相关问题