方式一:获取布局视图中的注记
1 { 2 IMapDocument mapDoc = new MapDocumentClass(); 3 mapDoc.Open(@"D:\Desktop\graphicsLayer.mxd"); 4 5 IGraphicsContainer container = mapDoc.PageLayout as IGraphicsContainer; 6 IElement pElement; 7 while ((pElement=container.Next())!=null) 8 { 9 ITextElement textElement = pElement as ITextElement; 10 Console.WriteLine(textElement.Text); 11 } 12 }
适用通过绘图工具条插入的文本、比例尺、线等要素
方式二:获取由图层的标注转换而来的注记(Labels To Annotation)
1 { 2 IMapDocument mapDoc = new MapDocumentClass(); 3 mapDoc.Open(@"D:\Desktop\graphicsLayer.mxd"); 4 5 IMap pMap = mapDoc.Map[0]; 6 IEnvelope pEnv = (pMap as IActiveView).Extent; 7 pEnv.Expand(1.5, 1.5, true); 8 9 IGraphicsLayer BasicGraphicsContainer = pMap.BasicGraphicsLayer; 10 ICompositeLayer pCompositeLayer = BasicGraphicsContainer as ICompositeLayer; 11 for (int i = 0; i < pCompositeLayer.Count; i++) 12 { 13 ILayer lyr = pCompositeLayer.get_Layer(i); 14 15 Console.WriteLine("---------------------"); 16 Console.WriteLine(lyr.Name); 17 IGraphicsLayer subGraLayer = lyr as IGraphicsLayer; 18 19 IGraphicsContainer container = subGraLayer as IGraphicsContainer; 20 IEnumElement enumElement = container.LocateElementsByEnvelope(pEnv); 21 if (enumElement != null) 22 { 23 enumElement.Reset(); 24 IElement subElement; 25 while ((subElement = enumElement.Next()) != null) 26 { 27 ITextElement textElement = subElement as ITextElement; 28 Console.WriteLine(textElement.Text); 29 } 30 } 31 } 32 }
解决问题场景:在批量制图时,宗地图与宗地草图差异存在一些细微的差异(例如,标注的界址点号不一样 图面形式不一样,可以通过修改mxd中的注记 出图后利用图片裁剪 拼接成新图。