14

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.CheckOutExtension("Spatial")

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)
        outViewshed.save("C:/temp/output/viewsheds/"+fid)
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
CodeSpatial
  • 830
  • 2
  • 10
  • 18
  • 1
    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. – RyanKDalton May 02 '13 at 14:39

1 Answers1

19

You may 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.

artwork21
  • 35,114
  • 8
  • 66
  • 134