I have ArcMap and a shapefile attribute table with lots of columns. Each column contains values between -1 and 1. For each column, I would like to select the values greater than 0 and then export a new shapefile from that selection. I have about 100 columns so don't want to do it one by one. Do I have to use ModelBuilder or python to do this?

  • 1
    How is your python? It would be tedious to do this with model builder but only a small task with arcpy. May 30 '17 at 0:48
  • What is your field type? float, double, or string?
    – Fezter
    May 30 '17 at 1:17

I would recommend doing this in arcpy/python script, here are the general workflow steps:

  1. Make feature layer of feature class
  2. Create a list variable of all 100 field names you want to query against
  3. Create a for loop and loop through each value of step 2 list
  4. Within the loop use the Select tool and set an expression with the current list value/field name and create a new shapefile from field values > 0. Note you may want to incorporate the field name into the new shapefiles name so you can keep track of the feature classes created based on the field name queried and used to create it.

Continue looping and creating shapefiles from step 3-4


import arcpy arcpy.env.workspace = "workspace location" shp = "shape file location"

fc = arcpy.MakeFeatureLayer_management(shp)

field_names = [] field_names = [f.name for f in arcpy.ListFields(shp)]

print field_names

field_names.remove("FID") field_names.remove("Shape") field_names.remove("gid")

for fieldname in field_names: expression = '"{}" > 0'.format(fieldname) arcpy.Select_analysis(fc, fieldname, expression)

Using @artwork21 methodology, try the below:

import arcpy
arcpy.env.workspace = r"location/to/workspace"
shp = r"enter/featureclass/location"

fc = arcpy.MakeFeatureLayer_management(shp)

fields = arcpy.ListFields(fc)

fieldlist = []
for field in fields:
    print field.name

print fieldlist 
#need to remove the fields you dont want from the list
fieldlist.remove("enterfieldname", "nextfieldnametoremove") #you can add multiple field names to remove   

for fieldname in fieldlist:
    expression = """{} > 0""".format(fieldname)
    arcpy.Select_analysis(fc, fieldname, expression)
  • Note of caution, ListFields will return all fields which may not need queried/selected against.
    – artwork21
    May 30 '17 at 14:20
  • ive added a method of identifying the fieldnames and removing the ones you dont need.
    – MacroZED
    May 30 '17 at 14:31
  • Thanks guys! I ran the code but encountered "Runtime error Traceback (most recent call last): File "<string>", line 11, in <module> AttributeError: 'list' object has no attribute 'name'"?
    – Sisi
    Jun 5 '17 at 19:58
  • try that again. f.name should have been field.name
    – MacroZED
    Jun 5 '17 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.