ysjGIS
路人甲
路人甲
  • 注册日期2003-11-27
  • 发帖数21
  • QQ
  • 铜币178枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1403回复:0

[原创]在线等,用CreateAnnotationLayer创建标注图层时总是提示:自动化错误

楼主#
更多 发布于:2006-06-22 08:15
 
<P>arcengine一个自带的例子.我想建一个标注图层,程序运行到CreateAnnotationLayer总提示自动化错误,请高手指点</P>
<P>代码如下:</P>
<P>Public Sub ConvertLabels2Anno(pFeatLayer As ILayer)                                'pFeatLayer为一个点图层,我要将它转为标注图层.<BR>  'Interface Pointers necessary for accessing basic information about the map<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 esriGeoDatabase.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>  On Error GoTo ConvertErr:<BR>  'setup the document, map, and get the first layer<BR>  <BR>  Set pMap = g_MapControl.Map<BR>  Set pLayer = pFeatLayer<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>  <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>  <BR>  <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</P>
<P><BR><FONT color=#000000>      Debug.Print propsIndex ; "个符号大小:" ; pLabelEngineLayerProperties.Symbol.SIZE<BR>      Debug.Print propsIndex ; "个符号文本:" ; pLabelEngineLayerProperties.Symbol.Text<BR>      Debug.Print propsIndex ; "个符号角度:" ; pLabelEngineLayerProperties.Symbol.Angle</FONT></P>
<P><FONT color=#3809f7>'在此,symbol的大小、文本、角度都有内容。</FONT><BR>      pSymCol.AddSymbol pSymbolClone.Clone, pAnnotateLayerProperties.Class ; " " ; propsIndex, pSymbolIdentifier<BR>      <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</P>
<P><BR>  Set pAnnoFeatureClassDesc = New AnnotationFeatureClassDescription<BR>  Set pAnnoObjectClassDesc = pAnnoFeatureClassDesc<BR>  Set pFields = pAnnoObjectClassDesc.RequiredFields<BR>  </P>
<P>  Dim lGeomIndex  As Long<BR>  lGeomIndex = pFields.FindField(pAnnoFeatureClassDesc.ShapeFieldName)<BR>  <BR>  Set pField = pFields.Field(lGeomIndex) '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</P>
<P><BR>  Set pMapOverposter = pMap<BR>  Set pOverposterProperties = pMapOverposter.OverposterProperties<BR>    <BR>    Debug.Print "标注图层中标注个数" ; pMapAnnoPropsColl.Count<BR>    Debug.Print "标注号符个数:" ; pSymCol.Count<BR>    Debug.Print "Dataset名称:" ; pFClass.FeatureDataset.Name<BR>    Debug.Print "图层名称:" ; pFeatLayer.Name<BR>    Debug.Print "overposter名称:" ; pOverposterProperties.Name<BR>    <BR><FONT color=#113dee>    '在此,各变量的内容都有。</FONT><BR>    <BR><FONT color=#ee3d11>  Set pAnnoLayer = pAnnotationLayerFactory.CreateAnnotationLayer(pWorkSpace, pFClass.FeatureDataset, _<BR>  "testannonation", pGeomDefEdit, Nothing, pMapAnnoPropsColl, pRefScale, pSymCol, True, True, False, True, pOverposterProperties, "")                         </FONT><FONT color=#113dee>  '程序运行到这里,提示“自动化错误”</FONT></P>
<P>....................</P>
<P> 在立即窗口中结果:</P>
<P>0个符号大小:21.5788786109562<BR>0个符号文本:53.50<BR>0个符号角度:0<BR>1个符号大小:21.5788786109562<BR>1个符号文本:53.30<BR>1个符号角度:318.83<BR>标注图层中标注个数2<BR>标注号符个数:2<BR>Dataset名称:sde.SDE.ydhx<BR>图层名称:ydhx_002_001<BR>overposter名称:ESRI Standard Label Engine</P>
喜欢0 评分0
游客

返回顶部