Select to view content in your preferred language

Creating new shapefile based on its attributes with python

943
1
Jump to solution
12-08-2012 10:48 AM
SenthilnathanThyagarajan
Emerging Contributor
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.

Thank You.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
T__WayneWhitley
Honored Contributor
...don't know if the moderator wants to delete this thread or if sxt128130 can remove it, but this was answered yesterday in a cross-post here:

http://forums.arcgis.com/threads/54927-Creating-Many-Shapefiles-Features-using-Python-Model-Builder-....

The basic answer offered, copied from that post (also, thanks to Mathew Coyle and Dan Patterson for the earlier guidance)--
import arcpy fc = "D:\\2010.shp" yrs = [1991,1992,1996,1998,1999,2000,2003,2004,2005,2006,2008,2010] 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)


Thanks,
Wayne

View solution in original post

0 Kudos
1 Reply
T__WayneWhitley
Honored Contributor
...don't know if the moderator wants to delete this thread or if sxt128130 can remove it, but this was answered yesterday in a cross-post here:

http://forums.arcgis.com/threads/54927-Creating-Many-Shapefiles-Features-using-Python-Model-Builder-....

The basic answer offered, copied from that post (also, thanks to Mathew Coyle and Dan Patterson for the earlier guidance)--
import arcpy fc = "D:\\2010.shp" yrs = [1991,1992,1996,1998,1999,2000,2003,2004,2005,2006,2008,2010] 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)


Thanks,
Wayne
0 Kudos