HOW TO

Remove duplicate points from a point theme using Avenue

Last Published: April 26, 2020

Summary

The following script takes a point shapefile that has duplicate point locations and creates a new shapefile without duplicate points.

Procedure

 
  1. Create a unique ID field. You can skip this step if your shapefile attribute table already has a unique ID field.

    See: How To: Add a field containing a unique value for each record
     
  2. Open a new script window.
     
    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.
  3. Copy the following code into the new window.
     
    Code:
    '--- Remove_Duplicate_Points.ave 
    '
    '-- This script takes a point shapefile with duplicate point locations
    '-- and creates a new shapefile without the duplicate points 
    
    theview = av.getactivedoc 
    theTheme = theView.getactivethemes.get(0) 
    theFTab = theTheme.GetFTab 
    theshpfld = theFTab.FindField("Shape") 
    thefieldlist = theftab.getfields 
    theidfield = msgbox.listasstring(thefieldlist,"This field"+
    "must contain unique ID values. It can be used"+ 
    "to join attributes from your active theme to your new"+
    "theme.","Select a Field") 
    
    if (theidfield = nil) then 
    return nil 
    end 
    
    defaultName = av.getproject.getworkdir.MakeTmp("inter","shp") 
    newfile = FileDialog.Put(defaultName,"*.shp","New POINT Theme") 
    
    if (newfile = nil) then 
    return nil 
    end 
    
    thenewftab = ftab.makenew(newfile,point) 
    thenewtheme = ftheme.make(thenewftab) 
    thenewtheme.setvisible(true) 
    thenewtheme.setactive(true) 
    theview.addtheme(thenewtheme) 
    newfldShape = thenewFTab.FindField("Shape") 
    thenewidfield = field.make(theidfield.asstring,#FIELD_DECIMAL, 8, 0) 
    thenewftab.addfields({thenewidfield}) 
    
    thenewFTab.seteditable(true) 
    theview.invalidate 
    
    for each rec in theftab 
    thepoint = theftab.returnvalue(theshpfld, rec) 
    theid = theftab.returnvalue(theidfield, rec) 
    thenewftab.selectbypoint(thepoint, 0.00000001, #VTAB_SELTYPE_NEW) 
    
    if (thenewftab.getselection.count = 0) then 
    newrec = thenewftab.addrecord 
    thenewFTab.SetValue(newfldShape,newrec,thepoint) 
    thenewftab.setvalue(thenewidfield, newrec, theid) 
    end 
    end 
    
    thenewftab.seteditable(false)
    
    '--- End of Script 
  4. Attach the script to a button on the View GUI.
     
    A. Compile the script.
    B. Switch to the Project window.
    C. Select Customize from the Project menu.
    D. On the Customize dialog box, click the Type dropdown arrow and click View.
    E. Select Buttons under Category.
    F. Click the New button.
    G. Double-click the Click property in the Customize dialog box.
    H. Type the name of the script in the Script Manager and click Select.
    I. Close the Customize dialog box.

    For more information, see "Customize dialog box" in ArcView Help.
  5. Make the point theme active.
  6. Click the new button to run the script.
  7. Join the Original attribute table to the new point shapefile attribute table using the unique ID field.
     
    A. Open the two tables
    B. Place tables side-by-side
    C. Make the source table active and select the join field
    D. Make the destination table active and select the join field
    E. Select Join from the Table menu

    The source table will disappear from the screen and the fields from the source table will be added to the destination table.

Article ID:000002493

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic