# The field you're querying queryfield = "KEY" # Read the file into a list data = text_file.readlines() # Strip the data of trailing newlines cleandata = [x.strip() for x in data] # Put single quotes around each string for SQL-friendliness queryterms = ["'%s'"%x for x in cleandata] # Put ", " between each of the queries comma_sep_terms = ", ".join(queryterms) # Then make the full expression querystring = '"%s" IN (%s)'%(queryfield,comma_sep_terms) # Use the Select tool once gp.Select(input_shapefile,output_dataset,querystring)
all_lines_to_query = [x.strip() for x in in_file.readlines()] first_half = all_lines_to_query[:len(all_lines_to_query)/2] second_half = all_lines_to_query[len(all_lines_to_query)/2:]
# Text files output = "D:\\Subblocks\\SubblocksOutput.txt" # Set overwrite property gp.OverWriteOutput = 1 # Make feature layer gp.MakeFeatureLayer("D:\\SUBBLOCKS.shp", "feature_lyr") # Open output file in read only mode text_file = open(output, "r") # Read the file into a list data = text_file.readlines() # Strip the data of trailing newlines cleandata = [x.strip() for x in data] # Quick function to put the data into SQL syntax querify = lambda st: '"KEY" = \'%s\''%st # Apply that function to all data (transforming each element from "a1" to "KEY" = 'A1') queryterms = map(querify,cleandata) # Put " OR " between each of the queries querystring = " OR ".join(queryterms) # Use the Select tool once gp.Select(input_shapefile,output_dataset,querystring) # Close text file text_file.close() # Free memory del gp
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.