I have to manually edit a shapefile of a couple of hundred points.

I would like a quick way to jump from one point to the next in both the attribute sense and the visual/spatial sense i.e I would like to while in edit mode jump from object ID 1 to Object ID 2 without having to open the attribute table, select the next point, zoom to selection, etc.

A sort of "Next" button that would expedite the manual process.

  • Do you have ArcObjects ability? I have noticed this deficiency and written a tool for it. I am happy to share the code if you can use it. – Michael Stimson Jul 27 '15 at 0:56
  • Unfortunately I do not although I would be glad to learn... – user32882 Jul 27 '15 at 1:02
  • You need to install the SDK from your ArcGis install media, but first you need to get Visual Studio (Express). Have a look at my answer gis.stackexchange.com/questions/62720/… for the prerequisites. I do need to mention that shapefiles have a problem where the FID changes on save, so to use this tool on a shapefile it is necessary not to save until the end. – Michael Stimson Jul 27 '15 at 1:06
  • @MichaelMiles-Stimson, do you have an add-in of this tool you could share so the user does not have to install the SDK and VS? – artwork21 Jul 27 '15 at 1:10
  • an add in would be very nice.... – user32882 Jul 27 '15 at 1:10

First part is the AddIn, the real work is done on a form:

Inherits ESRI.ArcGIS.Desktop.AddIns.Button
Private pForm As fFeatureInspector
Public Shared IsFormLoaded As Boolean = False

Public Sub New()

End Sub

Protected Overrides Sub OnClick()
    'My.ArcMap.Application.CurrentTool = Nothing
    If Not IsFormLoaded Then
        pForm = New fFeatureInspector
        pForm.pApp = CType(My.ArcMap.Application, ESRI.ArcGIS.ArcMapUI.IMxApplication)
    End If

End Sub

Protected Overrides Sub OnUpdate()
    Enabled = My.ArcMap.Application IsNot Nothing
End Sub

When you create a new addin most of this is already there for you. Then add a form to the project (name fFeatureInspector or you will need to change it a few times in the code).

enter image description here

It is important to get the names correct or you will need to do find & replace in the form code. The toolbox for the form has all the common controls: button, checkbox, listbox, combobox.

How this works is the tool gets all the selected and editable features, copies their name and OID/FID into the list box and then as one is highlighted it will select it (after clearing selection first) and zoom to it. There is a save and load button to save the inspection, back one and forward one, auto save check and reset button. The tool will refresh when it is loaded but after that you can refresh at any time. Auto save is not compatible with editing shapefiles as the FID is not static and gets compressed on save.

Points have a 0 width extent so it's important to set a min scale to something realistic; Zoom % is how much more than a polygon/line you want to see around it.

Here is the form code (sorry for lack of comments):

Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Editor
Imports ESRI.ArcGIS.Display

Public Class fFeatureInspector
    Const FormCaption As String = "Feature Inspector (22 Feb 10)"
    Const FormName As String = "fFeatureClass"
    Public pApp As IApplication
    Private pDoc As IMxDocument
    Private pMap As IMap

    Dim pEd As IEditor2
    Dim pID As UID = New UID
    Dim pFeatFrom() As String
    Dim pFeatWS As IFeatureWorkspace
    Dim pWS As IWorkspace
    Dim pFeatOID() As Long
    Dim pFeatCnt As Long
    Dim pInRefresh As Boolean
    Dim pPointExtent As IEnvelope
    Dim pSaveEdits As ICommandItem
    Dim pLoadTime As Long
    Dim pNow As Date
    Dim pStartIndex As Long

    Dim vStartTime As DateTime
    Dim vCurrentTime As DateTime

    Private Sub fFeatureInspector_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        StartFeatureInspector.IsFormLoaded = False
    End Sub
    Private Sub fFeatureInspector_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        pEd = pApp.FindExtensionByName("Esri Object Editor")
    End Sub
    Private Sub form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
        Dim pOutFile As Integer
        Dim pTempDir As String = Environ("Temp")

        If Me.Visible Then
            pOutFile = FreeFile()
            FileOpen(pOutFile, pTempDir & "\" & FormName & ".xy", OpenMode.Output)
            WriteLine(pOutFile, Me.Left & "," & Me.Top)
        End If
    End Sub
    Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        StartFeatureInspector.IsFormLoaded = True
        Me.Text = FormCaption
        pDoc = CType(pApp.Document, IMxDocument)

        Dim pTempDir As String = Environ("temp")
        Dim pInFile As Integer
        Dim pReadString As String = ""
        Dim pResyk As String = ""
        Dim pXpos As Integer = 0
        Dim pYpos As Integer = 0

        fZoomPercent.Text = "110"

        fPointScale.Text = "1000"

        If My.Computer.FileSystem.FileExists(Environ("Temp" & "\" & FormName & ".xy")) Then
            pApp.StatusBar.Message(0) = "Loading position"
            pInFile = FreeFile()
            FileOpen(pInFile, pTempDir & "\" & FormName & ".xy", OpenMode.Input)
            pReadString = LineInput(pInFile)
            pReadString = Mid(pReadString, 2, Len(pReadString) - 2)
            pApp.StatusBar.Message(0) = pReadString

            pResyk = Microsoft.VisualBasic.Left(pReadString, InStr(pReadString, ",") - 1)
            pApp.StatusBar.Message(0) = pResyk
            pXpos = CInt(pResyk)

            pApp.StatusBar.Message(0) = "Xposition " & pXpos
            pResyk = Microsoft.VisualBasic.Right(pReadString, Len(pReadString) - InStr(pReadString, ","))
            pApp.StatusBar.Message(0) = pResyk
            pYpos = CInt(pResyk)
            pApp.StatusBar.Message(0) = "Yposition " & pYpos
            Me.Left = pXpos
            Me.Top = pYpos
        End If
        pID.Value = "{59D2AFD2-9EA2-11D1-9165-0080C718DF97}"
        Dim pComBars As ICommandBars = pApp.Document.CommandBars
        pSaveEdits = pComBars.Find(pID, False, False)

    End Sub
    Private Sub fSaveButton_Click()
        Dim pOutfile As Integer
        Dim cnt As Long

        pOutfile = FreeFile()
        FileOpen(pOutfile, (Environ("Temp") & "\" & "FeatInspect"), OpenMode.Output, OpenAccess.Write)

        Print(pOutfile, pFeatCnt & vbNewLine)
        For cnt = 0 To pFeatCnt - 1
            Print(pOutfile, pFeatFrom(cnt) & "|" & pFeatOID(cnt) & vbNewLine)
        Next cnt
        Print(pOutfile, fFeatureList.SelectedIndex & vbNewLine)
        Print(pOutfile, fZoomPercent.Text & vbNewLine)
        Print(pOutfile, fPointScale.Text & vbNewLine)
    End Sub
    Private Sub fSaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fSaveButton.Click
    End Sub
    Private Sub fLoadButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fLoadButton.Click
        Dim cnt As Long
        Dim pInFile As Integer
        Dim pReadString As String
        Dim pSplitString() As String

        pInRefresh = True
        pInFile = FreeFile()
        FileOpen(pInFile, (Environ("Temp") & "\" & "FeatInspect"), OpenMode.Input, OpenAccess.Read)
        pReadString = LineInput(pInFile)
        pFeatCnt = pReadString
        ReDim pFeatFrom(pFeatCnt)
        ReDim pFeatOID(pFeatCnt)


        For cnt = 0 To pFeatCnt - 1
            pReadString = LineInput(pInFile)
            pSplitString = Split(pReadString, "|")

            pFeatFrom(cnt) = pSplitString(0)
            pFeatOID(cnt) = pSplitString(1)
            fFeatureList.Items.Add(pFeatFrom(cnt) & " - " & pFeatOID(cnt))
        Next cnt
        pInRefresh = False
        pReadString = LineInput(pInFile)
        fFeatureList.SelectedIndex = pReadString
        pReadString = LineInput(pInFile)
        fZoomPercent.Text = pReadString
        pReadString = LineInput(pInFile)
        fPointScale.Text = pReadString
        pStartIndex = fFeatureList.SelectedIndex
        pNow = Now()
        pLoadTime = (Hour(pNow) * 3600) + (Minute(pNow) * 60) + Second(pNow)

    End Sub

    Private Sub fBackButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fBackButton.Click
        If fFeatureList.SelectedIndex = 0 Then
            MsgBox("But you're already at the start!")
            Exit Sub
        End If
        fFeatureList.SelectedIndex = fFeatureList.SelectedIndex - 1
    End Sub
    Private Sub fGoDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fGoDown.Click
        If fFeatureList.SelectedIndex = fFeatureList.Items.Count - 1 Then
            MsgBox("That's all there is, there isn't anymore.")
            Exit Sub
        End If
        fFeatureList.SelectedIndex = fFeatureList.SelectedIndex + 1
    End Sub
    Private Sub bReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bReset.Click
        pInRefresh = True
        pInRefresh = False
        pLoadTime = (Hour(pNow) * 3600) + (Minute(pNow) * 60) + Second(pNow)
    End Sub
    Public Sub sResetList()
        Dim pEnumFeat As IEnumFeature
        Dim pFeature As IFeature
        Dim pFeatClass As IFeatureClass

        If pEd.EditState = esriEditState.esriStateNotEditing Then Exit Sub
        pEnumFeat = pEd.EditSelection

        pFeature = pEnumFeat.Next
        If pFeature Is Nothing Then
            MsgBox("Nothing selected", vbCritical)
            Exit Sub
        End If
        pFeatCnt = pEd.SelectionCount - 1

        ReDim pFeatFrom(pFeatCnt)
        ReDim pFeatOID(pFeatCnt)

        pFeatCnt = 0


        Do Until pFeature Is Nothing
            pFeatClass = pFeature.Class
            pFeatFrom(pFeatCnt) = pFeatClass.AliasName
            pFeatOID(pFeatCnt) = pFeature.OID
            fFeatureList.Items.Add(pFeatFrom(pFeatCnt) & " - " & pFeatOID(pFeatCnt))
            pFeatCnt = pFeatCnt + 1
            pFeature = pEnumFeat.Next

        fFeatureList.SelectedIndex = 0
        pNow = Now()
        pLoadTime = (Hour(pNow) * 3600) + (Minute(pNow) * 60) + Second(pNow)

    End Sub

    Private Sub fFeatureList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fFeatureList.SelectedIndexChanged
    End Sub
    Private Sub fFeatureList_Change()
        Dim pFeatClass As IFeatureClass
        Dim pFeature As IFeature
        Dim pSelection As ISelection
        Dim pLayer As ILayer
        Dim pEnumLayer As IEnumLayer
        Dim pEditLayers As IEditLayers
        Dim pFeatLayer As IFeatureLayer
        Dim pEnv As IEnvelope2
        Dim pDispTran As IDisplayTransformation
        Dim pThisTime As Long
        Dim pAvVis As Single
        Dim pTotTime As Long
        Dim pDeltaVis As Long
        Dim pLeft As Long
        Dim pTPF As Long
        Dim pAvVisStr As String
        Dim pETAstr As String
        Dim pPoint As ESRI.ArcGIS.Geometry.IPoint
        Dim cnt As Long

        If pInRefresh Then Exit Sub
        If fFeatureList.SelectedIndex < 0 Then Exit Sub

        If pEd.EditState = esriEditState.esriStateNotEditing Then
            MsgBox("This tool only works on EDIT features" & vbNewLine & "Please start editing", vbCritical)
            Exit Sub
        End If
        pFeatWS = pEd.EditWorkspace
        pFeatClass = pFeatWS.OpenFeatureClass(pFeatFrom(fFeatureList.SelectedIndex))
        On Error Resume Next
        pFeature = pFeatClass.GetFeature(pFeatOID(fFeatureList.SelectedIndex))
        If pFeature Is Nothing Then
            MsgBox("Feature not found", vbCritical) ' comment this out if you don't want to see errors
        End If
        pID.Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E} "
        pEnumLayer = pEd.Map.Layers(pID, True)
        pEditLayers = pEd

        pLayer = pEnumLayer.Next
        Do Until pLayer Is Nothing
            If TypeOf pLayer Is IFeatureLayer Then
                If pEditLayers.IsEditable(pLayer) And pLayer.Visible = True Then
                    pFeatLayer = pLayer
                    If pFeatLayer.Selectable Then
                        If pFeatLayer.FeatureClass.AliasName = pFeatFrom(fFeatureList.SelectedIndex) Then
                            pEd.Map.SelectFeature(pLayer, pFeature)
                            If pFeatLayer.FeatureClass.ShapeType = esriGeometryType.esriGeometryPoint Then
                                pEnv = New Envelope
                                pEnv.PutCoords(pDoc.ActiveView.Extent.XMin, pDoc.ActiveView.Extent.YMin, pDoc.ActiveView.Extent.XMax, pDoc.ActiveView.Extent.YMax)
                                pEnv.SpatialReference = pFeature.Shape.SpatialReference
                                If pEnv.SpatialReference.FactoryCode <> pDoc.FocusMap.SpatialReference.FactoryCode Then pEnv.Project(pDoc.FocusMap.SpatialReference)
                                pPoint = New ESRI.ArcGIS.Geometry.PointClass
                                pPoint = pFeature.ShapeCopy
                                pDoc.ActiveView.Extent = pEnv
                                pDispTran = pDoc.ActiveView.ScreenDisplay.DisplayTransformation
                                If Len(fPointScale.Text) > 0 Then
                                    pDispTran.ScaleRatio = Int(fPointScale.Text)
                                    pDispTran.ScaleRatio = 1000
                                End If
                                If fSaveOnNext.Checked Then
                                End If 'If fSaveOnNext.Checked Then

                                If Not pFeature.Shape.Envelope.IsEmpty Then
                                    pEnv = New Envelope
                                    pEnv.PutCoords(pFeature.Extent.XMin, pFeature.Extent.YMin, pFeature.Extent.XMax, pFeature.Extent.YMax)
                                    pEnv.SpatialReference = pFeature.Shape.SpatialReference
                                    If pEnv.SpatialReference.FactoryCode <> pDoc.FocusMap.SpatialReference.FactoryCode Then pEnv.Project(pDoc.FocusMap.SpatialReference)
                                    If Len(fZoomPercent.Text) > 0 Then
                                        pEnv.Expand(Int(fZoomPercent.Text) / 100, Int(fZoomPercent.Text) / 100, True)
                                    End If
                                    pDoc.ActiveView.Extent = pEnv
                                    If fPointScale.Text.Length > 0 Then
                                        If pDoc.ActiveView.ScreenDisplay.DisplayTransformation.ScaleRatio < Int(fPointScale.Text) Then pDoc.ActiveView.ScreenDisplay.DisplayTransformation.ScaleRatio = Int(fPointScale.Text)
                                    End If
                                    If fSaveOnNext.Checked Then
                                    End If 'If fSaveOnNext.Checked Then
                                End If 'Not pFeature.Shape.Envelope.IsEmpty
                            End If 'pFeatLayer.FeatureClass.ShapeType = esriGeometryType.esriGeometryPoint Then
                        End If 'pFeatLayer.FeatureClass.AliasName = pFeatFrom(fFeatureList.SelectedIndex) Then
                    End If 'pFeatLayer.Selectable Then
                End If 'pEditLayers.IsEditable(pLayer) And pLayer.Visible = True Then
            End If
            pLayer = pEnumLayer.Next
        Loop 'Until pLayer Is Nothing

        pNow = Now()
        pThisTime = (Hour(pNow) * 3600) + (Minute(pNow) * 60) + Second(pNow)
        pTotTime = pThisTime - pLoadTime
        pDeltaVis = fFeatureList.SelectedIndex - pStartIndex
        If pDeltaVis <= 0 Then
            fProgressLabel.Text = "Unable to Calculate"
            Exit Sub
            pAvVis = pTotTime / pDeltaVis
            pLeft = fFeatureList.Items.Count - fFeatureList.SelectedIndex + 1
            pETAstr = fLongTime_to_TimeString(pLeft * pAvVis)

            fProgressLabel.Text = pDeltaVis & " Inspected of " & fFeatureList.Items.Count & ". ETA " & pETAstr

        End If
    End Sub

    Private Function fLongTime_to_TimeString(ByVal pLongTime As Long) As String
        Dim pRemainder As Long
        Dim pHour As Integer
        Dim pMin As Integer
        Dim pSec As Integer

        pRemainder = pLongTime Mod 3600
        pHour = pLongTime - pRemainder
        If pHour > 0 Then pLongTime = pLongTime - pHour
        pRemainder = pLongTime Mod 60
        pMin = pLongTime - pRemainder
        If pMin > 0 Then pLongTime = pLongTime - pMin
        pSec = pLongTime

        pHour = pHour / 3600
        pMin = pMin / 60

        fLongTime_to_TimeString = pHour & ":" & pMin & ":" & pSec
    End Function

End Class

As much as I don't like sharing compiled code, Here is the link. Please read the Esri doc on 'Sharing and adding Addins'.

  • Thank you so much for your generosity. This will be very instructive and will save me a whole lot of time – user32882 Jul 27 '15 at 2:44

Here is the arcpy version of zoom to next feature. You may run this in your ArcMap python window:

mxd = arcpy.mapping.MapDocument("CURRENT") # currently opened map doc
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]

# define layer you want to iterate and zoom on
for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.name == 'myTOCLayerNameHere':
        fc = lyr

# get total record count of fc
with arcpy.da.SearchCursor(fc, ["FID"]) as cursor:
    for row in cursor:

def selectZoomNext(fc, field, record):
    if record > totalCount:
        record = 0 # reset to first feature
    expression = '{} = {}'.format(field, record)
    arcpy.SelectLayerByAttribute_management (fc, "NEW_SELECTION", expression)
    nextRecord = record + 1
    return nextRecord

record = 0
record = selectZoomNext(fc, 'FID', record) # second argument is the field name, this could be OBJECTID too

You can keep running the record = selectZoomNext(fc, 'FID', record) statement to keep selecting next feature in table and zooming to it. You could also include this snippet into a python add-in or python script tool. In addition, to make things easier while editing you may turn off un-necessary fields (in the layer properties) and also open the Attributes panel for quick attribute access.

  • That works too. I think it's a good illustration of the difference between ArcObjects and Python in the length and complexity of code. Note that this will have the same problem with shapefiles and will not work on file/personal/SDE geodatabase feature classes as the OID/FID values are not guaranteed to be contiguous and 0 based - that's a quirk of the shapefile format. – Michael Stimson Jul 27 '15 at 2:49
  • @MichaelMiles-Stimson, yes I would recommend using the AddFieldDelimiters method to construct a correct field expression between file, .mdb, and .gdb sources help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… – artwork21 Jul 27 '15 at 2:52
  • 1
    It's not that, in a geodatabase feature class the OID values don't need to start at 0 and even if they do the next one doesn't need to be 1. You need to get the OBJECTIDs into a list or dictionary when you count up with the cursor, you also need to use arcpy.Describe(fc).OIDFieldName as the field as geodatabase has OBJECTID and not FID. – Michael Stimson Jul 27 '15 at 3:42

Do you have the Data Reviewer extension? The Data Reviewer allows you to "Browse" through all features with the simple click of the "Next" button (zooms to both spatial location and attribute table record). There's a lot more functionality to Data Reviewer aside from this (such as flagging errors as "fixed", "marked" etc. and running batch jobs). Just an off-the-shelf tool, though I'm sure your tool @Michael is very fantastic as well!

enter image description here

  • Looks like just what I need, However it seems like my licensing level dooes not include data reviewer :( – user32882 Jul 29 '15 at 5:22
  • I wrote my tool before I even heard of PLTS (now production mapping), the original inspiration was written into an AML script because the requirement is so basic but necessary. I'm not surprised Esri has the tool but why isn't it native in ArcMap? Data reviewer is very good at what it does but I found that I had already written most of the tools that it came with when I evaluated it. – Michael Stimson Jul 30 '15 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.