阅读:2894回复:7
[求助]Feature Linked Annotation
<P>我用下面程序把LABEL转成FEATURE LINKED ANNOTATION. 创建ANNOTATION FEATURE CLASS了, 但总是空的. 试了很多次也没有结果. 请高手指点. 多谢多谢!!!</P><BR>
<P> private void CreateAnno()<BR> {<BR> ESRI.ArcGIS.Geodatabase.IWorkspace myWorkSpace = openSDEWorkspace("temp", "5151", "gistemp", "gistemp", "", "SDE.DEFAULT");<BR> if (myWorkSpace != null)<BR> {<BR> ESRI.ArcGIS.Geodatabase.IFeatureClass myFeatureClass = ((IFeatureWorkspace)myWorkSpace).OpenFeatureClass("GISADMIN.PhaseFlag");<BR> IFeatureDataset myDataset = ((IFeatureWorkspace)myWorkSpace).OpenFeatureDataset("GISADMIN.ElectricDataset");<BR> ConvertLabelsToGDBAnnotationSingleLayer(myWorkSpace, myDataset, myFeatureClass);<BR> }<BR> myWorkSpace = null;<BR> }</P><BR> <P> public IWorkspace openSDEWorkspace(String Server, String Instance, String User,<BR> String Password, String Database, String version)<BR> {<BR> ESRI.ArcGIS.esriSystem.IAoInitialize m_AoInitialize = new ESRI.ArcGIS.esriSystem.AoInitialize();<BR> m_AoInitialize.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeArcInfo);<BR> ESRI.ArcGIS.esriSystem.IPropertySet propertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();<BR> propertySet.SetProperty("SERVER", Server);<BR> propertySet.SetProperty("INSTANCE", Instance);<BR> propertySet.SetProperty("DATABASE", Database);<BR> propertySet.SetProperty("USER", User);<BR> propertySet.SetProperty("PASSWORD", Password);<BR> propertySet.SetProperty("VERSION", version);</P><BR> <P> ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2 workspaceFactory;<BR> workspaceFactory = (ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2)new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();<BR> IWorkspace pWorkspace;<BR> try<BR> {<BR> pWorkspace = workspaceFactory.Open(propertySet, 0);<BR> }<BR> catch<BR> {<BR> pWorkspace = null;<BR> }<BR> return pWorkspace;<BR> }</P><BR> <P> public void ConvertLabelsToGDBAnnotationSingleLayer(IWorkspace myWorkspace, IFeatureDataset myDataset, IFeatureClass myFeatureClass)<BR> {<BR> IGeoFeatureLayer pGeoFeatureLayer = testOpenMxd();<BR> bool featureLinked = true;<BR> IMap pMap = getMyMap();<BR> IConvertLabelsToAnnotation pConvertLabelsToAnnotation = new ConvertLabelsToAnnotationClass();<BR> ITrackCancel pTrackCancel = new CancelTrackerClass();<BR> pConvertLabelsToAnnotation.Initialize(pMap, esriAnnotationStorageType.esriDatabaseAnnotation,<BR> esriLabelWhichFeatures.esriAllFeatures, true, pTrackCancel, null);<BR> if (pGeoFeatureLayer != null)<BR> {<BR> IFeatureClass pFeatureClass = myFeatureClass;<BR> IDataset pDataset = pFeatureClass as IDataset;</P><BR> <P> IFeatureWorkspace pFeatureWorkspace = pDataset.Workspace as IFeatureWorkspace;<BR> //Add the layer information to the converter object. Specify the parameters of the output annotation feature class here as well.<BR> pConvertLabelsToAnnotation.AddFeatureLayer(pGeoFeatureLayer, "PhaseFlag_Anno",<BR> (IFeatureWorkspace)myWorkspace, myDataset,<BR> featureLinked, false, false, true, true, "");<BR> //Do the conversion.<BR> pConvertLabelsToAnnotation.ConvertLabels();<BR> IEnumLayer pEnumLayer = pConvertLabelsToAnnotation.AnnoLayers;<BR> //Turn off labeling for the layer converted.<BR> pGeoFeatureLayer.DisplayAnnotation = false;<BR> //Add the result annotation layer to the map.<BR> pMap.AddLayers(pEnumLayer, true);<BR> }<BR> }</P><BR> <P> public IMap getMyMap()<BR> {<BR> IMapDocument pMxDoc = new MapDocumentClass();<BR> pMxDoc.Open("C:\\temp\\aaa.mxd", null);<BR> IMap mymap = pMxDoc.get_Map(0);<BR> return mymap;<BR> }</P><BR> <P> public IGeoFeatureLayer testOpenMxd()<BR> {<BR> try<BR> {<BR> IMapDocument pMxDoc = new MapDocumentClass();<BR> pMxDoc.Open("C:\\temp\\aaa.mxd",null);<BR> int y = pMxDoc.MapCount;<BR> IMap map = pMxDoc.get_Map(0);<BR> for (int i = 0; i < map.LayerCount; i++)<BR> {<BR> IGeoFeatureLayer gf = new FeatureLayerClass();<BR> ILayer l = map.get_Layer(i);<BR> if (l is IGeoFeatureLayer)<BR> {<BR> gf = (IGeoFeatureLayer)l;<BR> IFeatureLayer layer = (IFeatureLayer)l;<BR> if (layer.Name == "PhaseFlag")<BR> {<BR> MessageBox.Show("Found phaseflag layer");<BR> break;<BR> }<BR> }<BR> else<BR> {<BR> if (l is ICompositeLayer)<BR> {<BR> ICompositeLayer cl = (ICompositeLayer)l;<BR> for (int j = 0; j < cl.Count; j++)<BR> {<BR> String s = cl.get_Layer(j).Name;<BR> if (cl.get_Layer(j).Name == "Phase Flag")<BR> {<BR> //MessageBox.Show("Found");<BR> IGeoFeatureLayer fLayer = (IGeoFeatureLayer)cl.get_Layer(j);<BR> return fLayer;<BR> }<BR> }<BR> }<BR> }<BR> }<BR> }<BR> catch (Exception e)<BR> {<BR> throw e;<BR> }<BR> return null;</P><BR> <P> } <BR> }<BR>}</P> |
|
1楼#
发布于:2010-01-16 14:44
自己顶一下. 请帮忙!
|
|
2楼#
发布于:2010-01-18 13:37
<P>转换完成后,你要把注记加载到地图上. 参考下面的代码把你的注记加载到地图上. <BR> 'Turn all the labels off<BR> Set pEnumLayer = pMap.Layers(pUID, True)<BR> Set pLayer = pEnumLayer.Next<BR> Do While Not pLayer Is Nothing<BR> Set pGeoFeatureLayer = pLayer<BR> If pGeoFeatureLayer.Valid Then<BR> If pMapLayers.IsLayerVisible(pLayer) Then 'takes scale and group layers into account<BR> If pGeoFeatureLayer.DisplayAnnotation Then<BR> pGeoFeatureLayer.DisplayAnnotation = False<BR> End If<BR> lLyrCount = lLyrCount + 1<BR> End If<BR> End If<BR> Set pLayer = pEnumLayer.Next<BR> Loop<BR> <BR> 'Add annotation to the map<BR> Dim pAnnoEnumLayers As IEnumLayer<BR> Set pAnnoEnumLayers = pConvertLabelsToAnnotation.AnnoLayers<BR> If lLyrCount > 1 Then<BR> 'add anno to a new group layer<BR> Dim pGroupLayer As IGroupLayer<BR> Set pGroupLayer = New GroupLayer<BR> pGroupLayer.name = "anno"<BR> pMap.AddLayer pGroupLayer<BR> pAnnoEnumLayers.Reset<BR> Set pLayer = pAnnoEnumLayers.Next<BR> Do While Not pLayer Is Nothing<BR> pGroupLayer.Add pLayer<BR> Set pLayer = pAnnoEnumLayers.Next<BR> Loop<BR> Else<BR> 'add the single anno layer to the map<BR> pMap.AddLayers pAnnoEnumLayers, True<BR> End If</P>
<P> <BR></P> |
|
|
3楼#
发布于:2010-01-18 13:40
<P>另外你的标注请注意不要设置样式,采用默认的标注符号样式</P>
|
|
|
4楼#
发布于:2010-01-18 15:19
<P>十分感谢! 我的程序中没有加标注吗? 为什么不可以加自己的样式? </P>
|
|
5楼#
发布于:2010-01-18 16:53
如果加自己的样式的话,label和目标的注记层的样式好像必须是一样的,才可以保证转换成功
|
|
|
6楼#
发布于:2010-01-19 04:04
谢谢. 我试试.
|
|
7楼#
发布于:2010-01-19 15:41
<P>我试了, 不知怎么出不来结果. 哪儿可以找到程序的例子或讨论? 多谢多谢!</P>
|
|