-1

I've been trying to use this code to add a field to, merge, and sort multiple feature classes:

import arcpy, os

arcpy.env.workspace = r'W:\S&P\s&p techs\Emily\TownshipsDissolved\FinalDissolved.gdb'

#Looping through dissolved feature classes, adding 'Name' field and writing
#feature class name in the added field.
fcs = arcpy.ListFeatureClasses()

for fc in fcs:
    arcpy.AddField_management(fc, "Name", "TEXT", field_length = 50)
    with arcpy.da.UpdateCursor(fc, "Name") as cursor:
      for row in cursor:
        row[0] = fc
        cursor.updateRow(row)


#Merging the multiple feature classes into one named OSRS_ORN_NER.
mergeOutput = r'W:\S&P\s&p techs\Emily\TownshipsDissolved\FinalDissolved.gdb\OSRS_ORN_NER'
sortOutput = r'W:\S&P\s&p techs\Emily\TownshipsDissolved\FinalDissolved.gdb\OSRS_ORN_NER_new'

arcpy.Merge_management(fcs, mergeOutput)


#Sorting by HWY_NUM_PR and replacing OSRS_ORN_NER by the sorted feature class.

arcpy.Sort_management(mergeOutput, sortOutput, [["HWY_NUM_PR", "ASCENDING"]])

but when I run it I get an error that says this: enter image description here

does anyone know what I'm doing wrong??

  • please add this question as an edit of your previous question. – radouxju Jan 19 '15 at 19:37
  • 3
    Could it be to do with your path names? Its bad practice to use & and spaces in folder names. – Hornbydd Jan 19 '15 at 19:51
  • just for checking, what does print fcs return ? Aren't your features in a feature dataset ? – radouxju Jan 19 '15 at 21:56
  • @radouxju I think it is correct to ask this as a new question rather than "as an edit of your previous question" because the earlier question already has an (accepted) answer that might become invalidated. – PolyGeo Jan 19 '15 at 22:23
  • Please try to always include the text (not screenshots) of code and errors because that way they can be searched. – PolyGeo Jan 19 '15 at 22:24
1

I think you should use Windows Explorer to copy W:\S&P\s&p techs\Emily\TownshipsDissolved\FinalDissolved.gdb to C:\temp and then try replacing:

r'W:\S&P\s&p techs\Emily\TownshipsDissolved\FinalDissolved.gdb'

with:

r'C:\temp\FinalDissolved.gdb'

as a test to see whether it is a problem with your pathname containing an ampersand and/or a space.

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.