Select to view content in your preferred language

Empy feature class

642
5
03-01-2019 07:56 AM
CCWeedcontrol
Frequent Contributor

I can't figure out why i am getting an empty feature class after i delete features, add field and calulate and delete empty features. I would appreciate some help.

Taxparcels = "C:/Temp/Scratchworkspace.gdb/TaxParcels1"

PT = "Taxparce1s"
arcpy.MakeFeatureLayer_management(Taxparcels, PT)

########################################
# Process: Select Layer By Attribute to remove Q accounts
arcpy.SelectLayerByAttribute_management(PT, "NEW_SELECTION", "\"PIN\" LIKE 'Q%'")

# Process: Delete Features
if int(arcpy.GetCount_management(PT).getOutput(0)) > 0:
    arcpy.DeleteFeatures_management(PT)

#arcpy.DeleteField_management(PT, ["ACRES"])

PT1 = "Taxparcels1"
arcpy.MakeFeatureLayer_management(PT, PT1)


arcpy.FeatureClassToFeatureClass_conversion(PT1, "C:\Temp\Scratchworkspace.gdb", "TEST")‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
5 Replies
CCWeedcontrol
Frequent Contributor

I modified the code to this but i am still getting empty features...

Taxparcels = "C:/Temp/Scratchworkspace.gdb/TaxParcels1"

mem_fc = arcpy.CopyFeatures_management(Taxparcels, r"in_memory\TaxPar")
fl = arcpy.MakeFeatureLayer_management(mem_fc, "TaxPar")

query = "PIN LIKE 'Q%'"
arcpy.SelectLayerByAttribute_management(fl, "NEW_SELECTION", query)
if int(arcpy.GetCount_management(fl).getOutput(0)) > 0:
    arcpy.DeleteFeatures_management(fl)

arcpy.FeatureClassToFeatureClass_conversion(fl, "C:/Temp/Scratchworkspace.gdb", "TEST")

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
CCWeedcontrol
Frequent Contributor

After some further investigating i found the issue was with arcpy.env.preserveGlobalIDs.

I had this at the top of my script :arcpy.env.preserveGlobalIds = True: I am not sure why it worked after removing this line.

Why would this create  an empty feature class? The original feature class did not have GlobalIds.

JoeBorgione
MVP Emeritus

So it's working now, correct? 

I have a love hate thing for Global IDs: love 'em for replication.  Hate 'em if they are used for anything else....

That should just about do it....
0 Kudos
CCWeedcontrol
Frequent Contributor

Yes i am good, but still wondering why having arcpy.env.preserveGlobalIds = True would cause an empty feature class.

0 Kudos
JoeBorgione
MVP Emeritus

A straight shot from hip....  Probably has something to do with the fact that you don't have Global IDs to preserve, and things got goofy on you...

That should just about do it....