1

I have about 30 geodatabases with about 15 feature classes in each database. Is there a way to have a script check the attribute tables to see if they're not attributed? If it could then select the features that don't have attributes and export them to a gdb or shp. I want an easy way to check the tables for nulls that I could run nightly. Would a searchcursor work for this? Is this possible?

4
  • You could potentially use a search cursor but it would then select any fc that had any NULL value. What I think you want is an entire fc that is null values? – GISKid May 28 '14 at 16:49
  • 2
    Could you use TableToNumpyArray to capture features with null values? There is an example on the above link. – Barbarossa May 28 '14 at 16:53
  • I was thinking once the values were selected to export to a shp? – MjonesGEO May 28 '14 at 17:26
  • Shape files don't support NULL, the values you're trying to find would become 0 or "". Best to just export the OID and database that fails validation. – Michael Stimson May 28 '14 at 22:18
2

Here is a little script I put together to find features with fields that are null. It will write to the report file what feature class and OID the feature is. It stops at the first null value so it wont report every bad field or give multiple reports for the same feature.

import arcpy, os, sys

InWorkspace = sys.argv[1]
OutReportFile = sys.argv[2]

arcpy.env.workspace = InWorkspace

# open the report file (overwrite) and write the header line
OFhandle = open(OutReportFile,"w")
OFhandle.write("FeatureClass,OID\n")

for fc in arcpy.ListFeatureClasses():
    # some basic information about the feature class
    fList = arcpy.ListFields(fc) # all the fields
    desc = arcpy.Describe(fc)
    OIDname = desc.OIDFieldName  # the OID/FID field name, skipped later
    SHPname = desc.shapeFieldName# the shape field name, not checked in the same way

    sc = arcpy.SearchCursor(fc)

    for feat in sc:
        # assume no null fields for now
        FoundNullField = False

        for field in fList:
            # for every field that the feature class has
            if field.name.lower() != OIDname.lower() and field.name.lower() != SHPname.lower():
                # so long as it's not the OID/FID field or the shape
                if not FoundNullField:
                    if feat.isNull(field.name):
                        # write to console and file, flag that a null field is found
                        # so that the row isn't reported many times
                        print "field is null: " + field.name
                        FoundNullField = True
                        OFhandle.write(fc + "," + str(feat.getValue(OIDname)) + "\n")
    del sc # clean up the cursor otherwise it leaves a lock
OFhandle.close()

There are other types of empty like "" which aren't checked by the script and it doesn't go down the feature dataset tree, to do that use ListDatasets() in the database and set your workspace to each one to get the feature classes.

This program works but it is intended to be a template to expand upon with your knowledge of your data structure; it will run in a batch file:

Script.py path\Geodatabase.gdb otherpath\reportfile.csv

or it can be incorporated into a model as a script and here which may be easier to work with.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.