AristotleCai
路人甲
路人甲
  • 注册日期2005-07-22
  • 发帖数2
  • QQ
  • 铜币109枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2104回复:3

AE中怎么样将label转为Annotation请指教

楼主#
更多 发布于:2005-08-19 11:13
我是AE的初学者,请问下在AE中怎么样将label转为Annotation,并且另外存为一个层,有知道的大侠请指教,不胜感激啊  ..... :)
喜欢0 评分0
ysjGIS
路人甲
路人甲
  • 注册日期2003-11-27
  • 发帖数21
  • QQ
  • 铜币178枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2006-06-20 11:47
谢谢!!!
举报 回复(0) 喜欢(0)     评分
AristotleCai
路人甲
路人甲
  • 注册日期2005-07-22
  • 发帖数2
  • QQ
  • 铜币109枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2005-08-19 15:02
谢谢大哥指教
<P>例子看了 ,谢谢指教,高人就是高人啊</P>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
3楼#
发布于:2005-08-19 12:10
<P>下面是开发帮助里一个例子</P>
<P>How to use: <BR>Add a Geodatabase feature class to ArcMap. Set labeling properties on layer. <BR>Copy/paste the macro code into VBA. <BR>Run the macro. <BR>          </P>
<P>Option Explicit</P>
<P>Const ANNO_FC_NAME = "Conversion01" 'the name that will be used for the new annotation feature class</P>
<P>Public Sub ConvertLabels2Anno()<BR>  'Interface Pointers necessary for accessing basic information about the map<BR>  Dim pMxDoc As IMxDocument<BR>  Dim pMap As IMap<BR>  Dim pAView As IActiveView<BR>  <BR>  'Interface Pointers necessary for getting information about the layer being labeled<BR>  Dim pLayer As ILayer<BR>  Dim pDataset As IDataset<BR>  Dim pAnnotationLayer As IAnnotationLayer<BR>  Dim pGeoFeatureLayer As IGeoFeatureLayer<BR>  Dim pFClass As IFeatureClass<BR>  Dim pAnnoLayer As IAnnotationLayer<BR>  Dim pWorkspace As IWorkspace<BR>  Dim pGeoDataset As IGeoDataset<BR>  Dim pESRILicenseInfo As IESRILicenseInfo<BR>  Dim bIsArcView As Boolean</P>
<P>  'Interface Pointers necessary for setting up the labeling properties for conversion<BR>  Dim pAnnotateLayerPropertiesCollection As IAnnotateLayerPropertiesCollection<BR>  Dim pMapAnnoPropsColl As IAnnotateLayerPropertiesCollection<BR>  Dim pAnnotateLayerProperties As IAnnotateLayerProperties<BR>  Dim pLabelEngineLayerProperties As ILabelEngineLayerProperties2<BR>  Dim pOverposterLayerProperties As IOverposterLayerProperties2<BR>  Dim propsIndex As Long<BR>  Dim pSymbolClone As IClone<BR>  <BR>  'Interface Pointers necessary for creating the annotation feature class<BR>  Dim pRefScale As IGraphicsLayerScale<BR>  Dim pSymCol As ISymbolCollection2<BR>  Dim pSymbolIdentifier As ISymbolIdentifier2<BR>  Dim pAnnotationLayerFactory As IAnnotationLayerFactory<BR>  Dim pAnnoFeatureClassDesc As IFeatureClassDescription<BR>  Dim pAnnoObjectClassDesc As IObjectClassDescription<BR>  Dim pFields As IFields 'pointer needed for pointer needed<BR>  Dim pField As IField<BR>  Dim pGeomDefEdit As IGeometryDefEdit<BR>  <BR>  'Interface Pointers necessary for performing labeling<BR>  Dim pScreenDisplay As IScreenDisplay<BR>  Dim pGraphicsLayer As IGraphicsLayer<BR>  Dim pAnnotateMapProps As IAnnotateMapProperties<BR>  Dim pAnnotateMap2 As IAnnotateMap2<BR>  Dim pTrackCancel As ITrackCancel<BR>  Dim pMapOverposter As IMapOverposter<BR>  Dim pOverposterProperties As IOverposterProperties</P>
<P>  'setup the document, map, and get the first layer<BR>  Set pMxDoc = ThisDocument<BR>  Set pMap = pMxDoc.FocusMap<BR>  Set pLayer = pMap.Layer(0)<BR>  <BR>    'check to make sure map is valid<BR>  If pMap Is Nothing Then<BR>    MsgBox "There is not an active map", vbCritical<BR>    Exit Sub<BR>  End If<BR>  <BR>  'see if the first layer is the proper type<BR>  If TypeOf pLayer Is IGeoFeatureLayer Then<BR>    Set pGeoFeatureLayer = pLayer<BR>  Else<BR>  'throw an error if the first layer is not a GeoFeatureLayer because only layers implementing this interface can be labeled<BR>    MsgBox "First layer in map must be feature layer", vbCritical<BR>  End If</P>
<P>  'check to see if we are beginning with a GDB based layer.  This sample creates an annotation<BR>  'feature class in the same workspace and we can only create annotation in GDB workspaces<BR>  Set pDataset = pGeoFeatureLayer<BR>  Set pWorkspace = pDataset.Workspace<BR>  If pWorkspace.Type = esriFileSystemWorkspace Then<BR>      MsgBox "The layer being labeled is not a layer for a Geodatabase Feature Class.", vbCritical<BR>    Exit Sub<BR>  End If<BR>  <BR>  'see what license we are working with<BR>  Set pESRILicenseInfo = New ESRILicenseInfo<BR>  If pESRILicenseInfo.DefaultProduct = esriProductCodeViewer Then<BR>    bIsArcView = True<BR>  End If<BR>  </P>
<P>  'get a reference to the layers feature class and QI to IGeoDataset to get spatial reference information<BR>  Set pFClass = pGeoFeatureLayer.FeatureClass<BR>  Set pGeoDataset = pFClass<BR>  <BR>  'cocreate a new objects<BR>  Set pAnnotationLayerFactory = New FDOGraphicsLayerFactory 'Factory for creating annotation feature classes<BR>  Set pSymCol = New SymbolCollection 'the symbol collection needed for the annotation feature class<BR>  Set pMapAnnoPropsColl = New AnnotateLayerPropertiesCollection 'a new properties collection which will be populated<BR>  <BR>  'loop through the properties collection of the layer<BR>  'for each item, copy it to the new properties collection,<BR>  'pull the symbol out for the SymbolCollection, and setup the ID<BR>  Set pAnnotateLayerPropertiesCollection = pGeoFeatureLayer.AnnotationProperties<BR>  For propsIndex = 0 To (pAnnotateLayerPropertiesCollection.Count - 1)<BR>    pAnnotateLayerPropertiesCollection.QueryItem propsIndex, pAnnotateLayerProperties<BR>    If Not pAnnotateLayerProperties Is Nothing Then<BR>      pMapAnnoPropsColl.Add pAnnotateLayerProperties<BR>      Set pLabelEngineLayerProperties = pAnnotateLayerProperties<BR>      Set pSymbolClone = pLabelEngineLayerProperties.Symbol<BR>      pSymCol.AddSymbol pSymbolClone.Clone, pAnnotateLayerProperties.Class  ; " " ;  propsIndex, pSymbolIdentifier<BR>      pLabelEngineLayerProperties.SymbolID = pSymbolIdentifier.ID<BR>    End If<BR>  Next propsIndex<BR>  <BR>  'clear the pointers for later use in the sub<BR>  Set pAnnotateLayerProperties = Nothing<BR>  Set pLabelEngineLayerProperties = Nothing<BR>  <BR>  'setup GraphicsLayerScale for use in creating the annotation feature class<BR>  Set pRefScale = New GraphicsLayerScale<BR>  If pMap.ReferenceScale = 0 Then<BR>    pRefScale.ReferenceScale = pMap.MapScale<BR>  Else<BR>    pRefScale.ReferenceScale = pMap.ReferenceScale<BR>  End If<BR>  pRefScale.Units = pMap.MapUnits<BR>  <BR>  'Use AnnotationFeatureClassDescription to get the list of fields needed for the annotation feature class<BR>  'Also, pull out the shape field and setup the spatial reference to equal the base feature layer<BR>  Set pAnnoFeatureClassDesc = New AnnotationFeatureClassDescription<BR>  Set pAnnoObjectClassDesc = pAnnoFeatureClassDesc<BR>  Set pFields = pAnnoObjectClassDesc.RequiredFields<BR>  Set pField = pFields.Field(pFields.FindField(pAnnoFeatureClassDesc.ShapeFieldName)) 'get the field definition for the shape field<BR>  Set pGeomDefEdit = pField.GeometryDef 'get the geometry defintion for the field<BR>  Set pGeomDefEdit.SpatialReference = pGeoDataset.SpatialReference 'set the spatial reference on the field<BR>  <BR>  'get the overposter (label engine) properties from the map<BR>  Set pMapOverposter = pMap<BR>  Set pOverposterProperties = pMapOverposter.OverposterProperties<BR>  <BR>  'Now, create the annotation feature class with this method by passing in all the information<BR>  'a reference to the layer is returned so that we can populate the feature class<BR>  'The ArcView license case does not have to be treated differently here because the Factory internally<BR>  'handles it.  If working with an ArcView license, only one annotation class will be created<BR>  'Pass in Nothing for the related feature class because this sample does not create feature-linked anno<BR>  Set pAnnoLayer = pAnnotationLayerFactory.CreateAnnotationLayer(pWorkspace, pFClass.FeatureDataset, _<BR>  ANNO_FC_NAME, pGeomDefEdit, Nothing, pMapAnnoPropsColl, pRefScale, pSymCol, True, True, False, True, pOverposterProperties, "")</P>
<P>  'activate the graphics container (AnnoLayer) for adding elements.<BR>  Set pAView = pMap<BR>  Set pScreenDisplay = pAView.ScreenDisplay<BR>  Set pGraphicsLayer = pAnnoLayer<BR>  pGraphicsLayer.Activate pScreenDisplay<BR>    <BR>  'Prepare the annotation properties for label placement<BR>  For propsIndex = 0 To (pMapAnnoPropsColl.Count - 1)<BR>    pMapAnnoPropsColl.QueryItem propsIndex, pAnnotateLayerProperties       'get the properties from the collection<BR>    If Not pAnnotateLayerProperties Is Nothing Then<BR>      Set pAnnotateLayerProperties.FeatureLayer = pGeoFeatureLayer         'point the properties to the feature layer<BR>      Set pAnnotateLayerProperties.GraphicsContainer = pAnnoLayer          'set the AnnoLayer as the destination for the labels<BR>      pAnnotateLayerProperties.AddUnplacedToGraphicsContainer = True       'add the unplaced labels to the Annotation Feature Class<BR>      pAnnotateLayerProperties.CreateUnplacedElements = True               'ALWAYS create unplaced elements<BR>      pAnnotateLayerProperties.DisplayAnnotation = True                    'turn on the label class if it isn't already<BR>      pAnnotateLayerProperties.FeatureLinked = False                       'This sample creates standard annotation, so set this to false<BR>      pAnnotateLayerProperties.LabelWhichFeatures = esriAllFeatures        'this creates labels/anno for the full extent. This can be changed to produce labels for the current extent, selection etc<BR>      pAnnotateLayerProperties.UseOutput = True                            ' yes, we want to produce elements<BR>      Set pLabelEngineLayerProperties = pAnnotateLayerProperties           'QI to LabelEngineLayerProperties<BR>      pLabelEngineLayerProperties.SymbolID = propsIndex           'Since a New Annotation FeatureClass was created, the propsIndex will be the same as the SymbolID<BR>      'ArcView does not support multiple annotation classes, therefore see if we have an ArcView license<BR>      'and set the AnnotationClassID to 0 if it is ArcView, so annotation features are assigned to the proper class<BR>        If bIsArcView Then<BR>          pLabelEngineLayerProperties.AnnotationClassID = 0<BR>        Else<BR>          pLabelEngineLayerProperties.AnnotationClassID = propsIndex<BR>        End If<BR>      Set pOverposterLayerProperties = pLabelEngineLayerProperties.OverposterLayerProperties 'Get the overposter layer properties from the LabelEngineLayerProps<BR>      pOverposterLayerProperties.TagUnplaced = True               'add unplaced labels as unplaced (true) or placed (false)<BR>    End If<BR>  Next propsIndex<BR>  <BR>  'sort the collection so labels are placed in the proper order<BR>  pMapAnnoPropsColl.Sort<BR>  <BR>  'populate AnnotateMapProperties with the prepared collection<BR>  Set pAnnotateMapProps = New AnnotateMapProperties<BR>  Set pAnnotateMapProps.AnnotateLayerPropertiesCollection = pMapAnnoPropsColl<BR>  <BR>  <BR>  Set pTrackCancel = New CancelTracker 'cocreat a cancel tracker<BR>  <BR>  'get the current AnnotateMap object from the map<BR>  'this ensures we are using the proper label engine<BR>  Set pAnnotateMap2 = pMap.AnnotationEngine<BR>  <BR>  'Now, call Label which will populate the annotation feature class with labels based on the properties we setup<BR>  'The Label method know to put the labels in the annotation feature class because we specified the Anno Layer<BR>  'as the destination GraphicsContainer in the above preparation loop<BR>  pAnnotateMap2.Label pOverposterProperties, pAnnotateMapProps, pMap, pTrackCancel<BR>  <BR>  'release the feature layer reference in the properties collection to be safe<BR>  'in some cases, not doing this would lead to a circular reference<BR>  For propsIndex = 0 To (pMapAnnoPropsColl.Count - 1)<BR>    pMapAnnoPropsColl.QueryItem propsIndex, pAnnotateLayerProperties<BR>    If Not pAnnotateLayerProperties Is Nothing Then<BR>      Set pAnnotateLayerProperties.FeatureLayer = Nothing<BR>    End If<BR>  Next propsIndex<BR>  <BR>  'add layer to map and turn off labeling of feature layer<BR>  pMap.AddLayer pAnnoLayer<BR>  pGeoFeatureLayer.DisplayAnnotation = False</P>
<P>  'refresh the map<BR>  Set pAView = pMap<BR>  pAView.Refresh<BR>  <BR>End Sub</P>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部