1

I have a feature class that has data for the whole month of January with 'date' as one of the attribute categories (labeled ARGH here). I want to grab the information for each day in January and stick it in it's own feature class, so I have 31 separate files. So, as you'll see in the code below, I perform a query for each day, make a feature layer for that day's info and save the layer file to my gdb.

I don't get any error messages when I run it. HOWEVER, I can't find the saved layer files anywhere. I've looked all over. I can't figure out where I've gone wrong.

import arcpy, os
arcpy.env.workspace = "L:\\gathr\\indonesia\\Sara\\SAISData\\AAAS\\SAIS2.gdb"
arcpy.env.overwriteOutput = True

Source_File = "AIS_Jan2016_CorrectTIme"

field = "ARGH"
Day_List = [row[0] for row in arcpy.da.SearchCursor(Source_File,"ARGH")]
Day_List1 = [x.encode('UTF8') for x in Day_List]
UniqueDay = set(Day_List1)
UniqueDay_List = list(UniqueDay)
print UniqueDay_List

arcpy.env.workspace = "L:\\gathr\\indonesia\\Sara\\SAISData\\AAAS\\SAIS2.gdb"
outputpath = "L:\\gathr\\indonesia\\Sara\\SAISData\\AAAS\\SAIS2.gdb"
for day_query in UniqueDay_List:
    out_layer = str(day_query)+ "lyr"
    out_layer_name= "s" + out_layer 
    #out_layer_fc= "fc" + out_layer

    #MakeFeatureLayer variables
    in_features = "AIS_Jan2016_CorrectTIme"

    where_clause = ['ARGH = ' + "'" + day_query + "'"]
    #so as an sql-type query this would be ARGH = 'day_query' or something similar
    print where_clause
    workspace = "L:\\gathr\\indonesia\\Sara\\SAISData\\AAAS\\SAIS2.gdb"

    try:
        #Execute MakeFeatureLayer
        print in_features
        print out_layer
        print where_clause
        print workspace
        arcpy.MakeFeatureLayer_management(in_features, out_layer, where_clause, workspace)

        #Execute SaveToLayerFile
        arcpy.SaveToLayerFile_management(in_layer, out_layer_name)

    except:
        print arcpy.GetMessages()
5

A Layer file .lyr is a file, not something you can store in a geodatabase. You are trying to store your new file inside L:\gathr\indonesia\Sara\SAISData\AAAS\SAIS2.gdb (your arcpy.env.workspace).

In order to save your layer file you will need to specify an output folder to save it in as part of your out_layer_name

out_layer_name = os.path.join(r"c:\myfolder", "s" + out_layer)

which will save your layer file to something like c:\myfolder\sMyValuelyr (where MyValue is the value from str(day_query) in the line out_layer = str(day_query)+ "lyr")

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.