How to open a large link file


The Spatial Adjustment functions allow you to load a text file containing adjustment links, which may have been previously saved in ArcGIS or have come from an external system or process. Within the edit session these links are added via the operation stack and are also selected in the graphics container. These operations can take considerable time if you are loading large numbers of links.
This sample provides a way to load large link files by bypassing the operation stack and graphic selection.

How to use

  1. Copy and paste this code into ArcMap VBA.
  2. Run the OpenLargeLinkFile subroutine.
  3. Select the link file in the dialog.
[VBA]
Public Sub OpenLargeLinkFile()
    
    'Add displacement links from ascii textfile.
    'Bypass operation stack and select graphics
    
    Dim pMxDoc As IMxDocument
    Dim pAdjustProp As IAdjustProperties
    Dim pGraCon As IGraphicsContainer
    Dim pElement As IElement
    Dim pDLink As IDisplacementLinkElement
    Dim pPolyLine As IPolyline
    Dim pPoint As IPoint
    
    Dim pGxObject As IGxObject
    Dim pGxDialog As IGxDialog
    Dim pFileSel As IEnumGxObject
    Dim pObjFilter As IGxObjectFilter
    
    Dim sRec As String
    Dim colRec As Collection
    
    'Set up the filebrowser and get the file
    Set pGxDialog = New GxDialog
    pGxDialog.Title = "Select Link File"
    
    Set pObjFilter = New GxFilterTextFiles
    Set pGxDialog.ObjectFilter = pObjFilter
    
    pGxDialog.DoModalOpen Application.hWnd, pFileSel
    
    Set pGxObject = pFileSel.Next
    
    'Get the map and graphics container
    Set pMxDoc = ThisDocument
    Set pGraCon = pMxDoc.FocusMap
    pGraCon.Reset
    
    'Delete existing links
    DeleteLinks
    
    'Get the adjustment propertes
    Set pAdjustProp = Application.FindExtensionByName("ESRI Adjustment Tools")
    
    'Open the file and loop through records
    Open pGxObject.FullName For Input As #1
    
    Do Until EOF(1)
        
        Line Input #1, sRec
        Set colRec = AsTokens(sRec, vbTab)
        
        'Create a displacement link
        Set pPolyLine = New Polyline
        
        Set pPoint = New Point
        pPoint.PutCoords colRec(1), colRec(2)
        pPolyLine.FromPoint = pPoint
        
        Set pPoint = New Point
        pPoint.PutCoords colRec(3), colRec(4)
        pPolyLine.ToPoint = pPoint
        
        Set pDLink = New DisplacementLinkElement
        Set pElement = pDLink
        
        pElement.Geometry = pPolyLine
        'Toggle for ID field in link file
        'pDLink.ID = colRec(1)
        pDLink.Symbol = pAdjustProp.DisplacementLinkSymbol
        
        'Add the link to the graphics container
        pGraCon.AddElement pElement, 0
        
    Loop
    
    'Close the file
    Close #1
    
    pMxDoc.ActiveView.Refresh
    
End Sub

Public Sub DeleteLinks()
    
    'Delete links without selecting or going through op stack
    
    Dim pMxDoc As IMxDocument
    Dim pGraCon As IGraphicsContainer
    Dim pElement As IElement
    
    'Get the map and graphics container
    Set pMxDoc = ThisDocument
    Set pGraCon = pMxDoc.FocusMap
    pGraCon.Reset
    
    'Delete all links first
    Set pElement = pGraCon.Next
    Do Until pElement Is Nothing
        If TypeOf pElement Is IDisplacementLinkElement Or TypeOf pElement Is IIdentityLinkElement Then
            pGraCon.DeleteElement pElement
        End If
        Set pElement = pGraCon.Next
    Loop
    
    Set pElement = pGraCon.Next
    Do Until pElement Is Nothing
        If TypeOf pElement Is IDisplacementLinkElement Or TypeOf pElement Is IIdentityLinkElement Then
            pGraCon.DeleteElement pElement
        End If
        Set pElement = pGraCon.Next
    Loop
    
    'pMxDoc.ActiveView.Refresh
    
End Sub

Private Function AsTokens(sString As String, sDelimiter As String) As Collection
    ' Break the string out into a collection, breaking it apart by the delimiter character
    Dim lLoop As Long
    Dim lIndex As Long
    Dim lIndex_Prev As Long
    Dim sSubString As String
    lIndex_Prev = 0
    lIndex = 0
    Set AsTokens = New Collection
    lIndex = InStr(sString, sDelimiter)
    While lIndex > 0
        sSubString = Mid(sString, lIndex_Prev + 1, (lIndex - lIndex_Prev - 1))
        AsTokens.Add sSubString
        lIndex_Prev = lIndex
        lIndex = InStr(lIndex + 1, sString, sDelimiter)
    Wend
    sSubString = Right(sString, Len(sString) - lIndex_Prev)
    AsTokens.Add sSubString
End Function






Additional Requirements
  • An Edit Session.