How to process selected features one by one in feature layer

837
2
12-17-2018 12:05 PM
CongHuang
New Contributor II

I'm working with ArcGIS Pro, SDK, try to make an add-in button that can process my selected features one by one. Now I have FeatureLayer feature_layer = layer_made[0] as FeatureLayer; I know this feature_layer already contains my selection, and I can get all selection object ID through GetSelection().GetObjectID() method. I can make a selection by using query filter, e.g feature_layer.select(query).

My question is, how can I convert this selection to feature layer? I know I can use MakeFeatureLayer, but this way will create a feature layer on the map, I just want all this processing finish in backstage. Is any way I can directly convert the selection into a feature layer?

0 Kudos
2 Replies
by Anonymous User
Not applicable

Cong,

Try creating a new feature class then copying the features into it. Only the selected features will be copied.

      //create feature class via GP
      var mva = Geoprocessing.MakeValueArray(@"C:\arcgis\ArcTutor\Editing\Zion.gdb", "test", "POINT","","DISABLED","DISABLED",MapView.Active.Map.SpatialReference);
      var cts = new System.Threading.CancellationTokenSource();
      Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management", mva, null, cts.Token, null, GPExecuteToolFlags.None);

      //copy selected features from a layer in the map to feature class
      mva = Geoprocessing.MakeValueArray("Ranger stations", @"C:\arcgis\ArcTutor\Editing\Zion.gdb\test");
      Geoprocessing.ExecuteToolAsync("CopyFeatures_management", mva,null,cts.Token,null,GPExecuteToolFlags.None);

You might want to create the feature class using a template so the schemas match the selection.

Setting the tool flags to 'none' ensures the output isn't added to the map.

CongHuang
New Contributor II

Thank you, Sean, I will try this way. Just wondering, Once I do the copy, can I use the SQL? Just like ArcPy, like:

mva = Geoprocessing.MakeValueArray("Ranger stations", @"C:\arcgis\ArcTutor\Editing\Zion.gdb\test","OBJECTID=3");
0 Kudos