I have a shapefile with polygons. I can merge them manually by going into edit session and, selecting a some features to be merged, and then using merge button under Editor.
How to do this programmatically (in VBA)?
I've found the analogous ways but it doesn't solve the problem:
- Standard Dissolve tool (from ArcToolbox) doesn't work correctly for this purpose, because it cuts off many fields and because it operates with whole FeatureClass but not with a separate features.
- As I know by reading some examples, using an IBasicGeoprocessor (VBA) have the same problem - it operates with whole FeatureClass, producing a new FeatureClass, but not with separate features, mearging them within the same FeatureClass.
@kenbuja, Here is my try in vba (not in vb.net) : Using a CType causes the Compile error: Sub or Function not defined. What do I do wrong?
Dim pMxDoc As IMxDocument
Dim pCountyLayer As IFeatureSelection
Dim pCountySelection As ISelectionSet
Dim pCountyCursor As IFeatureCursor
Dim pCountyCursor2 As IFeatureCursor
Dim pFirstFeature As IFeature
Dim pSecondFeature As IFeature
Dim pThirdFeature As IFeature
Set pMxDoc = ThisDocument
Set pCountyLayer = pMxDoc.FocusMap.Layer(1)
Set pCountySelection = pCountyLayer.SelectionSet
' Create a cursors from the selected feature in Layer (1).
pCountySelection.Search Nothing, True, pCountyCursor
pCountySelection.Search Nothing, True, pCountyCursor2
' Return the selected features from the cursor.
Set pFirstFeature = pCountyCursor.NextFeature
Set pThirdFeature = pCountyCursor2.NextFeature
Set pSecondFeature = pCountyCursor2.NextFeature
Dim pFirstGeometry As IGeometry
Set pFirstGeometry = CType(pFirstFeature.Shape, IGeometry)
Dim pTopoOperator As ITopologicalOperator
Set pTopoOperator = CType(pFirstGeometry, ITopologicalOperator)
Dim pSecondGeom As IGeometry
Set pSecondGeom = CType(pSecondFeature.Shape, IGeometry)
Dim pMergedGeom As IGeometry
Set pMergedGeom = pTopoOperator.Union(pSecondGeom)