Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a shapefile which has an attribute year. I used to generally copy and paste these features in the dataframe and then using the definition query just show polygons which were established before that year.

I want to know how can I do it using python. Like if I can give the input feature class, add all the years I want the different shapefiles for and the workspace where it can create shapefile for the mentioned years with the right naming convention.

share|improve this question
What is "the right naming convention"? What version of ArcGIS are you working with? Are you looking to implement this as a script tool, a standalone Python script, a Python add-in, etc.? How do you want the user to interact with the script or tool? What inputs are required, and what are the desired results given a set of inputs? Try to describe each of these requirements in as exact language as possible otherwise it is easy to misinterpret what you are trying to do. – blah238 Dec 9 '12 at 1:47
up vote 2 down vote accepted

I believe this was 'cross-posted' on another site... and the problem was answered with code below. (special thanks extended for the invaluable guidance by Mathew Coyle and Dan Patterson, as well as others on this site)

import arcpy
# input fc
fc = "D:\\2010.shp"
# the yr 'breaks'...hard-coded as a Python list.
yrs = [1991,1992,1996,1998,1999,2000,2003,2004,2005,2006,2008,2010]
# initialize variable (part of SQL qry) to remove previous selections
subtract = ''
for yr in yrs:
     where = '"Year" <= ' + str(yr) + subtract
     subtract = ' AND "Year" > ' + str(yr)
     filename = str(yr) + '.shp'
     arcpy.FeatureClassToFeatureClass_conversion(fc, "D:\\test output", filename, where)
share|improve this answer

This can be accomplished using Select Layer by Attribute followed by Copy Features.

For a more tailored answer, please see my comments above.

share|improve this answer
Good answer. Using this methodology, you could also very easily script what your particular attribute queries are going to be, and then just run the Select Layer by Attribute tool iteratively over all of your predefined queries. – RyanDalton Dec 9 '12 at 4:03

If you want to split the file into separate shapefiles based upon year then check out Split layer by Attributes

Split Layer by Attributes

share|improve this answer
Say for instance I have a field years. I may have 25 unique values but I just want to create 10 shapefiles and that too such that one shapefile which has years<=1990. Second shapefile years <= 1995. Is that doable in the script written by you. – SNT Dec 8 '12 at 22:08
Link doesn't work anymore. – Paul Richter Feb 8 at 17:28
I Fixed the link – Dan Patterson Feb 8 at 17:35

Your Answer


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.