Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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??

share|improve this question
    
please add this question as an edit of your previous question. –  radouxju Jan 19 at 19:37
2  
Could it be to do with your path names? Its bad practice to use & and spaces in folder names. –  Hornbydd Jan 19 at 19:51
    
just for checking, what does print fcs return ? Aren't your features in a feature dataset ? –  radouxju Jan 19 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 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 at 22:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.