Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
    
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. –  GISKid Jul 14 at 19:50

3 Answers 3

It has already been created. Try SplitLayerByAttributes

share|improve this answer

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.

share|improve this answer
    
check the scripts in my thread if you are interested in coding details –  Dan Patterson Jul 18 at 18:14

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?

share|improve this answer
    
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) –  Oliver Burdekin Jul 18 at 17:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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