# Wetlands buffer.py
# Description: Program that determines if Wetlands are within 0.5 miles of specific point files with the program returning a 'yes' or 'no' if a wetland is within the range or not.

# Import ArcGIS python library
import arcpy

# Define workspace
arcpy.env.workspace = "P:\Python"

# create buffer around single substation
substation_buffer = arcpy.Buffer_analysis("substation.shp", "P:\Python\substation_buffertest", "0.5 Miles", "FULL", "ROUND", "LIST", "", "PLANAR")
print "Made buffer layer"

# turn substation_buffertest into a feature layer for the select by location tool
fl = arcpy.MakeFeatureLayer_management("substation_buffertest.shp", "buffer_layer")
print "Made feature layer"

# select wetlands within buffer
wetland_selection = arcpy.SelectLayerByLocation_management("buffer_layer", "CONTAINS", "Wetlands.shp", "", "NEW_SELECTION", "NOT_INVERT")
print "Selected by location"

I'm trying to write a program for the company I work for that determines if a point file's buffer zone contains wetlands from another feature class. I'm trying to do this through a search cursor but the attribute table that is created only contains the FID, Shape, and Id. I've made it this far but I'm not so sure where to go from here.

  • 2
    Use CopyFeatures_management to export what's been selected. May 28, 2019 at 20:48
  • 1
    Your code doesn't include a SearchCursor
    – Vince
    May 28, 2019 at 21:23

2 Answers 2


Emil Brundage is correct. The arcpy.CopyFeatures_management tool method exports the selected records of the input FeatureClass (or Layer or TableView) to the output FeatureClass (or Layer or TableView). It is not necessary to use any kind of Cursor to use the geoprocessing tool method, because it acts on the entire input dataset as a whole, not on individual records. This will export the entire selected records to the output dataset.

If you only need a subset of the fields in the input dataset, select the records that you want, use a SearchCursor over the input dataset, loop over the records, and build a list of values for each field that you need. Create the output dataset using CreateFeatureclass_management (or CreateTable_management), add the needed output fields using arcpy.AddField_management, create an InsertCursor for the output dataset to add records, and use row.setValue() to copy the values to the appropriate fields in the output dataset from the values in the corresponding list. Don't forget to delete the cursors and row objects when you are done to free up the allocated memory if you are going to go on and perform other operations on the data.


Actually, a more efficient way to do this if you want the output layer to have the same attributes as the input layer is with

MakeFeatureLayer_management (in_features, out_layer, {where_clause}, {workspace}, {field_info})

(Documentation abridged from ArcPy documentation)

Parameter Explanation:

in_features: The input feature class or layer from which to make the new layer. Complex feature classes, such as annotation and dimensions, are not valid inputs to this tool.

out_layer: The name of the feature layer to be created. The newly created layer can be used as input to any geoprocessing tool that accepts a feature layer as input.

where_clause: (Optional) An SQL expression used to select a subset of features. For more information on SQL syntax see the help topic SQL reference for query expressions used in ArcGIS.

workspace: (Optional) The input workspace used to validate the field names. If the input is a geodatabase table and the output workspace is a dBASE table, the field names may be truncated, since dBASE fields can only have names of ten characters or less. The new names may be reviewed and altered using the field information control

field_info: (Optional) Can be used to review and alter the field names and hide a subset of fields in the output layer. A split policy can be specified. See the usages for more information.


If you use the where_clause, this combines the selection and export steps into one.

  • 1
    Make Feature Layer does not provide an export. It creates a "view" of the data. You'd still need to run CopyFeatures to persist just the selected features into a new featureclass.
    – KHibma
    May 7, 2021 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.