import arcpy # lines preceded with the '#' symbol are comment lines (not code) # your workspace where all input/output will go for now arcpy.env.workspace = r'D:\\test output' # your input shapefile inputShp = '"D:\\2010.shp' # What is your input shapefile? # your output shapefile outputShp = 'yr1991.shp' # where clause -- substitute 'somefield' with your field (keeping the quotes) # also, is your yr value numeric? where = "'Year' = 1990" # Form Feature Class to Feature Class command based on above params # FeatureClassToFeatureClass_conversion (in_features, out_path, out_name, {where_clause}, {field_mapping}, {config_keyword}) arcpy.FeatureClassToFeatureClass_conversion(inputShp, arcpy.workspace, outputShp, where)
import arcpy fc = "D:\\2010.shp" where = '"Year" <= 1990' arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", "1990.shp", where)
myList = ['strQuery1', 'strQuery2', 'strQuery3'] for eachWhere in myList: # execute Feature Class To Feature class # (substitute 'where' variable with the loop variable, 'eachWhere' [no quotes])
outNames = ['name1', 'name2', 'name3'] whereClauses = ['where1', 'where2', 'where3'] for i in range(len(outNames)): arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", outNames, whereClauses)
for yr in yrs: where = '"Year" <=' + str(yr) + "'" filename = str(yr) + '.shp'
import arcpy fc = "D:\\2010.shp" yrs = [1991,1992,1996,1998,1999,2000,2003,2004,2005,2006,2008,2010] for yr in yrs: where = '"Year" <=' + str(yr) + "'" filename = str(yr) + '.shp' arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", filename, where)
import arcpy fc = "D:\\2010.shp" yrs = [1991,1992,1996,1998,1999,2000,2003,2004,2005,2006,2008,2010] for yr in yrs: where = '"Year" <=' + yr filename = str(yr) + '.shp' arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", filename, where)
import arcpy fc = "D:\\2010.shp" yrs = [1991,1992,1996,1998,1999,2000,2003,2004,2005,2006,2008,2010] for yr in yrs: where = '"Year" <=' + str(yr) + "'" filename = str(yr) + '.shp' arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", filename, where) del yr
import arcpy fc = "D:\\2010.shp" yrs = [1991,1992,1996,1998,1999,2000,2003,2004,2005,2006,2008,2010] subtract = '' for yr in yrs: where = '"Year" <= ' + str(yr) + subtract subtract = ' AND "Year" > ' + str(yr) filename = str(yr) + '.shp' arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", filename, where)