3

I have a large data shapefile for the state of New York. Each shape has a code corresponding to each county, so I want to iterate "Selection by Attribute" for each code, create a layer from all the parcels with the same county code, and export that into a separate shapefile.

How would I go about doing this? I am using Arcmap 10.1

1
  • I added tags for your post. You're going to want to look into model builder and python. I'd suggest editing your questions with what you've tried, screenshots of your data, etc. As it stands now it doesn't really fit the guidelines for asking a good question.
    – GISHuman
    Jul 14, 2014 at 19:50

3 Answers 3

6

It has already been created. Try SplitLayerByAttributes

0

One way this can be done is in a python script.

You'd need to ask for the name of the field you are interested in (in your case it would be the county code) and extract unique values from its rows with a SearchCursor. You could save the data to a list and then iterate through the list and use a where clause with arcpy.Select and output each separate category into its own shapefile.

If you're python savvy I can elaborate a bit more on it.

1
  • check the scripts in my thread if you are interested in coding details
    – user681
    Jul 18, 2014 at 18:14
0

I've just written this for a similar task. It's for 10.2 but I think it will still work:

def unique_values(table, field):
with arcpy.da.SearchCursor(table, [field]) as cursor:
dict = sorted({x[0] for x in cursor})
print type(dict) #testing to find type 
for i in range(len(dict)):

    whereD = dict[i]
    fname = whereD[0:5] + "_" + whereD[-4:] #just to make a filename for outputs
    arcpy.MakeFeatureLayer_management(table, fname)
    query = "relatedBirds_Species = '" + whereD + "'"
    arcpy.SelectLayerByAttribute_management(fname, "NEW_SELECTION", query)
    arcpy.CopyFeatures_management(fname,fname+ "_c") #add a "_c" to output to differ from intermediate files

If you put the above into notepad and save as something.py, in ArcGIS you can open the python window, right click>load, navigate to the something.py file and load it in. Hit enter a couple of times to get back to the >>>>> prompt.

Then you just call the method with unique_values("c:/whatever_location/yourfile.shp","field_in_question")

Depending on your data it might take a while to run. I'm trying to speed it up now. See:

Iterating using search cursor and layer selection performance?

1
  • Just to add, if your attribute code is a number you'll need to change the fname line to something like fname = "fn_" + str(whereD) Jul 18, 2014 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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