I have a script that runs in arcmap Python window. It does a select layer by location then exports the selected features but i need to remove features with Null or empty attributes in a specific filed before acpy.TableToTable but some times there will be none with Null or empty attributes. I am not sure how to do that so if someone could show me how to this it would be awesome.
Currently this is the code i have.
TA = "TAXLOTS"
SP4 = "SUBJECT_PROPERTY"
arcpy.SelectLayerByLocation_management(TA, "WITHIN_A_DISTANCE", SP4, "600 Feet", "NEW_SELECTION")
try:
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.TableToTable_conversion("TAXLOTS", wp, "NOTIFIED_LOTS.dbf")
arcpy.SelectLayerByAttribute_management("TAXLOTS", "CLEAR_SELECTION")
except:
pass
Solved! Go to Solution.
You remove features from a selection using the same tool as you use to add them:
Select Layer By Attribute—Help | ArcGIS for Desktop
or
Select Layer By Location—Help | ArcGIS for Desktop
Check the 'selection_type' parameter, 'REMOVE_FROM_SELECTION' option.
How many fields are in this layer? Do you want to exclude records if a certain field or two has a NULL or empty, or do you want to drop a record if any field has a NULL or empty?
There is about 10 fields in the layer. Of the selected I would like to exclude records if a certain field is NULL or empty .
You remove features from a selection using the same tool as you use to add them:
Select Layer By Attribute—Help | ArcGIS for Desktop
or
Select Layer By Location—Help | ArcGIS for Desktop
Check the 'selection_type' parameter, 'REMOVE_FROM_SELECTION' option.
I figured i was over looking something simple.
Will line 2 this handle NULL's ?
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.SelectLayerByAttribute_management("TAXLOTS", "REMOVE_FROM_SELECTION", "\"DXF_TEXT\" = ' '")
Will line 2 this handle NULL's ?
No, you need to handle both cases - blank and null.
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.SelectLayerByAttribute_management(
"TAXLOTS",
"REMOVE_FROM_SELECTION",
"DXF_TEXT = ' ' OR DXF_TEXT IS NULL")
With i run the following in ArcMap python window
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0: arcpy.SelectLayerByAttribute_management(
"DXF_TEXT = ' ' OR DXF_TEXT IS NULL"
I get error,
ERROR 000732: Selecting Features: Dataset DXF_TEXT = '' OR DXF_TEXT IS NULL does not exist or is not supported
Failed to execute (SelectLayerByLocation).
The blank and NULL records don't get removed.
You are missing the first two arguments for the Select Layer By Attribute tool.
oh my bad i had 'Select by Location' instead of 'Select layer by attribute'.