AnsweredAssumed Answered

python to snap based on attribute

Question asked by kwallis@cityofnapa.org on Aug 10, 2015
Latest reply on Feb 15, 2017 by vannb1

I need to move some points that were geocoded to the place they actually are on the map.
I have a feature class called Meters that needs to be snapped (or x,y updated) to that they are moved to the corresponding point in a feature class called GPSpoints.
Based on the thread found here

Re: Snap points to lines based on attribute matching 

I tried the code below., however I keep getting the error "Layer Name or Table View: Dataset Meter_layer does not exist or is not supported"

Any help would be greatly appreciated.

 

import arcpy

arcpy.env.workspace = "C:\\Users\\kwallis\\Desktop\\METERS"

Meter_layer = arcpy.MakeFeatureLayer_management("C:\Users\kwallis\Desktop\METERS\Meters.shp", "Meters_lyr")
field_Meters = "ACCOUNTID"

GPSpnts_layer = arcpy.MakeFeatureLayer_management("C:\\Users\\kwallis\\Desktop\\METERS\\GPSpnts.shp", "GPSpnts_lyr")
field_GPSpnts = "ACCOUNTID" 

#creating cursor for a list of all the names in Meter layer
cursor_Meters = arcpy.SearchCursor(Meter_layer)

#empty list for Meter names
list_Meter_names = []

#filling the list with names from Meter layer
for row in cursor_Meters:
    list_Meter_names .append(row.getValue(field_Meters))

                                            
#another empty list for storing  only unique names from list_Meter_names
s = []
for i in list_Meter_names :
       if i not in s:
          s.append(i)
                                             

#selecting Meters and GPSpnts by name:
for name in s:
     layer1 = arcpy.management.SelectLayerByAttribute("Meter_layer", "NEW_SELECTION", "ACCOUNTID=" +"'"+name+"'")
     layer2 = arcpy.management.SelectLayerByAttribute("GPSpnts_layer", "NEW_SELECTION", "ACCOUNTID=" +"'"+name+"'")
     arcpy.Snap_edit(layer1, [layer2, "VERTEX", "30 feet"])
arcpy.management.SelectLayerByAttribute(Meter_layer , "CLEAR_SELECTION")
arcpy.management.SelectLayerByAttribute(GPSpnts_layer , "CLEAR_SELECTION")

Outcomes