1

I am using SubsetFeatures_ga to create a random dataset within a file geodatabase and am trying to save the output feature class in a feature dataset but it keeps getting saved in the root of the file geodatabase. I have ArcMap 10.3.1 installed and am using Python 2.7 to run the code. I have already read this post which simulates the same problem but it was apparently solved by ESRI at ArcMap 10.1.

Here is the code:

import sys, string, os, arcpy
from arcpy import env
env.workspace = "J:/data/database/test.gdb/polygons/"
arcpy.CheckOutExtension("GeoStats")
in_features = "polys"
out_training_feature_class = "polys_train"
out_test_feature_class = ""
size_of_training_dataset = "10"
subset_size_units = "PERCENTAGE_OF_INPUT"
arcpy.SubsetFeatures_ga(in_features,out_training_feature_class,out_test_feature_class,size_of_training_dataset,subset_size_units)

Here is an image of the database structure:

enter image description here

And this is what it looks like after I run my script (you can see how 'polys_train' is output into the root of test.gdb)

enter image description here

1

This seems to be as a bug in a GP tool SubsetFeatures. I have the same results as you on 10.3.1 - it's impossible to save the output feature class in the same feature dataset where the input feature class comes from. This is not specific to arcpy, because running the GP tool in ArcMap results in the same behavior - the output feature class is saved into root of the geodatabase.

The workaround is to use an intermediate step writing your output first to an in_memory geodatabase and then saving the output training feature class in the feature dataset.

This is what your code would look like:

import sys, string, os, arcpy
from arcpy import env
env.workspace = "J:/data/database/test.gdb/polygons/"
arcpy.CheckOutExtension("GeoStats")
in_features = "polys"
memory_out_training_feature_class = "in_memory\polys_train"
disk_out_training_feature_class = "polys_train"
out_test_feature_class = ""
size_of_training_dataset = "10"
subset_size_units = "PERCENTAGE_OF_INPUT"
arcpy.SubsetFeatures_ga(in_features,memory_out_training_feature_class,out_test_feature_class,size_of_training_dataset,subset_size_units)

arcpy.CopyFeatures_management(memory_out_training_feature_class,
                              disk_out_training_feature_class)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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