将input featureclass里的选择集feature插入到output featureclass里
使用IFeatureClass.createfeature和feature.store方法來逐個添加新要素,適用于簡單的少量的插入操作。
數據量較大時,其效率過低。
Public Sub t_InsertRecords() Sub t_InsertRecords()Sub t_InsertRecords()Sub t_InsertRecords(pFeatclsNm As IFeatureClassName, _
pInputFCName As IFeatureClassName, _
pQFilt As IQueryFilter)
' +++ Note: this function assumes that the schema between the input feature class and
' the destination feature class are the same. If they are not, then this
' function will always report errors.
' get the feature classes from the name
Dim pFName As IName
Dim pInputName As IName
Set pFName = pFeatclsNm
Set pInputName = pInputFCName
Dim pFeatcls As IFeatureClass
Dim pInputFCls As IFeatureClass
Set pFeatcls = pFName.Open
Set pInputFCls = pInputName.Open
' get the workspace and start editing
Dim pDataset As IDataset
Set pDataset = pFeatcls
Dim pWorkspace As IWorkspace
Set pWorkspace = pDataset.Workspace
Dim pWorkspaceEdit As IWorkspaceEdit
Set pWorkspaceEdit = pWorkspace
pWorkspaceEdit.StartEditing False
pWorkspaceEdit.StartEditOperation
' open a cursor on the input feature class with the given query filter
Dim pFeatCursor As IFeatureCursor
Set pFeatCursor = pInputFCls.Search(pQFilt, False)
' loop through the input features in the cursor, and insert
' them into the destination feature class. This is slow since we must use
' IFeature::Store to mimic an edit session.
Dim pFeat As IFeature
Dim pRow As IRow
Dim pFlds As IFields
Dim lSFld As Long
Dim i As Long
Set pRow = pFeatCursor.NextFeature
Do Until pRow Is Nothing
Set pFeat = pFeatcls.CreateFeature
Set pFlds = pFeat.Fields
For i = 0 To pFlds.FieldCount - 1
lSFld = pRow.Fields.FindField(pFlds.Field(i).Name)
pFeat.Value(i) = pRow.Value(lSFld)
Next i
pFeat.Store
' get next row
Set pRow = pFeatCursor.NextFeature
Loop
pWorkspaceEdit.StopEditOperation
pWorkspaceEdit.StopEditing True
End Sub