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'm trying to add a field to a layer file, but it always gives an error. What I did was making a closest facility layer and save the result as a layer and after that I tried to add a field, but then it gives an error. It says it cannot add a field if it isn't a raster layer, ...

I tried to avoid this by making a shapefile (manually) and this can work, but is there a method to do this in Python? So convert a route from the closest facility layer to a shapefile using Python? It always says:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Feature Layer.

Thanks!

Regards

share|improve this question
5  
You may want to post your actual Python code to help us better troubleshoot your problem. –  Baltok Apr 4 '13 at 13:39
    
Did you really try to Add Field to a layer file rather than a layer or dataset? If so, that would explain the error message. –  PolyGeo Apr 7 '13 at 12:46
add comment

1 Answer 1

up vote 1 down vote accepted

You might need to add the ValidateFieldName function to your script, which will replace invalid characters with an underscore, and ensure the suggested new field name does not already exist. The code below should get you started:

import arcpy  
fc = "C:/Data/NameOfData.shp" 
fieldname = arcpy.ValidateFieldName("NewFieldName") 
arcpy.AddField_management(fc, fieldname, "TEXT", "","", 12)
share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.