Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import arcpy
- from arcpy.analysis import *
- #Define input/output
- input = arcpy.GetParameterAsText(0)
- fieldName = arcpy.GetParameterAsText(1)
- values = arcpy.GetParameterAsText(2)
- output = arcpy.GetParameterAsText(3)
- #Build the where clause
- queryJoin = "' OR " + fieldName + " = '"
- whereClause = fieldName + " = '" + queryJoin.join(values) + "'"
- Select(input, output, whereClause)
- # Import system modules
- import arcpy
- from arcpy import env
- # Set the workspace
- env.workspace = arcpy.GetParameterAsText(0)
- Dir = env.workspace
- # Local variables
- input = arcpy.GetParameterAsText(1)
- polygon = arcpy.GetParameterAsText(2)
- expression = arcpy.GetParameterAsText(3)
- name = arcpy.GetParameterAsText(4)
- # Make a layer from the input feature class
- arcpy.MakeFeatureLayer_management(input, "lyr")
- # Select all points or polygons which overlap the polygon/s of interest
- arcpy.SelectLayerByLocation_management("lyr", "intersect", polygon, 0, "new_selection")
- # Within selected features, further select based on a SQL query within the script tool
- arcpy.SelectLayerByAttribute_management("lyr", "SUBSET_SELECTION", expression)
- # Write the selected features to a new featureclass
- arcpy.CopyFeatures_management("lyr", Dir + "\" + str(name))
- def whereClause(table, field, values):
- """Takes a semicolon-delimited list of values and constructs a SQL WHERE
- clause to select those values within a given field and table."""
- # Add field delimiters
- fieldDelimited = arcpy.AddFieldDelimiters(arcpy.Describe(table).path, field)
- # Split multivalue at semicolons and strip quotes
- valueList = [value[1:-1]
- if (value.startswith("'") and value.endswith("'"))
- else value for value in values.split(';')]
- # Determine field type
- fieldType = arcpy.ListFields(table, field)[0].type
- # Add single-quotes for string field values
- if str(fieldType) == 'String':
- valueList = ["'%s'" % value for value in valueList]
- # Format WHERE clause in the form of an IN statement
- whereClause = "%s IN(%s)" % (fieldDelimited, ', '.join(valueList))a
- return whereClause
- # Add field delimiters
- fieldDelimited = arcpy.AddFieldDelimiters(arcpy.Describe(table).path, field)
- # Split multivalue at semicolons and strip quotes
- valueList = [value[1:-1]
- if (value.startswith("'") and value.endswith("'"))
- else value for value in values.split(';')]
- # Determine field type
- fieldType = arcpy.ListFields(table, field)[0].type
- # Add single-quotes for string field values
- if str(fieldType) == 'String':
- valueList = ["'%s'" % value for value in valueList]
- # Format WHERE clause in the form of an IN statement
- whereClause = "%s IN(%s)" % (fieldDelimited, ', '.join(valueList))a
- return whereClause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement