axlzydh
路人甲
路人甲
  • 注册日期2004-11-15
  • 发帖数40
  • QQ
  • 铜币239枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2163回复:7

用代码创建FeatureClass在SDE中出错,如何解释?附源码

楼主#
更多 发布于:2005-01-06 12:36
<P>各位,我用VB写的创建FeatureClass,并加载图层。创建FeatureClass时在SDE中出错,说是License不能创建,如何解释?有没有解决办法呢?</P>

<P>源码如下:</P>
<P>Public Function CreateTemplateLayer(pFeatureDataset As esriGeoDatabase.IFeatureDataset, _
            ClassName As String, AliasName As String, _
            Optional FeatureType As esriGeoDatabase.esriFeatureType = esriFTSimple, _
            Optional GeometryType As esriGeometry.esriGeometryType = esriGeometryPolygon, _
            Optional pFields As esriGeoDatabase.IFields, _
            Optional pCLSID As UID, _
            Optional pCLSEXT As UID, _
            Optional ConfigWord As String = "") As Boolean
    On Error GoTo ExitH
    Dim pFeatureLayer As esriCarto.IFeatureLayer
    Dim pFeatureClass As esriGeoDatabase.IFeatureClass
    Dim pFieldsEdit As esriGeoDatabase.IFieldsEdit
    Dim pGeomDef As esriGeoDatabase.IGeometryDef
    Dim pGeomDefEdit As esriGeoDatabase.IGeometryDefEdit
    Dim pField As esriGeoDatabase.IField
    Dim pFieldEdit As esriGeoDatabase.IFieldEdit</P>
<P>    Dim strShapeFld As String
    Dim i As Long</P>
<P>    CreateTemplateLayer = False
    If pFeatureDataset Is Nothing Then Exit Function
    If MapControl.Map Is Nothing Then Exit Function
    If Trim$(ClassName) = "" Then Exit Function
    If Trim$(AliasName) = "" Then Exit Function</P>
<P>    If (pCLSID Is Nothing) Or IsMissing(pCLSID) Then
        Set pCLSID = Nothing
        Set pCLSID = New UID</P>
<P>        Select Case FeatureType
            Case esriFTSimple
                pCLSID.Value = "esriGeoDatabase.Feature"
            Case esriFTSimpleJunction
                GeometryType = esriGeometryPoint
                pCLSID.Value = "esriGeoDatabase.SimpleJunctionFeature"
            Case esriFTComplexJunction
                pCLSID.Value = "esriGeoDatabase.ComplexJunctionFeature"
            Case esriFTSimpleEdge
                GeometryType = esriGeometryPolyline
                pCLSID.Value = "esriGeoDatabase.SimpleEdgeFeature"
            Case esriFTComplexEdge
                GeometryType = esriGeometryPolyline
                pCLSID.Value = "esriGeoDatabase.ComplexEdgeFeature"
            Case esriFTAnnotation
                Exit Function
        End Select
    End If</P>
<P>
    If (pFields Is Nothing) Or IsMissing(pFields) Then
        Set pFieldsEdit = New esriGeoDatabase.Fields</P>
<P>        Set pGeomDef = New esriGeoDatabase.GeometryDef
        Set pGeomDefEdit = pGeomDef</P>
<P>        With pGeomDefEdit
            .GeometryType = GeometryType
            .GridCount = 1
            .GridSize(0) = 10
            .AvgNumPoints = 2
            .HasM = False
            .HasZ = False
        End With</P>
<P>        Set pField = New esriGeoDatabase.Field
        Set pFieldEdit = pField
        pFieldEdit.Name = "OBJECTID"
        pFieldEdit.AliasName = "object identifier"
        pFieldEdit.Type = esriFieldTypeOID
        pFieldsEdit.AddField pField
        
        Set pField = New esriGeoDatabase.Field
        Set pFieldEdit = pField
        pFieldEdit.Name = "SHAPE"
        pFieldEdit.AliasName = "geometry"
        pFieldEdit.Type = esriFieldTypeGeometry
        Set pFieldEdit.GeometryDef = pGeomDef
        pFieldsEdit.AddField pField
        
        Set pFields = pFieldsEdit
    End If</P>
<P>    If (pCLSEXT Is Nothing) Or IsMissing(pCLSEXT) Then
        Set pCLSEXT = Nothing
    End If</P>
<P>    For i = 0 To pFields.FieldCount - 1
        If pFields.Field(i).Type = esriFieldTypeGeometry Then
            strShapeFld = pFields.Field(i).Name
        End If
    Next</P>
<P>     Set pFeatureClass = pFeatureDataset.CreateFeatureClass(ClassName, pFields, pCLSID, pCLSEXT, FeatureType, strShapeFld, ConfigWord)
    If Not pFeatureClass Is Nothing Then
        Set pFeatureLayer = New esriCarto.FeatureLayer
        Set pFeatureLayer.FeatureClass = pFeatureClass
        pFeatureLayer.Name = AliasName 'pFeatureLayer.FeatureClass.AliasName
        MapControl.Map.AddLayer pFeatureLayer
    End If</P>
<P>    CreateTemplateLayer = True</P>
<P>    Set pFeatureLayer = Nothing
    Set pFeatureClass = Nothing
    Set pFieldsEdit = Nothing
    Set pGeomDef = Nothing
    Set pGeomDefEdit = Nothing
    Set pField = Nothing
    Set pFieldEdit = Nothing
    Exit Function
ExitH:
    CreateTemplateLayer = False</P>
<P>    Set pFeatureLayer = Nothing
    Set pFeatureClass = Nothing
    Set pFieldsEdit = Nothing
    Set pGeomDef = Nothing
    Set pGeomDefEdit = Nothing
    Set pField = Nothing
    Set pFieldEdit = Nothing
End Function</P>
喜欢0 评分0
axlzydh
路人甲
路人甲
  • 注册日期2004-11-15
  • 发帖数40
  • QQ
  • 铜币239枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2005-01-06 12:39

[此贴子已经被作者于2005-1-6 12:42:50编辑过]
举报 回复(0) 喜欢(0)     评分
wavvylia
路人甲
路人甲
  • 注册日期2003-07-28
  • 发帖数384
  • QQ
  • 铜币555枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2005-01-07 16:10
<P>用这个吧,这个经过测试过的。</P><P>Public Function CreateDatasetFeatureClass(pFDS As esriGeoDatabase.IFeatureDataset, _
      Name As String, featType As esriFeatureType, _
      Optional geomType As esriGeometryType = esriGeometryPoint, _
      Optional pFields As IFields, _
      Optional pCLSID As esriSystem.UID, _
      Optional pCLSEXT As esriSystem.UID, _
      Optional ConfigWord As String = "" _
      ) As esriGeoDatabase.IFeatureClass
  
   '' createDatasetFeatureClass: simple helper to create a featureclass in a geodatabase Dataset.
   '' NOTE: when creating a feature class in a dataset the spatial reference is inherited
   '' from the dataset object
   ''
   Dim pFieldsEdit As esriGeoDatabase.IFieldsEdit
   Dim pGeomDef As IGeometryDef
   Dim pGeomDefEdit As IGeometryDefEdit
   Dim pField As iField
   Dim pFieldEdit As IFieldEdit
   Dim strShapeFld As String
   Dim j As Integer
  
   On Error GoTo eh
  
   Set CreateDatasetFeatureClass = Nothing</P><P>   If pFDS Is Nothing Then Exit Function</P><P>   If Name = "" Then Exit Function
  
   If (pCLSID Is Nothing) Or VBA.IsMissing(pCLSID) Then</P><P>      Set pCLSID = Nothing
      Set pCLSID = New UID
    
      '' determine the appropriate geometry type corresponding the the feature type</P><P>      Select Case featType</P><P>         Case esriFTSimple
            pCLSID.Value = "esriGeoDatabase.Feature"</P><P>         Case esriFTSimpleJunction
            geomType = esriGeometryPoint
            pCLSID.Value = "esriGeoDatabase.SimpleJunctionFeature"</P><P>         Case esriFTComplexJunction
            pCLSID.Value = "esriGeoDatabase.ComplexJunctionFeature"</P><P>         Case esriFTSimpleEdge
            geomType = esriGeometryPolyline
            pCLSID.Value = "esriGeoDatabase.SimpleEdgeFeature"</P><P>         Case esriFTComplexEdge
            geomType = esriGeometryPolyline
            pCLSID.Value = "esriGeoDatabase.ComplexEdgeFeature"</P><P>         Case esriFTAnnotation
            Exit Function</P><P>      End Select</P><P>   End If
  
   ' establish a fields collection</P><P>   If (pFields Is Nothing) Or VBA.IsMissing(pFields) Then</P><P>      Set pFieldsEdit = New esriGeoDatabase.Fields
      ''
      '' create the geometry field
      Set pGeomDef = New GeometryDef
      Set pGeomDefEdit = pGeomDef
    
      '' assign the geometry definiton properties.</P><P>      With pGeomDefEdit
         .GeometryType = geomType
         .GridCount = 1
         .GridSize(0) = 10
         .AvgNumPoints = 2
         .HasM = False
         .HasZ = False
      End With
    
      Set pField = New Field
      Set pFieldEdit = pField
    
      pFieldEdit.Name = "shape"
      pFieldEdit.AliasName = "geometry"
      pFieldEdit.Type = esriFieldTypeGeometry
      Set pFieldEdit.GeometryDef = pGeomDef
      pFieldsEdit.AddField pField</P><P>      '' create the object id field
      Set pField = New Field
      Set pFieldEdit = pField
      pFieldEdit.Name = "OBJECTID"
      pFieldEdit.AliasName = "object identifier"
      pFieldEdit.Type = esriFieldTypeOID
      pFieldsEdit.AddField pField</P><P>      Set pFields = pFieldsEdit
   End If
  
   ' establish the class extension</P><P>   If (pCLSEXT Is Nothing) Or VBA.IsMissing(pCLSEXT) Then</P><P>      Set pCLSEXT = Nothing
   End If
  
   ' locate the shape field</P><P>   For j = 0 To pFields.FieldCount - 1</P><P>      If pFields.Field(j).Type = esriFieldTypeGeometry Then</P><P>         strShapeFld = pFields.Field(j).Name
      End If</P><P>   Next
  
   Set CreateDatasetFeatureClass = pFDS.CreateFeatureClass(Name, pFields, pCLSID, pCLSEXT, featType, strShapeFld, ConfigWord)
  
   Exit Function
eh:
   MsgBox Err.Description, vbInformation, "CreateDatasetFeatureClass"</P><P>End Function
</P>
举报 回复(0) 喜欢(0)     评分
axlzydh
路人甲
路人甲
  • 注册日期2004-11-15
  • 发帖数40
  • QQ
  • 铜币239枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2005-01-10 13:15
这位仁兄,你给我的就是帮助里自带的例子,我看过的。如果对SDE可以,我还用问吗?我早就做过测试了。
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
4楼#
发布于:2005-01-12 18:43
<P>你是用arcengine做的吗,需要gdb read/write许可</P><P>9以前的版本,请完全安装,如果是arcview的话,好象是没有编辑geodatabase的许可的</P>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
wavvylia
路人甲
路人甲
  • 注册日期2003-07-28
  • 发帖数384
  • QQ
  • 铜币555枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2005-01-13 09:17
<DIV class=quote><B>以下是引用<I>axlzydh</I>在2005-1-10 13:15:13的发言:</B>
这位仁兄,你给我的就是帮助里自带的例子,我看过的。如果对SDE可以,我还用问吗?我早就做过测试了。</DIV>
<P>这个人真是的,这个例子我是测试过的,并且创建成功了,你运行不成功为什么不检查一下自己的代码呢?还不屑一顾的样子,唉,心寒!</P><img src="images/post/smile/dvbbs/em15.gif" />
举报 回复(0) 喜欢(0)     评分
wavvylia
路人甲
路人甲
  • 注册日期2003-07-28
  • 发帖数384
  • QQ
  • 铜币555枚
  • 威望0点
  • 贡献值0点
  • 银元0个
6楼#
发布于:2005-01-13 09:21
如果代码没错的话那就是你的License许可不全!所以说原因还是出在你那边,而不是例子中代码的缘故!
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
7楼#
发布于:2005-01-15 10:54
楼上所说不差,问问题还要有点礼貌才行
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部