I have a huge number of shape files that I receive on a recurring basis. I want to be able to compare the new version to the current version, and then only update the db with those that are different.

Currently, I am using arcpy.FeatureCompare_management to check Geometry & Attributes. However, this seems to be quite timely. I was considering if a byte-by-byte comparison of the .shp and .dbf files would work, but I run into discrepencies? This is what I have tried so far:

# These refer to the FQP of the Geometry and Attribute files for the same data-source
old_geo_file = r'\myfiles\q1\myshape.shp'
new_geo_file = r'\myfiles\q2\myshape.shp'

# These are only needed by filecmp. ArcPy grabs related files.
old_attr_file = r'\myfiles\q1\myshape.dbf'
new_attr_file = r'\myfiles\q2\myshape.dbf'

arcpy_geo = arcpy.FeatureCompare_management(new_geo_file, old_geo_file, 'MY_SORT_COL', 'GEOMETRY_ONLY')
arcpy_attr = arcpy.FeatureCompare_management(new_geo_file, old_geo_file, 'MY_SORT_COL', 'ATTRIBUTES_ONLY')

print arcpy_geo
print arcpy_attr

print('*' * 10)

# Clear the filecmp cache to ensure comparison
filecmp._cache = {}

filecmp_geo = filecmp.cmp(new_geo_file, old_geo_file, shallow=False)
filecmp_attr = filecmp.cmp(new_attr_file, old_attr_file, shallow=False)

print filecmp_geo
print filecmp_attr

This is the output:


Can someone explain why a byte comparison would come out False, but ArcPy still considers them geometrically the same?

  • Script as you shown it doesn't work, because getOutput is missing. After modification it produces results as expected. Is projection defined for both? – FelixIP Dec 7 '15 at 20:11
  • @FelixIP I think you should expand your comment a fraction as an answer. – PolyGeo Nov 24 '16 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.