Need help with Merge GeoProcess task in ArcEngine (C#)

1832
1
12-14-2011 02:46 AM
Highlighted
by
New Contributor III
Help!  Having the hardest time getting the correct syntax when adding layers as gp parameters to call the Merge_management GeoProcessing Task.  Below is just one of MANY, MANY ways I have tried with no luck.  Can anyone help? 

I've successfully called many GeoProcessing tasks via code in ArcEngine, but this is the first one to take what appears to be an array ( ie. [layer1,layer2,etc]) as one of the parameters.

        public void RunMergeGeoProcess(ILayer SourceLayer1, ILayer SourceLayer2, string ResultFeatureClassName, string GeoDBAbsFileName)
        {

            IFeatureLayer featureLayerSource1 = (IFeatureLayer)SourceLayer1;
            IFeatureLayer featureLayerSource2 = (IFeatureLayer)SourceLayer2;


            _geoProcessor.SetEnvironmentValue("Workspace", GeoDBAbsFileName);
            //_gpParams.Add(featureLayerSource1);
            ////_gpParams.Add(featureLayerSource2);

            IWorkspace refWS = ((IDataset)featureLayerSource1.FeatureClass).Workspace;
            string dbPath = refWS.PathName;
           
            IDataset myDS1 = featureLayerSource1.FeatureClass as IDataset;
            string mysDS1 = dbPath + "\\" + myDS1.Name;
            IDataset myDS2 = featureLayerSource2.FeatureClass as IDataset;
            string mysDS2 = dbPath + "\\"+ myDS2.Name;

            string myResult = dbPath + "\\" + ResultFeatureClassName;

            string param1 = "[" + mysDS1 + ", " + mysDS2 + "]";

            _gpParams.Add(param1);
            _gpParams.Add(myResult);


            try
            {
                _geoProcessor.OverwriteOutput = true;
                _geoProcessor.Execute("Merge_management", _gpParams, null);
                //returnMessages(_geoProcessor);
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was a GeoProcessing Error." + ex.ToString());
                returnMessages(_geoProcessor);
            }

            _gpParams.RemoveAll();

        }
Reply
0 Kudos
1 Reply
Highlighted
by
New Contributor III
Reply
0 Kudos