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.
1 Answer 1
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"...
Explore related questions
See similar questions with these tags.