I have created two geodatabases: Source GDB and Target GDB. Databases are basically copies of one another. Source GDB featureclasses are exported Directly from CAD whereas Target GDB contains feature classes that must be updated daily with new records from Source feature classes using search and insert cursor.
I was able to do this with a single-source feature class to a single target feature class and now I am trying to figure out how to update the entire list of target feature classes by using search and insert cursor.
In the code below I am trying to loop through both the Source and Target GDB, and if the source and target GDB are equal then create a search cursor for both source and target featureclass and insert a record if they do not exist in target featureclass. I get no error messages but my target featureclasses are not updated.
Any suggestions on what and where I am missing would be of great help.
import arcpy
from arcpy import env
import os
import sys
arcpy.env.workspace = targetGDB = r"Path to Target GDB"
targetFC = arcpy.ListFeatureClasses()
arcpy.env.worksapce = sourceGDB = r"Path to Source GDB"
sourceFC = arcpy.ListFeatureClasses()
for target in targetFC:
# print (targetGDB, targetFC)
for source in sourceFC:
# print (sourceGDB, source)
if target == source:
curTarget=arcpy.da.SearchCursor(target, ["Handle", "SHAPE@", "Layer", "Linetype"])
curSource=arcpy.da.SearchCursor(source, ["Handle", "SHAPE@", "Layer", "Linetype"])
curInsert=arcpy.da.InsertCursor(target, ["Handle", "SHAPE@", "Layer", "Linetype"])
curS_list=[y[0] for y in curTarget]
for row in curSource:
if not row[0] in curS_list:
curInsert.insertRow(row)
del curInsert,curTarget,curSource