在featureDataset和workspace下創建featureclass

在featureDataset里创建新的featureclass

ExpandedBlockStart.gif ContractedBlock.gif Public   Function createDatasetFeatureClass() Function createDatasetFeatureClass(pFDS As IFeatureDataset, _
                                          Name 
As String, featType As esriFeatureType, _ 
                                          
Optional geomType As esriGeometryType = esriGeometryPoint, _  
                                          
Optional pfields As IFields, _
                                          
Optional pCLSID As UID, _
                                          
Optional pCLSEXT As UID, _ 
                                          
Optional ConfigWord As String = "" _
                                          ) 
As 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 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
  
If pFDS Is Nothing Then Exit Function
  
If Name = "" Then Exit Function
  
  
If (pCLSID Is NothingOr IsMissing(pCLSID) Then
    
Set pCLSID = Nothing
    
Set pCLSID = New UID
    
    
'' determine the appropriate geometry type corresponding the the feature type
    Select Case featType
      
Case esriFTSimple
        pCLSID.Value 
= "esriGeoDatabase.Feature"
      
Case esriFTSimpleJunction
        geomType 
= esriGeometryPoint
        pCLSID.Value 
= "esriGeoDatabase.SimpleJunctionFeature"
      
Case esriFTComplexJunction
        pCLSID.Value 
= "esriGeoDatabase.ComplexJunctionFeature"
      
Case esriFTSimpleEdge
        geomType 
= esriGeometryPolyline
        pCLSID.Value 
= "esriGeoDatabase.SimpleEdgeFeature"
      
Case esriFTComplexEdge
        geomType 
= esriGeometryPolyline
        pCLSID.Value 
= "esriGeoDatabase.ComplexEdgeFeature"
      
Case esriFTAnnotation
        
Exit Function
    
End Select
  
End If
  
  
' establish a fields collection
  If (pfields Is NothingOr IsMissing(pfields) Then
    
Set pFieldsEdit = New Fields
    
''
    '' create the geometry field
    Set pGeomDef = New GeometryDef
    
Set pGeomDefEdit = pGeomDef
    
    
'' assign the geometry definiton properties.
    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

    
'' 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

    
Set pfields = pFieldsEdit
  
End If
  
  
' establish the class extension
  If (pCLSEXT Is NothingOr IsMissing(pCLSEXT) Then
    
Set pCLSEXT = Nothing
  
End If
  
  
' locate the shape field
  For j = 0 To pfields.FieldCount - 1
    
If pfields.Field(j).Type = esriFieldTypeGeometry Then
      strShapeFld 
= pfields.Field(j).Name
    
End If
  
Next
  
  
Set createDatasetFeatureClass = pFDS.CreateFeatureClass(Name, pfields, pCLSID, pCLSEXT, featType, strShapeFld, ConfigWord)
  
  
Exit Function
EH:
    
MsgBox Err.Description, vbInformation, "createDatasetFeatureClass"
End Function

 

 在工作区间(Workspace)创建新的featureclass

ExpandedBlockStart.gif ContractedBlock.gif Public   Function createWorkspaceFeatureClass() Function createWorkspaceFeatureClass(featWorkspace As IFeatureWorkspace, _
                                            Name 
As String, _
                                            featType 
As esriFeatureType, _
                                            
Optional geomType As esriGeometryType = esriGeometryPoint, _
                                            
Optional pfields As IFields, _
                                            
Optional pCLSID As UID, _
                                            
Optional pCLSEXT As UID, _
                                            
Optional ConfigWord As String = "" _
                                            ) 
As IFeatureClass
  
  
On Error GoTo EH
  
  
Set createWorkspaceFeatureClass = Nothing
  
If featWorkspace Is Nothing Then Exit Function
  
If Name = "" Then Exit Function
  
  
If (pCLSID Is NothingOr IsMissing(pCLSID) Then
    
Set pCLSID = Nothing
    
Set pCLSID = New UID
    
    
'' determine the appropriate geometry type corresponding the the feature type
    Select Case featType
      
Case esriFTSimple
        pCLSID.Value 
= "esricore.Feature"
        
If geomType = esriGeometryLine Then geomType = esriGeometryPolyline
      
Case esriFTSimpleJunction
        geomType 
= esriGeometryPoint
        pCLSID.Value 
= "esricore.SimpleJunctionFeature"
      
Case esriFTComplexJunction
        pCLSID.Value 
= "esricore.ComplexJunctionFeature"
      
Case esriFTSimpleEdge
        geomType 
= esriGeometryPolyline
        pCLSID.Value 
= "esricore.SimpleEdgeFeature"
      
Case esriFTComplexEdge
        geomType 
= esriGeometryPolyline
        pCLSID.Value 
= "esricore.ComplexEdgeFeature"
      
Case esriFTAnnotation
        
Exit Function
    
End Select
  
End If
  
  
' establish a fields collection
  If (pfields Is NothingOr IsMissing(pfields) Then
    
Dim pFieldsEdit As esriCore.IFieldsEdit
    
Set pFieldsEdit = New esriCore.Fields
    
    
''
    '' create the geometry field
    ''
    Dim pGeomDef As IGeometryDef
    
Set pGeomDef = New GeometryDef
    
Dim pGeomDefEdit As IGeometryDefEdit
    
Set pGeomDefEdit = pGeomDef
    
    
' assign the spatial reference
    Dim pSR As ISpatialReference
    
Set pSR = New esriCore.UnknownCoordinateSystem
    pSR.SetDomain 
021474.83645021474.83645
    pSR.SetFalseOriginAndUnits 
00100000
    
    
'' assign the geometry definiton properties.
    With pGeomDefEdit
      .GeometryType 
= geomType
      .GridCount 
= 1
      .gridSize(
0= 10
      .AvgNumPoints 
= 2
      .hasM 
= False
      .hasZ 
= False
      
Set .SpatialReference = pSR
    
End With
    
    
Dim pField As IField
    
Dim pFieldEdit As IFieldEdit
    
Set pField = New Field
    
Set pFieldEdit = pField
    
    pFieldEdit.Name 
= "shape"
    pFieldEdit.AliasName 
= "geometry"
    pFieldEdit.Type 
= esriFieldTypeGeometry
    
Set pFieldEdit.GeometryDef = pGeomDef
    pFieldsEdit.addField pField
    
    
''
    '' 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

    
Set pfields = pFieldsEdit
  
End If
  
  
' establish the class extension
  If (pCLSEXT Is NothingOr IsMissing(pCLSEXT) Then
    
Set pCLSEXT = Nothing
  
End If
  
  
' locate the shape field
  Dim strShapeFld As String
  
Dim j As Integer
  
For j = 0 To pfields.FieldCount - 1
    
If pfields.Field(j).Type = esriFieldTypeGeometry Then
      strShapeFld 
= pfields.Field(j).Name
    
End If
  
Next
  
  
Set createWorkspaceFeatureClass = featWorkspace.CreateFeatureClass(Name, pfields, pCLSID, _
                             pCLSEXT, featType, strShapeFld, ConfigWord)
  
  
Exit Function
EH:
    
MsgBox Err.Description, vbInformation, "createWorkspaceFeatureClass"
End Function

 

转载于:https://www.cnblogs.com/iswszheng/archive/2009/03/18/1415116.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值