I am stuck on how to create multiple features classes from one feature class using a select few fields. I have the following attribute table for a shapefile.
I would like to select the 'USAF', 'COUNT', 'ADMIN_1' fields and append one year field from 2000, 2001, 2002...2014), such that the attribute fields of the new feature classes will be:
'USAF', 'COUNT', 'ADMIN_1', '2000'
'USAF', 'COUNT', 'ADMIN_1', '2001'
'USAF', 'COUNT', 'ADMIN_1', '2002'
. . .
Till 2014.
I have been trying to work it out using modelbuilder and a python script (separately) and haven't been close to successful. Here is a script I wrote to test on the first year, but the resultant shapefile is identical to the input
#import the arcpy site-package
import arcpy
from arcpy import env
env.workspace = "Z:\\GEOG517\\siu850437305\\Project\\Results" #set current workspace
env.overwriteOutput = True #allow outputs to be overwritten
#List variables
in_file = "Z:\\GEOG517\\siu850437305\\Project\\shapefiles\\sahel_ppt.shp"
arcpy.MakeFeatureLayer_management(in_file, "stationslyr.shp")# Make a layer from the feature class
stations = "stationslyr"
#Create field list iterate through using for loop
fields = arcpy.ListFields(stations)
for field in fields:
for field.name == '2000':
if field.name == "2000":
arcpy.SelectLayerByAttribute_management(stations, "new_selection" )
arcpy.CopyFeatures_management(stations, "yr2000")# Write the selected features to a new featureclass
print ("Created yr2000")
break
Then tried to append the years on using:
field_names = []
fields = arcpy.ListFields(stations)
for field in fields:
field_names.append(field.name)
but that failed too! I am not even sure there is a tool to do this. I am new to python scritping for geoprocessing tasks so I am not looking for a really complex method just a simple and straightforward way to do this.