Select to view content in your preferred language

Create a script that loops through table compare tool

624
1
03-28-2022 09:41 PM
YerceniaGutierrez1
New Contributor

I have started this script:

import arcpy
import os
import sys
from arcpy import env

# Set workspaces
WorkspaceNewGDB = r"C:\GIS6340\Final_Project_GIS6340\FC_03132022\NewFC2\New File Geodatabase.gdb"
ProjectWorkspace = r"C:\GIS6340\Final_Project_2\Final_Project_2.gdb"
MainGDB = r"C:\GIS6340\Geospatial_Library\ToDateFeatureClasses.gdb"
ClippedGDB = r"C:\GIS6340\Final_Project_GIS6340\FC_03132022\ClippedFC\ClippedGDB.gdb"

# Create new GDB for newly clipped layers
out_folder_path = r"C:\GIS6340\Final_Project_GIS6340\FC_03132022\ClippedFC"
out_gdb_name = "ClippedGDB"
arcpy.management.CreateFileGDB(out_folder_path, out_gdb_name)

# Clip new downloaded layers
clipFeature = r"C:\GIS6340\Final_Project_2\Final_Project_2.gdb\ANF_AdministrativeRegion"

env.workspace = WorkspaceNewGDB

# Loop through new feature classes and add to ClippedGDB
fcList = arcpy.ListFeatureClasses()

for fc in fcList:
out_ClipFC = ClippedGDB + "\\ANF_" + fc
arcpy.analysis.Clip(fc, clipFeature, out_ClipFC)

# Compare feature class from NewGBD to ProjectGDB
clippedGDBfcList = ("ANF_AdministrativeRegion", "ANF_Bld_FS_Office_Location", "ANF_RangerDistrict", "ANF_RightOfWay", "ANF_Road_MVUM", "ANF_RoadCore_FS", "ANF_RoadlessArea_2001", "ANF_SurfaceOwnership", "ANF_WatershedConditionClass")
projectfcList = ("ANF_AdministrativeRegion", "ANF_RangerDistrict", "ANF_RightOfWay", "ANF_Road_MVUM", "ANF_SurfaceOwnership", "ANF_WatershedConditionClass")


listDifference = (set(clippedGDBfcList) - set(projectfcList))


for clippedGDBfcList in clippedGDBfcList:
if clippedGDBfcList == projectfcList:
print(True)
else:
clippedGDBfcList = ["ANF_AdministrativeRegion", "ANF_Bld_FS_Office_Location", "ANF_RangerDistrict", "ANF_RightOfWay", "ANF_Road_MVUM", "ANF_RoadCore_FS", "ANF_RoadlessArea_2001", "ANF_SurfaceOwnership", "ANF_WatershedConditionClass"]
projectfcList = ["ANF_AdministrativeRegion", "ANF_RangerDistrict", "ANF_RightOfWay", "ANF_Road_MVUM", "ANF_SurfaceOwnership", "ANF_WatershedConditionClass"]


listDifference = (set(clippedGDBfcList) - set(projectfcList))
print(listDifference)

# Extract different layers and add them to MainGDB
listDifference = ("ANF_Bld_FS_Office_Location", "ANF_RoadCore_FS", "ANF_RoadlessArea_2001") # If list difference is printed from step above, insert
arcpy.conversion.FeatureClassToGeodatabase(listDifference, MainGDB)
print(MainGDB)

# Delete listDifference feature classes from ClippedGDB

env.workspace = ClippedGDB
for fc in arcpy.ListFeatureClasses():
arcpy.management.Delete(listDifference)

# Compare clippedGDB feature class table to ProjectGDB feature class tables

??????

So everything is clipped, moved, deleted, and in the locations that they need to be. The last thing I want to do is compare the tables for each feature class, from clippedGDB compare to Final_Project2GDB' so ANF_AdministrativeRegion = ANF_AdminstrativeRegion, TRUE or FALSE. If it's TRUE nothing needs to be done, however if it is FALSE, then the feature class from clippedGDB needs to replace the corresponding feature class located in the MainGDB.  I have been trying to run the Table Compare tool in ArcGIS Pro, but as a python script, and just can't get it.

The path for ClippedGDB.gdb is:

r"C:\GIS6340\Final_Project_GIS6340\FC_03132022\ClippedFC\ClippedGDB.gdb"

YerceniaGutierrez1_0-1648528298025.jpeg

 

The path for Final_Project is:

r"C:\GISData\Final_Project_2\Final_Project_2.gdb"

YerceniaGutierrez1_1-1648528339183.jpeg

The path for MainGDB:

r"C:\GIS6340\Geospatial_Library\ToDateFeatureClasses.gdb"

YerceniaGutierrez1_0-1648651843119.png

 

Per the table compare tool, the in_base_table is the correct data, which in this case its the Clipped GDB feature classes, and the in_test_table is the ProjectGDB feature classes.

I can run it individually through Pro:

YerceniaGutierrez1_2-1648528721484.png

 

which is correct. What I am trying to do is create a script that iterates through each feature class from each geodatabase and print out the name if there are changes.

I've tried but can't get it to work. If anyone can help, I'd appreciate it.

 

Tags (2)
0 Kudos
1 Reply
GKmieliauskas
Esri Regular Contributor

Hi,

You could call the same Table Compare tool from python code. 

After you run Table Compare geoprocessing tool from ArcGIS Pro click Open history. Right click on Table Compare item and choose "Copy Python Command" and paste it to your code. Change input parameters depending on your code.

GintautasKmieliauskas_0-1648627301068.png

More info here:

https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/table-compare.htm 

List of tables you could get using arcpy.ListTables()

 

0 Kudos