Comparing Feature Classes in two different geodatabases

3582
7
06-22-2011 05:38 AM
philiptivel
New Contributor II
This forum has been a great help to me in creating a couple python tools I really needed to get working. So thanks a ton to the people who have helped me with these. I 'm hoping I can get help with one last tool.

I have a master database with a master set of feature classes in it and a new database with most of the same feature classes and a couple new ones. Is there python code I can use to print out a list of just the feature classes names in the new database that don't match any of the feature class names in the master database? Thanks,

Phil
Tags (2)
0 Kudos
7 Replies
MathewCoyle
Frequent Contributor
I did something similar, looks like this. Counting features in a feature class and making sure they have the same number of features as another feature class. You could just modify it so it just tests whether it is there is or isn't a feature class of that name.

Would be a simple like like

if fc2 not in fcList:
  print fc2+" not found"

import arcpy

sde1 = r"D:\sde_transit\sde1.gdb"
output = r"C:\Users\coylema\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Connection to winms-wooddb.sde"
#output = r"D:\sde_transit\sdeCSRS.gdb"

arcpy.env.workspace = r"D:\sde_transit\sde1.gdb"

sdeList = arcpy.ListFeatureClasses()
for fc in sdeList:
    
    result = arcpy.GetCount_management(fc)
    count1 = result.getOutput(0)

    fc2 = output+"\\TFM_BKG."+fc
    if arcpy.Exists(fc2):
        result = arcpy.GetCount_management(fc2)
        count2 = result.getOutput(0)
        if count1 == count2:
            print fc+" OK"
        else:
            print "Problem with "+fc
            print count1
            print count2
    else:
        print fc2+" not found"
        pass

# Clean up
sdeList = None
del arcpy.env.workspace
del arcpy
0 Kudos
philiptivel
New Contributor II
Thanks for the help it definitely got me a lot closer. I decided that instead of printing out a list of the new feature classes in my dataset, that instead I would simply delete out any feature classes that matched those in the master dataset, thus leaving me with only the new feature classes that don't appear in the master dataset. My code runs successfully but it's not doing anything and I'm not sure why. Here is how I wrote it

import arcpy

MasterDataset = arcpy.GetParameterAsText (0)
fcs = arcpy.GetParameterAsText (1)

arcpy.env.workspace = MasterDataset

fclist = arcpy.ListFeatureClasses()

for fc in fcs:
    if fc in fclist:
        arcpy.Delete_management(fc, "FeatureClass")
0 Kudos
MathewCoyle
Frequent Contributor
What exactly is MasterDataset, and what is fcs?

Also, why do you limit your deletes to Feature Class only? Are there tables etc with similar names you want to keep? Feature Class should also be two words iirc.
0 Kudos
philiptivel
New Contributor II
Both MasterDataset and fcs are datasets that users gets to input for the purpose of comparing the feature classes inside them. Any feature classes that are in the fcs dataset that are not in the MasterDataset dataset need to be evaluated. That's why I would like to delete all the feature classes in the fcs dataset that are already in the MasterDataset dataset.

I guess I don't need to limit the deletes to feature classes only, but there are no other tables or anything that appear in these datasets or databases. I input the delete tool in model builder and converted it to python and it left the "FeatureClass" in the Delete_management statement so I did too.
0 Kudos
MathewCoyle
Frequent Contributor
Ok, you will want to make a list of both datasets first, from your input workspaces.

import arcpy

MasterDataset = arcpy.GetParameterAsText (0)
fcs = arcpy.GetParameterAsText (1)

arcpy.env.workspace = MasterDataset
fclist = arcpy.ListFeatureClasses()
arcpy.env.workspace = fcs
fcslist = arcpy.ListFeatureClasses()

for fc in fcslist:
    if fc in fclist:
        arcpy.Delete_management(fc)
0 Kudos
philiptivel
New Contributor II
That worked perfectly! Thanks so much for your help!!!
0 Kudos
MathewCoyle
Frequent Contributor
Thank you.

"The teacher is no longer merely the-one-who-teaches, but one who is himself taught in dialogue with the students, who in turn while being taught also teach. They become jointly responsible for a process in which all grow." -Paulo Freire