orcoastalmgmt / cmecs

CMECS is a comprehensive national framework for organizing information about coasts and oceans and their living systems.
2 stars 0 forks source link

Both NULL and some Empty string in columns in Biotic Component Attributes #40

Closed cybersea closed 6 years ago

cybersea commented 6 years ago

Having both NULL and empty string makes it more challenging to summarize and query data. Suggest making this consistent so that it is either all NULL or all empty string

cybersea commented 6 years ago

I wrote some Python/ArcPy to do this. Sharing in case it is useful for you.

import arcpy

if name == "main": workspace = 'Y:/projects/ocmp_cmecs2016/data/cmecs_draft_20180328/cmecs_draft_20180328_4prodreview.gdb' arcpy.env.overwriteOutput = True arcpy.env.workspace = workspace

source_layers = [
    'Aquatic_Setting_DRAFT_20180208',
    'Biotic_Component_DRAFT_20180328',
    'Geoform_Component_DRAFT_20180308',
    'Substrate_Component_DRAFT_20180308',
]

for layer in source_layers:
    desc = arcpy.Describe(layer)
    print(desc.name)
    tempLayer = layer + "_tmp"
    arcpy.MakeFeatureLayer_management(layer, tempLayer)
    for field in desc.fields:
        if field.type == "String":
            # print("{0}, {1}".format(field.name, field.type))
            expression = "{0} IS NULL".format(arcpy.AddFieldDelimiters(tempLayer, field.name))
            print(expression)
            arcpy.SelectLayerByAttribute_management(tempLayer,"NEW_SELECTION",expression)
            selected_count = int(arcpy.GetCount_management(tempLayer).getOutput(0))
            print(selected_count)
            if selected_count > 0:
                arcpy.CalculateField_management(tempLayer, field.name,'""','PYTHON_9.3')
tchaddad commented 6 years ago

Thanks! The problem with this issue is that it tends to come back each time we make edits. But I'll add the above into the end of the workflow, and and that will help.