merlinda

Problem with ExportfeatureClass

Discussion created by merlinda on Aug 16, 2013
I want to export a selectionset from a specified SDE layer, when get the featureclass via OpenFeatureClass methord, it's ok. But if get the featureclass from the existing layer in arcmap window, an error message prompted "Error exporting Data. Create output feature class failed". Is there any one know why?

The follows code is VBA running in arcmap:
Public Function gf_ErrorCheck(ByVal HwyGate As String, ByVal Rdele As String, ByVal ErrGate As String, _
ByVal sFolder As String, ByVal sFile As String, _
ByVal Server As String, ByVal Instance As String, ByVal user As String, password As String, _
Optional Database As String = "", Optional Version As String = "SDE.DEFAULT") As Boolean
Dim pWorkspace As IWorkspace
Dim pPropSet As IPropertySet
Set pPropSet = New PropertySet
With pPropSet
.SetProperty "SERVER", Server
.SetProperty "INSTANCE", Instance
.SetProperty "DATABASE", Database
.SetProperty "USER", user
.SetProperty "PASSWORD", password
.SetProperty "VERSION", Version
End With


Dim pSdeFact As IWorkspaceFactory
Set pSdeFact = New SdeWorkspaceFactory
Set pWorkspace = pSdeFact.Open(pPropSet, 0)

Dim pFeatureWorkspace As IFeatureWorkspace
Set pFeatureWorkspace = pWorkspace

Dim pFeatureClass1 As IFeatureClass
Dim pFeatLayer As IFeatureLayer
Set pFeatLayer = GetLayer(HwyGate)
Set pFeatureClass1 = pFeatLayer.FeatureClass

  'Set pFeatureClass1 = pFeatureWorkspace.OpenFeatureClass(HwyGate)

Dim pSelectedSet As ISelectionSet
Dim pQF As IQueryFilter
Set pQF = New QueryFilter
pQF.whereClause = "rsname is null"
Set pSelectedSet = pFeatureClass1.Select(pQF, esriSelectionTypeIDSet, esriSelectionOptionNormal, Nothing)
If ExportSelection2SDE(pSelectedSet, pFeatureClass1, "ErrGate", Nothing) = True Then
End If
End Function

Public Function ExportSelection2SDE(ByVal pSelectionSet As ISelectionSet, ByVal pFC As IFeatureClass, _
ByVal strOutName As String, Optional ByVal pQueryFilter As IQueryFilter) As Boolean
On Error GoTo ErrorHandle
Const CSTR_METHOD_NAME As String = "ExportSelection2SDE"

Dim pOutWSName As IWorkspaceName
Dim pInDataset As IDataset
Dim pOutDataset As IDataset

Dim pInDatasetName As IDatasetName
Dim pInFCName As IFeatureClassName
Dim pOutDatasetName As IDatasetName
Dim pOutFCName As IFeatureClassName
Dim pInWSName As IWorkspaceName


Dim pGDef As IGeometryDef
Dim iGeomIndex As Long
Dim sShpName As String
Dim pFields As IFields
Dim pField As IField

Dim pExportOp As IExportOperation

sShpName = pFC.ShapeFieldName
Set pFields = pFC.Fields
iGeomIndex = pFields.FindField(sShpName)
Set pField = pFields.Field(iGeomIndex)
Set pGDef = pField.GeometryDef
Set pInDataset = pFC
Set pInFCName = pInDataset.FullName
Set pInDatasetName = pInFCName

Set pOutWSName = New WorkspaceName
Set pOutFCName = New FeatureClassName
Set pOutDatasetName = pOutFCName
Set pOutDatasetName.WorkspaceName = pInDatasetName.WorkspaceName
pOutDatasetName.Name = strOutName

Set pExportOp = New ExportOperation
pExportOp.ExportFeatureClass pInDatasetName, Nothing, pSelectionSet, pGDef, pOutFCName, 0
ExportSelection2SDE = True

Exit Function
If False Then
ErrorHandle:
ExportSelection2SDE = False

End If
End Function

Outcomes