0

I have two geodatabases, one is a production sde database, the other is a backup in a local file geodatabase. The script runs as a task once a month and is very resource intensive. I am using ArcGIS for Desktop 10 SP 5.

What I would like to do is use a search and update cursor for each feature class in the database, including feature data sets; if there has been any change to the feature class; then just update the backup based on what is in the production instead of deleting it.

The example here shows how to update a feature class based on a field and changes to a field. I would like to parse and update all feature classes in gdb2 if there is a change to a feature class in gdb1. How can this script be modified to meet my needs?

import arcpy
#input feature class
fc2 = r"C:\temp\temp.gdb\fc2"
#target feature class
fc3 = r"C:\temp\temp.gdb\fc3"
#check field
checkField = "SRNumber"
#Get list of values in field from target feature class
checkValues = [r[0] for r in arcpy.da.SearchCursor (fc3, checkField)]
#Get list of fields
fields = [f.name for f in arcpy.ListFields (fc2)]
#Get index of check field
index = fields.index (checkField)
#Create insert cursor for fc3 to allow appending of rows
inCursor = arcpy.da.InsertCursor (fc3, fields)
#Create search cursor to iterate input feature class
cursor = arcpy.da.SearchCursor (fc2, fields)
#iterate
for row in cursor:
 #Get value to check
 checkValue = row[index]
 #Check if value is in target fc
 if checkValue in checkValues:
 #skip if value is in target fc
 continue
 #Insert row otherwise
 inCursor.insertRow(row)
#Clean up
del cursor
del inCursor
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 20, 2016 at 17:33
3
  • 2
    Are you on Desktop 10.0 SP5? I believe the da module was made available at 10.1. With walk it would be simple to iterate over a GDB assuming the structures are identical. Commented May 20, 2016 at 18:28
  • I am not on 10.1 .da is not available in Desktop 10.0 Commented May 20, 2016 at 18:40
  • 3
    Why not just replicate the feature class from production to development? Commented May 20, 2016 at 23:47

1 Answer 1

2

As alexGIS already said, it would be easiest to create a replica between your SDE database and your local backup fileGDB

Make sure that your SDE database is versioned and all feature classes have a GlobalID. If you want to work with a fileGDB check-in/ check-out replicas is the right choise: http://help.arcgis.com/EN/ARCGISDESKTOP/10.0/HELP/index.html#/Creating_a_check_out_replica/00270000002t000000/

answered May 21, 2016 at 20:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.