0

I have been trying to add a new field to one of my feature layers. And I keep getting an error and I can't figure out what is going wrong.

I am attaching my code below for reference:

When I changed the spatial reference of the 'tracts10_area', it has created a new feature layer called 'tracts10_area_1' in the mentioned workspace.

I have been trying to add a new field called "Populationdesnity" to my existing layer called "tracts10_area_1". And this is the error that is shown:

input_features = ["tracts10_area"]
out_workspace = r"S:\Grad School\FALL 2020\CEE 424 - GIS for Civil Engineers\Homeworks\HW6 PythonEdition\censusGDB\censusGDB\KingCounty_GDB_census.gdb"
out_coordinate_system = arcpy.SpatialReference(4326)
arcpy.BatchProject_management(input_features, out_workspace, out_coordinate_system)
<Result 'S:\\Grad School\\FALL 2020\\CEE 424 - GIS for Civil Engineers\\Homeworks\\HW6 Python Edition\\censusGDB\\censusGDB\\KingCounty_GDB_census.gdb'>
lyrfile = arcpy.mapping.Layer(r"S:\Grad School\FALL 2020\CEE 424 - GIS for Civil Engineers\Homeworks\HW6 Python Edition\censusGDB\censusGDB\KingCounty_GDB_census.gdb\tracts10_area_1")
 arcpy.AddField_management("tracts10_area_1","Populationdensity","LONG",6,"","","pop_den","NULLABLE","NON_REQUIRED")
Runtime error Traceback (most recent call last):
File "<string>", line 1, in <module> File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\management.py",
line 3424, in AddField raise e ExecuteError: The value cannot be a joined table 
 ERROR 000840: The value is not a Raster Layer. 
 ERROR 000840: The value is not a Raster Catalog Layer. 
 ERROR 000840: The value is not a Mosaic Layer.

ERROR message along with the code

Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
asked Nov 9, 2020 at 19:11
0

1 Answer 1

0

The simplest solution would be something like:

myFC = r"S:\Grad School\FALL 2020\CEE 424 - GIS for Civil Engineers\Homeworks\HW6 Python Edition\censusGDB\censusGDB\KingCounty_GDB_census.gdb\tracts10_area_1"
arcpy.AddField_management(myFC,"Populationdensity","LONG",6,"","","pop_den","NULLABLE","NON_REQUIRED")

This bypasses the need for creating a layer object and directly references the Feature Class.

If you need a layer object consider using MakeFeatureLayer tool then you can reference the layer object with it's name as you have done in your code:

i.e. arcpy.AddField_management("tracts10_area_1","Populationdensity","LONG"...

answered Nov 10, 2020 at 0:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.