ArcGIS 2.9.2. - How to calculate a CRC checksum in geodatabase?

917
6
04-06-2022 05:18 AM
VincentLaunstorfer
Occasional Contributor III

Hi,

I wonder if there is a geoprocessing tool to calculate a CRC checksum for a given set of attributes in a file and/or enterprise GDB?

Ideally, the CRC checksum should be generated with alphanumeric attributes and spatial attributes to output a robust checksum to detect any changes on feature after editing... If running same CRC checksum later on, it will be obvious to detect updated feature...

Any help appreciated

Tags (3)
6 Replies
Robert_LeClair
Esri Notable Contributor

Vincent - I believe this might work for you - check out the following Technical Article here - it describe how to use Checksum on a file within ArcGIS.  Not sure if it would work on a set of GDB attributes though.

0 Kudos
VincentLaunstorfer
Occasional Contributor III

Thanks Rob. It is a similar approach I wish to apply into a GDB.

Calculate a checksum (any algorithm: MD5, SHA-256...) for each single features. Ideally, I would implement it in an attribute rule.

Is there any geoprocessing tool to calculate a checksum? Or any Arcade code to calculate a checksum in an attribute rule?

0 Kudos
Robert_LeClair
Esri Notable Contributor

Gotcha - thx for the explanation Vincent.  I know that Python in ArcMap has GenerateCheckSum command within the Aviation Charting component but do not see it in ArcGIS Pro (could be looking in the wrong place in ArcGIS Pro though!)  No GP tool or Arcade expression that I'm aware of....

0 Kudos
VincentLaunstorfer
Occasional Contributor III

Correct, I have seen the GenerateCheckSum from the Aviation Charting extension... However, this needs extra licensing and I am unsure if it exists in ArcGIS Pro. Also, attribute rule cannot use Python script.

However, if I were going with Python, I found:

# Python program to find SHA256 hash string of a file
import hashlib

filename = input("Enter the input file name: ")
sha256_hash = hashlib.sha256()
with open(filename,"rb") as f:
# Read and update hash string value in blocks of 4K
for byte_block in iter(lambda: f.read(4096),b""):
sha256_hash.update(byte_block)
print(sha256_hash.hexdigest())

in https://www.codegrepper.com/code-examples/python/frameworks/file-path-in-python/python+sha256+checks...

I wonder if it is doable to loop through selected attributes (including geometry), instead of byte_block, to calculate a SHA256 checksum...although computing on alphanumeric character instead of bytes would make the algorithm not as robust!

VincentLaunstorfer
Occasional Contributor III

Hi,

I managed to compute a checksum on attribute with Calculate Field code-block, using the hashlib module

 

import hashlib
def hash(attribute):
  hash = hashlib.md5(attribute.encode()).hexdigest()
  return attribute

 

Here I used MD5 algorithm. But SHA256 is just as good (or better).

Just as simple as that!

Ideally, I would like to compute this MD5 checksum in Arcade in attribute rule...

 

Zartico-GIS
New Contributor III

Hey thanks @VincentLaunstorfer  for the example. It was useful to me.

 

You may want to update your code block to say "return hash", not attribute. 🙂 Otherwise it just returns the parameter given.

0 Kudos