Select Multiple Polygons and then Merging them

4049
6
04-12-2015 08:34 PM
bobbycorpuz
New Contributor II

Good day everyone, can somebody help me with my problem? I want to Select Multiple Polygons from the same layer and merging it after the selection (programatically). I am using arcmap 10.1 and vba as my coding environment. Tnx in advance for your help.

Tags (1)
0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

Programmatically...using vba? are you working in Desktop or elsewhere?

0 Kudos
bobbycorpuz
New Contributor II

yes sir Dan Patterson​... i am working with Desktop.

0 Kudos
bobbycorpuz
New Contributor II

highlighted.png

for example sir. i want to merge those highlighted parcels programmatically. Can you please send me some vba codes?

And before that i use this code to highlight them manually.

HIGHLIGHTED CODE:

Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)

Dim pMxDoc As IMxDocument

Set pMxDoc = ThisDocument

Dim SearchTol As Double

Dim pPoint As IPoint

  Set pPoint = pMxDoc.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y)

 

  'Pass the point to the FindBoundary function along with the Map and search tolerance

  SearchTol = pMxDoc.SearchTolerance

  FindBoundary SearchTol, pPoint, pMxDoc.FocusMap

 

  'Message box the feature ID and feature class alias name

  

  'MsgBox pFeature.OID & " " & pFeature.Class.AliasName

pMxDoc.ActiveView.Refresh

End Sub

Private Function FindBoundary(SearchTol As Double, pPoint As IPoint, pMap As IMap)

'** This function is called by the subroutine SelectBoundary_MouseDown

'** this selects the boundary based on the click event of the user

    Dim pFeatSel As IFeatureSelection

  Dim pEnvelope As IEnvelope

  Dim pSpatialFilter As ISpatialFilter

  Dim pEnumLayer As IEnumLayer

  Dim pFeatureLayer As IFeatureLayer

  Dim pFeatureClass As IFeatureClass

  Dim pUID As New uid

  Dim pFeatureCursor As IFeatureCursor

  Dim pFeature As IFeature

  Dim pSelection As IFeatureSelection

  If pMap.LayerCount = 0 Then Exit Function

  'Clear any already selected Features

  pUID = "{40A9E885-5533-11D0-98BE-00805F7CED21}" 'IFeatureLayer

  Set pEnumLayer = pMap.Layers(pUID, False)

  pEnumLayer.Reset

  Set pFeatureLayer = pEnumLayer.Next

  Set pFeatureClass = pFeatureLayer.FeatureClass

  'Expand the points envelope to give better search results

  Set pEnvelope = pPoint.Envelope

  pEnvelope.Expand SearchTol, SearchTol, False

  ShapeFieldName = pFeatureLayer.FeatureClass.ShapeFieldName

  'Search each selectable feature layer for a feature

  'Return the first feature found

  Set pSpatialFilter = New SpatialFilter

  Set pSpatialFilter.Geometry = pEnvelope

  Set pSpatialFilter.OutputSpatialReference(ShapeFieldName) = pMap.SpatialReference

  pSpatialFilter.GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName

  pSpatialFilter.SpatialRel = esriSpatialRelIntersects

  If pFeatureLayer.Selectable Then

    Set pSelection = pFeatureLayer

    pSelection.SelectFeatures pSpatialFilter, esriSelectionResultAdd, False

   Set pFeatSel = pSelection

   MsgBox (pFeatSel.SelectionSet.Count & " Features Selected from " & pFeatureLayer.FeatureClass.AliasName)

  End If

  End Function

0 Kudos
bobbycorpuz
New Contributor II

CAN ANYBODY KNOWS HOW TO DO IT? TNX IN ADVANCE...

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Hi Bobby,

Have you thought about trying the coding using ArcPy and Python?  I know it's sometimes easier to stick to a language that you know (and I'm not saying you have to switch, but recommended since VBA is being phased out with ArcMap), but Python actually is fairly easy to learn and the language of choice now, and you may get more responses if you want help with Python.  One other suggestion (so your question will get looks at by a larger group of developers) is to edit your original question and move it to the Developers​ group.

If you need some suggestions for how to get started in Python, check out this group

Python

and Python for ArcGIS | ArcGIS for Desktop

Sorry I can't be of more help, but I'm very rusty on VBA....although in a few months I'll dig into it again as I try to update some of my older apps.

These are just suggestions to get your question looked at by a larger, more developer oriented audience.

bobbycorpuz
New Contributor II

Thank you for your comment and recommendation Madam Rebecca Strauch​​​, I just need to finish the project that i am working on. Maybe i'll try working on arcPy and Python sooner. As for now, I will just stick to this rusty vba until this project is done. GODSPEED!