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 currently have a search cursor iterating through a shapefile in ArcGIS 10.1 that selects a feature and runs a viewshed analysis on that feature (and only that feature). What's the easiest way to also export that same feature to a shapefile with the same name in Python?

fieldFID = 'FID'

arcpy.MakeFeatureLayer_management (inPoints, "pts")

with arcpy.da.SearchCursor('pts',[fieldFID]) as cursor:
    for row in cursor:
        fid = str(row[0])
        print fid
        arcpy.SelectLayerByAttribute_management ("pts", "NEW_SELECTION", '"FID" = {}'.format(fid))
        outViewshed = Viewshed(inDEM,"pts",1,"CURVED_EARTH",0.15)"C:/temp/output/viewsheds/"+fid)

Thanks again!

share|improve this question
Generally speaking, all ArcGIS GP operations behave on 1) the selected features , and 2) the whole data set if none is selected. Therefore, as long as you have features selected, only those features will be exported. – RyanDalton May 2 '13 at 14:39
up vote 14 down vote accepted

You can use the Feature Class To Feature Class python snippet. Here is the general syntax.

FeatureClassToFeatureClass_conversion (in_features, out_path, out_name, {where_clause}, {field_mapping}, {config_keyword})

To output to a shapefile, make sure that your out_path is a folder (and not pointing within a file geodatabase), and that out_name has a *.shp extension.

share|improve this answer
Will this output to a shapefile? – Spatial Pariah May 2 '13 at 13:43
If out_path is a folder, it will be a shapefile. – nmpeterson May 2 '13 at 13:51
Yes, just make sure your out_path is not pointing within a geodatabase and out_name has a .shp extension. – artwork21 May 2 '13 at 13:51
Worked great, thanks! – Spatial Pariah May 2 '13 at 13:59

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.