Select to view content in your preferred language

Export selected polygons

1274
3
Jump to solution
07-31-2012 06:09 AM
DaveJordan1
Regular Contributor
What is the code I need to export the selected set of Polygons?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChristopherThompson
Frequent Contributor
If you want to create a new feature class from the selection arcpy.CopyFeatures_management will do it:

arcpy.CopyFeatures_management(SelectedFeatures,'afilepath\NewFeatures.shp')


The above presumes the output is a shapefile, if you were copying into a new geodatabase feature class you'd have to set up the reference to the gdb and drop the .shp from the name.

If you want the selection to go into an existing featureclass the the append tool is probably more what you are looking for.

View solution in original post

0 Kudos
3 Replies
BruceNielsen
Frequent Contributor
CopyFeatures_management
0 Kudos
ChristopherThompson
Frequent Contributor
If you want to create a new feature class from the selection arcpy.CopyFeatures_management will do it:

arcpy.CopyFeatures_management(SelectedFeatures,'afilepath\NewFeatures.shp')


The above presumes the output is a shapefile, if you were copying into a new geodatabase feature class you'd have to set up the reference to the gdb and drop the .shp from the name.

If you want the selection to go into an existing featureclass the the append tool is probably more what you are looking for.
0 Kudos
by Anonymous User
Not applicable
I usually will use the MakeFeatureLayer command to make a layer from a feature class based on a query and then use CopyFeatures to export it out into its own feature class.  I have an example below:

   
arcpy.MakeFeatureLayer_management(feature, feat_lyr)
    arcpy.SelectLayerByAttribute_management(feat_lyr, 'NEW_SELECTION', query)
    arcpy.SelectLayerByAttribute_management(feat_lyr, 'SUBSET_SELECTION', query3)
    
    result = arcpy.GetCount_management(feat_lyr)
    print "Number of selected addresses in the layer: " + str(result)

    #Copy selected features to new feature class
    if arcpy.Exists(output):
        arcpy.Delete_management(output)
        
    arcpy.CopyFeatures_management(feat_lyr, output)
    print "Copied selected features from urban points layer to: " + output


I hope this helps!

Caleb
0 Kudos