Pass selected features to a GP process

348
0
06-13-2017 09:20 AM
JordanBaumgardner
Occasional Contributor III

I had a bit of trouble running this down. Thought it might help someone.

 IMxDocument pMxDoc = (IMxDocument)ArcMap.Application.Document;
 IContentsView pTOC = pMxDoc.CurrentContentsView;
 IFeatureLayer exportLayer = (IFeatureLayer)pTOC.SelectedItem; // Selected Layer

 if (!exportAll)
 {
 IFeatureLayerDefinition iDefLayer = (IFeatureLayerDefinition)pTOC.SelectedItem;
 exportLayer = iDefLayer.CreateSelectionLayer(pTOC.Name, true, null, null);  // Selected features
 }

 Geoprocessor gp = new Geoprocessor();
 gp.OverwriteOutput = true;
 gp.AddOutputsToMap = false;

 LayerToKML layerToKML = new LayerToKML();
 layerToKML.layer = exportLayer;
 layerToKML.layer_output_scale = 10000;
 layerToKML.out_kmz_file = fileName;

 try {
 object result = gp.Execute(layerToKML, null);
 messages = new string[gp.MessageCount];
 for (int i = 0; i < gp.MessageCount; i++)
 {
 messages = gp.GetMessage(i);
 }

 return true;
 }
 catch (Exception ex) {
 messages = new string[gp.MessageCount];
 for (int i = 0; i < gp.MessageCount; i++)
 {
 _logger.Error($"GP Message #{i} :"+gp.GetMessage(i));
 }
 return false;
 }
0 Kudos
0 Replies