Having trouble maintaining GlobalID values between two geodatabases

1483
3
08-16-2011 03:39 PM
TannerSemerad
New Contributor II
I am creating a python script that compares two different feature classes - a parent and a child - and updates the child with whatever changes that were made to the parent.

For example, all of our "prime time" data is stored in our Publication SDE gdb. We have a separate gdb that "mirrors" the Publication gdb, except it is projected to Web Mercator. Whenever a feature is added, removed, or changed in Publication, the script will detect it and make the corresponding change in the Web Mercator gdb.

All of the adds, deletes, and updates are determined by comparing GlobalIDs. This works fine with deletes and updates, but I am having issues with adds. My code will correctly determine which row to insert from the input feature class to the output feature class, but when it is inserted into the output it is given a new GlobalID that doesn't match the original feature's GlobalID. I understand that the InsertCursor is technically inserting a new row, thus the new GlobalID, but what I need is a way to copy an individual row.

My question is: Is there any way to copy an individual feature (row) from one location to another while maintaining the parent's GlobalID? I have only found ways of copying entire feature classes or tables. I feel like there should be a sort of 'CopyCursor'.

    def insertRow(outInsertCur, outDatasetPath, inDatasetPath, globalId):
        in_search = arcpy.SearchCursor(inDatasetPath, "GlobalID = '%s'" % globalId)
        insert_row = in_search.next()
        outInsertCur.insertRow(insert_row)
        print "Inserted %s into %s" % (insert_row.GlobalID, outDatasetPath)
        del in_search

    out_insert = arcpy.InsertCursor(out_dataset_path)
    insertRow(out_insert, out_dataset_path, in_dataset_path, add_id)



What I am trying to create is similar to replication, but my organization does not want to go that route.
0 Kudos
3 Replies
BruceHarold
Esri Regular Contributor
Hello Tanner

Please take a look at this sample script tool:

http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=351BEE10-1422-2418-8815-82074...

You may want to put it in a model and project one of the inputs if you are going to use Shape as one of the change detection fields.  You also may need to edit the tool properties to allow GUID fields to be inputs, I can't recall if these are allowed.

The tool is not fast, sorry.

Regards
0 Kudos
TannerSemerad
New Contributor II
Thanks for the code Bruce.

I looked through it and tried out the tool, but it only compares the features and returns the differences. If I were to add the Added Features returned from your tool to the "original" feature class using an InsertCursor, then each row from Added Features that is inserted into the original feature class would be generated a new GlobalID. My code does the compares fine, I just need to find a way to keep the GlobalID the same when doing inserts.
0 Kudos
CherylCleghorn
Esri Contributor
Tanner

you may get some ideas from this link:
How to copy or load data and preserve GlobalID values

Regards
Cheryl
0 Kudos