Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ws = arcpy.env.workspace
- mxd = arcpy.mapping.MapDocument("CURRENT")
- data_frame = arcpy.mapping.ListDataFrames(mxd)[0]
- layer = parameters[0].valueAsText #GPFeature Layer
- field = parameters[1].valueAsText #field name
- seach_layer = arcpy.mapping.Layer(layer)
- lfields = arcpy.ListFields(seach_layer.dataSource)
- rows = arcpy.SearchCursor(layer, fields=field)
- #get they field type to use in query
- ftype = None
- for f in lfields:
- if f.name == field:
- ftype = f.type
- # get values for unique list
- value_list = []
- for row in rows:
- value = row.getValue(field)
- value_list.append(value)
- unique = set(value_list)
- len_list = len(unique)
- try:
- for name in unique:
- if ftype in ['Float','Double','SmallInteger']:
- where_clause = ""%s"=%s" %(field, name)
- else:
- where_clause = ""%s"='%s'" %(field, name)
- temp = r"%s_temp_%s" %(layer, field)
- # make a feature layer to an "outfile" that's in memory
- # add to TOC and leave up to user to save if they want
- arcpy.MakeFeatureLayer_management(layer, temp,
- where_clause)
- except Exception as e:
- arcpy.AddError(e)
- arcpy.MakeFeatureLayer_management(layer, temp, where_clause)
- arcpy.SetParameterAsText(0, temp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement