1

How can I save selected features to a new feature class?

If I do one of the following commands always all of the features are copied, and not just the selcted ones.

## First select features
arcpy.management.SelectLayerByLocation(input, "INTERSECT", intersecting_features, None, "NEW_SELECTION", "NOT_INVERT")

## then try one of these to save as new features
new_copy = arcpy.CopyFeatures_management(input, output)

or

new_copy = arcpy.management.Copy(input, output, "FeatureClass", None)

As I mentioned, always all of the features are copied.

3
  • is input a layer ( made with MakeFeatureLayer) ?
    – radouxju
    Commented May 2, 2022 at 9:36
  • Input is a layer straight imported from file
    – Saelon
    Commented May 2, 2022 at 10:54
  • the selection is stored in a layer, not a feature class
    – radouxju
    Commented May 3, 2022 at 9:28

1 Answer 1

2

You can try to save the result of the selection in a variable and then copy the value in the variable.

sel = arcpy.management.SelectLayerByLocation(input, "INTERSECT", intersecting_features, None, "NEW_SELECTION", "NOT_INVERT")


new_copy = arcpy.CopyFeatures_management(sel, output)

1
  • That was it! Thank you very much! I just had to copy the variable!
    – Saelon
    Commented May 3, 2022 at 8:18

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.