Empty Feature class created?

3386
3
Jump to solution
08-20-2015 02:02 PM
CCWeedcontrol
Occasional Contributor III

I have a script here and seems simple enough but for some reason after the script is done it creates an empty feature class. I don't get any errors..  Am i missing something?

# Import arcpy module
import arcpy
import os
from arcpy import env
from datetime import datetime as d
startTime = d.now()

arcpy.env.workspace = "C:\GIS\weeds\Weeds.gdb"
arcpy.env.overwriteOutput = "True"
arcpy.env.qualifiedFieldNames = False

CITY = "C:\GIS\weeds\Weeds.gdb\City_Limits"

Taxparcels = "C:\GIS\weeds\Weeds.gdb\Parcels"
ADMIN = "C:\GIS\weeds\Weeds.gdb\ADMIN"
temp = "C:\GIS\weeds\Weeds.gdb"

# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(Taxparcels, "In_memory\Par")

# Process: Analysis Erase
arcpy.Erase_analysis("In_memory\Par", CITY, "In_memory\Par_ERASE","")

arcpy.MakeFeatureLayer_management("In_memory\Par_ERASE", "In_memory\Par1")

# Process: Add Join
try:
    arcpy.AddJoin_management("In_memory\Par1", "ACCOUNT", ADMIN, "Acct", "KEEP_ALL")
except BaseException as e:
    pass
#arcpy.FeatureClassToFeatureClass_conversion("In_memory\Par1", temp, "TaxWeed1")#working
arcpy.MakeFeatureLayer_management("In_memory\Par1", "In_memory\Par2")

# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management("In_memory\Par2", "NEW_SELECTION", "\"TEXT\" = 'common area'")

# Process: Delete Features
if int(arcpy.GetCount_management("In_memory\Par2").getOutput(0)) > 0:
    arcpy.DeleteFeatures_management("In_memory\Par2")

    
# Process: Make Feature Layer (2)
TaxPar2 = "weedtax"
arcpy.MakeFeatureLayer_management("In_memory\Par2", TaxPar2)

arcpy.FeatureClassToFeatureClass_conversion(TaxPar2, temp, "TaxWeed")
arcpy.Delete_management("In_memory\Par")
arcpy.Delete_management("In_memory\Par1")
arcpy.Delete_management("In_memory\Par2")
arcpy.Delete_management("In_memory\Par_ERASE")
#arcpy.Delete_management("In_memory\ParCel")

try:
    print '(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')'

except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

My guess, line #39 is deleting all of the features, so line #46 is copying an empty feature class to make a new, empty feature class.  When using the Select Layer By Attribute tool, be careful because all records are returned if no records meet the criteria.

View solution in original post

3 Replies
JoshuaBixby
MVP Esteemed Contributor

My guess, line #39 is deleting all of the features, so line #46 is copying an empty feature class to make a new, empty feature class.  When using the Select Layer By Attribute tool, be careful because all records are returned if no records meet the criteria.

CCWeedcontrol
Occasional Contributor III

ok, so if no records are found in line 35, then at 39 it's selecting all records because nothing was found. So how can i by pass line 35 in case nothing is found?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Although a bit kludgy, you can run a Get Count before the selection and store that number.  Then, after the selection, you can compare the new Get Count with the old one.  If they are the same, nothing was selected.

0 Kudos