I am trying to automate the production of a feature class with daily updates. I would like to use a Python Script do this. The basic concept is there is a SQL table that is updated with addresses, the script needs to pull that table into a intermediate file geodatabase, geocoded it, compare the geocoded results to the existing SDE feature class, and remove any old entries from the SDE feature class, append any new features, and leave alone any that are the same. I get the first chunk of my script to do what I want it to do. When I get to the compare and update part, my initial line of thinking will not work in all cases (especially when there are only removals). I know there has to be a more elegant way of doing the compare and update portion. Any suggestions?
This is what the portion that does not work all the time:
# Put in error trapping in case an error occurs when running tool
CoMGIS_SDE_Warrants = #Path to SDE Feature Class
try:
# Make a layer from the feature class
arcpy.MakeFeatureLayer_management(MAW_GeoCode,"newCompare_lyr")
# Selecting all existing features
arcpy.SelectLayerByLocation_management("newCompare_lyr", "INTERSECT", CoMGIS_SDE_Warrants, "", "NEW_SELECTION")
# Selecting only new features
arcpy.SelectLayerByLocation_management("newCompare_lyr", "INTERSECT", CoMGIS_SDE_Warrants, "", "SWITCH_SELECTION")
# Write the selected features to a new featureclass
arcpy.Append_management("newCompare_lyr", CoMGIS_SDE_Warrants,"TEST","","")
arcpy.Delete_management("newCompare_lyr")
# Make a layer from the Existing Features
arcpy.MakeFeatureLayer_management(CoMGIS_SDE_Warrants,"existCompare_lyr")
# Selecting all existing features
arcpy.SelectLayerByLocation_management("existCompare_lyr", "INTERSECT", MAW_GeoCode, "", "NEW_SELECTION")
# Selecting only Non-Active Warrants
arcpy.SelectLayerByLocation_management("existCompare_lyr", "INTERSECT", MAW_GeoCode, "", "SWITCH_SELECTION")
# Delete Non-Active Warrants
arcpy.DeleteFeatures_management("existCompare_lyr")
arcpy.Delete_management("existCompare_lyr")
except:
print arcpy.GetMessages()
print "Success"