[Visual Basic 6.0]The following example is a routine that accepts an input IFeatureClassName, and output IFeatureClassName and an IQueryFilter. It uses IFeatureClass::CreateFeature and IFeature::Store to mimic an edit session and append the features from the input feature class that satisfy the input query filter to the output feature class. Because it is done within an edit session, this script can be used to append features to feature classes in a geometric network or topology.
Public 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 True 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
[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button
in the upper-left corner of the page.