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)
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] for yr in yrs: where = '"Year" <=' + yr filename = str(yr) + '.shp' arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", filename, where)
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)
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)
import arcpy fc = "D:\\2010.shp" where = '"Year" <= 1990' arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", "1990.shp", where)
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 ## below is the shapefile which I want to split it into fc = "D:\\2010.shp" # #the sql string which I want all the features to be selected for where = '"Year"<= "1990"' arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", "1990.shp", where)
at the beginning. Forget about the loop and inline substitution for a moment - the 1st priority is to get a single execution of Feature Class To Feature Class going with 1 properly formed query...so do something like this: 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:\\' # your input shapefile inputShp = 'yr2010.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 = "'somefield' = 1991" # 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" Year = ["1991", "1992", "1997"] for yr in Year: where = "contractfield like '%"+1+"%'" arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", "somename"+yr+ as integer".shp", where)
fc = "C:/GIS/test.shp" contracts = ["A", "B", "C"] for cont in contracts: where = "contractfield like '%"+i+"%'" arcpy.FeatureClassToFeatureClass_conversion(templayer, exportdir, "somename"+cont+".shp", where)
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.