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 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)

Thanks again!

share|improve this question
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. –  RyanDalton May 2 '13 at 14:39

1 Answer 1

up vote 9 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
2  
If out_path is a folder, it will be a shapefile. –  nmpeterson May 2 '13 at 13:51
1  
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

 
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.