import arcpy,sys from arcpy import env ws = raw_input('Copy/paste the pathname of the folder containing feature classes to select from): ') env.workspace = ws feats = arcpy.ListFeatureClasses() # function prints text to the IDE window def prn_screen(txt): sys.stdout.write(txt+'\n') sys.stdout.flush() feat_dict = {} #creates an empty dictionary # populates above dictionary from the list of features, where the key is # essentially the index of the featureclass in the list for x in range(len(feats)): feat_dict = feats #simply prints the dictonary keys and associated values so the user can see these for key,value in feat_dict.iteritems(): display = str(key) + " : " + str(value) prn_screen(display) # entering a number is easier than typing featureclass names, avoiding seplling errors clip_keys = raw_input('Enter the number for each featureclass you want to clip, commas separating each entry: ') idx_list = [] #converts the raw_input string to a list of numbers that match the dictionary keys idx_list += map(int,clip_keys.split(',')) clip_list = [] for idx in idx_list: clip_list.append(feat_dict[idx])
arcpy.ListFeatureClasses ({wild_card}, {feature_type}, {feature_dataset})
Thanks for the super fast answer!Works great!Thanks!Moving along the script, next, i would like for example to Clip some features.Now, each of the clip parameters can differ at each run of the script (the source layer, the target layer and the output name)How can I do this? (without definning them as parameters in a toolbox)Should I use the raw_input again for each parameter?if so, I can't use the arcpy.env.workspace = r'%s' %CSTFC for the source layer for example, so how do i define the raw_input result as the in feature for the clip command?Thanks for any help
import arcpy, os, sys, traceback ws = raw_input('Please Copy and Paste Worspace Environment\n') arcpy.env.workspace = r'%s' % ws arcpy.env.overwriteOutput = True # Local variables folder = 'Clipped_features' try: if arcpy.Exists(ws): arcpy.CreateFolder_management(ws, folder) clip_feat = raw_input('Copy and paste full path of clip boundary feature\n') fclist = arcpy.ListFeatureClasses() for fc in fclist: arcpy.Clip_analysis(fc, clip_feat, os.path.join(folder, fc)) print 'Clipped: ' + fc else: print 'Workspace does not exist or is not supported'
field = raw_input('type field name') value = raw_input('type value') cliplyr = clip_feat.split('.')[0] query = "%s" = '%s' % (field, value) arcpy.MakeFeatureLayer_management (clip_feat, cliplyr, query) # sub cliplyr in the clip tool if query is used
ws = raw_input('Please Copy and Paste Worspace Environment\n') arcpy.env.workspace = r'%s' % ws
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.