blhornun

Store a rubberband line selection and use its attributes to query map selection

Discussion created by blhornun on Apr 16, 2012
I am trying to find a way to use a rubber band to select a line feature and store that selection (separate from current map selection). The selection must not affect the map selection - the map selection must retain all previously selected features. The stored line selection's attributes need to be used to re-query and add top the selection of the line feature class. The trouble that I am running into is that I need to store the rubber band selection in an intermediate and isolated space.

I have code that currently uses a rubber band to select a line feature using the pmap.selectbyshape method. The code then stores the attributes of the selected line feature and re-queries the line layer to include all related lines (where the sequence attribute is => or =< the selected feature's).

I am having trouble figuring out a way to retain previous selection while adding new selections based upon a rubber band selected line.

Any help would be much appreciated!



________________________________________________________________________________________________________________

Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)
        MyBase.OnMouseDown(arg)

        'Get document
      
        Dim m_application As IMxApplication = CType(Hook, ESRI.ArcGIS.Framework.IApplication)
        Dim pMxDoc As IMxDocument = m_application.Document
        Dim pMap As IMap = pMxDoc.ActiveView.FocusMap
      
        'get screen display
        Dim screenDisplay As IScreenDisplay3 = pMxDoc.ActiveView.ScreenDisplay

        'create Rubber band
        Dim RubSelection As IRubberBand2 = New RubberEnvelope

        'track the rubber band
        Dim selectionBoxRubber As IGeometry5 = RubSelection.TrackNew(screenDisplay, Nothing)

        'reference the layer
        Dim selectEnv As ISelectionEnvironment = m_application.SelectionEnvironment

        Try

            pMap.SelectByShape(selectionBoxRubber, Nothing, False)
          
        Catch ex As Exception

        End Try

    
        If pMap.SelectionCount.ToString > 1 Then
            MsgBox("Please select only one road segment.")
            pMap.ClearSelection()
        ElseIf pMap.SelectionCount.ToString = 0 Then
            'MsgBox("You must select a road segment.")
        Else


      
            '---------------------------------------------------------------------------------
            ' Get the FeatureCursor
            '---------------------------------------------------------------------------------
            Dim pCur As ICursor = Nothing
            Dim pFeature As IFeature
            Dim pFeatureLayer As IFeatureLayer
            Dim pFeatureSelection As IFeatureSelection
            Dim pSelectionSet As ISelectionSet
            Dim pWRMLayer As ILayer = pMxDoc.FocusMap.Layer(0)
            Dim pWRMFeatLayer As IFeatureLayer = pWRMLayer
            Dim pWRMFeatClass As IFeatureClass = pWRMFeatLayer.FeatureClass
            Dim RtSeq As String
            Dim Route As String
            Dim Priority As String
            Dim Dispatch As String
            Dim RtSeqFieldIndex As Integer
            Dim RouteFieldIndex As Integer
            Dim PriorityFieldIndex As Integer
            Dim DispatchFieldIndex As Integer

            'Find Associated Field Indexes
            RtSeqFieldIndex = pWRMFeatClass.FindField("SEQUENCE")
            RouteFieldIndex = pWRMFeatClass.FindField("ROUTE_NUMBER")
            PriorityFieldIndex = pWRMFeatClass.FindField("DISPATCH_PRIORITY")
            DispatchFieldIndex = pWRMFeatClass.FindField("DISPATCH_GROUP")

            pFeatureLayer = pMap.Layer(0)
            pFeatureSelection = pFeatureLayer 'QI
            pSelectionSet = pFeatureSelection.SelectionSet
      
            pSelectionSet.Search(Nothing, False, pCur)

            Dim pFCur As IFeatureCursor = CType(pCur, IFeatureCursor)

            pFeature = pFCur.NextFeature

            'set rt seq number for query
            RtSeq = pFeature.Value(RtSeqFieldIndex)
            Route = pFeature.Value(RouteFieldIndex)
            Priority = pFeature.Value(PriorityFieldIndex)
            Dispatch = pFeature.Value(DispatchFieldIndex)

            System.Runtime.InteropServices.Marshal.ReleaseComObject(pFCur)
            MsgBox("route seq number = " & RtSeq & " Route = " & Route & " Priority = " & Priority & " Disp Grp = " & Dispatch)

      
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            'get access to user form'''''''''''''''''''''''''''''''''''''''''
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Dim frmStartEnd As New LastCmplSeg_Form

            'call the form to show
            frmStartEnd.ShowDialog()
            frmStartEnd.Activate()
            Dim StartEndAnswer As Boolean
            Dim PartialRtQueryWhere As String


            StartEndAnswer = frmStartEnd.boolBegEnd
            'MsgBox(StartEndAnswer)

            'true = end , false = start
            If (StartEndAnswer = True) Then
                'MsgBox("true")
                PartialRtQueryWhere = "DISPATCH_PRIORITY = " & Priority & " AND DISPATCH_GROUP = '" & Dispatch & "' AND ROUTE_NUMBER = " & Route & " AND SEQUENCE >= " & RtSeq
                SelectMapFeaturesByAttributeQuery(pMxDoc.ActiveView, pMap.Layer(0), PartialRtQueryWhere, esriSelectionResultEnum.esriSelectionResultNew)
                pMxDoc.ActiveView.Refresh()
                'MsgBox(PartialRtQueryWhere)

            ElseIf (StartEndAnswer = False) Then
                'MsgBox("false")
                PartialRtQueryWhere = "DISPATCH_PRIORITY = " & Priority & " AND DISPATCH_GROUP = '" & Dispatch & "' AND ROUTE_NUMBER = " & Route & " AND SEQUENCE <= " & RtSeq
                SelectMapFeaturesByAttributeQuery(pMxDoc.ActiveView, pMap.Layer(0), PartialRtQueryWhere, esriSelectionResultEnum.esriSelectionResultNew)
                pMxDoc.ActiveView.Refresh()
                'MsgBox(PartialRtQueryWhere)
            Else
                Return

            End If

            pMxDoc.ActiveView.Refresh()


        End If

Outcomes