3

I am writing an ArcMap Add-In to combine multiple shapefiles and then run some custom python scripts on the resulting shapefile. However I cannot seem to get the Geoprocessor working to run the FeatureToLine tool. I am using the ArcGIS SDK 10.4 for .NET.

private void Button5_Click(object sender, EventArgs e)
    {
        Geoprocessor gp = new Geoprocessor();
        gp.OverwriteOutput = true;

        try
        {
            FeatureToLine FTLTool = new FeatureToLine();

            List<string> inputs = new List<string>();

            string[] ins = new string[] { @"D:\\Code projects\\Network-WZRD\\Network Wzrd\\Data\\Centerlines\\Roadway\\Delaware.shp", 
                @"D:\\Code projects\\Network-WZRD\\Network Wzrd\\Data\\Centerlines\\Trails\\Trails.shp" };

            FTLTool.in_features = ins;
            FTLTool.out_feature_class = @"D:\\Code projects\\Network-WZRD\\Network Wzrd\\atestout.shp";
            ITrackCancel pTrackCancel = new CancelTracker();
            pTrackCancel.CancelOnKeyPress = true;

            gp.Execute(FTLTool, pTrackCancel);
        }
        catch(Exception ex)
        {
            MessageBox.Show("Error\nAn error occured while attempting to merge shapefiles.\n" + ex.Message);
        }

    }//button5_Click -- Final Load

I know I am incorrectly inputing my shapefiles. But I couldn't find any examples of tools that used multiple inputs in the In_Feature field. I get a general error when it gets to execute the tool

Error HRESULT E_FAIL has been returned from a call to a COM component

The questions I have are: How can I input multiple shapefiles into the tool? Does the output need to be an existing shapefile object within the code, or can it just be a path to where I would like the resulting shapefile to be put?

EDIT: I tried Hornbydd's suggestion, and used the exact example in the sample code and got the same error code.

    public void ExampleGPUsingMultipleInputs()
    {

        // Initialize the geoprocessor.
        Geoprocessor GP = new Geoprocessor();

        // Initialize the Union tool.
        Union uniontool = new Union();

        // List all feature classes in the workspace.
        GP.SetEnvironmentValue("workspace", @"D:\Code projects\Network-WZRD\Network Wzrd\Data\Centerlines\Trail");
        IGpEnumList fcColl = GP.ListFeatureClasses("*", "", "");

        // Create a StringBuilder object and add the feature classes as a semicolon-delimited list.
        StringBuilder sb = new StringBuilder();
        string inputfeatures = fcColl.Next();

        while (inputfeatures != "")
        {
            System.Diagnostics.Debug.WriteLine(inputfeatures);
            sb.AppendFormat("{0};", inputfeatures);
            inputfeatures = fcColl.Next();
        }

        // Execute the Union tool with multiple inputs creating landuse.shp.
        uniontool.in_features = sb.ToString();
        uniontool.out_feature_class = "landuse.shp";
        GP.Execute(uniontool, null);

    }
2

I suspect the error is related to how you set your input features. Have a look at How to use multiple inputs, it gives examples in c# and vb.

  • I used the code from the example you gave (I just changed the directories to ones populated with 2 shapefiles) and got the same result: Exception thrown: 'System.Runtime.InteropServices.COMException' in ESRI.ArcGIS.Geoprocessor.dll – Zooloo10 Jun 29 '16 at 14:26
  • 1
    Solved it. the union tool doesnt accept shape files with polyLines. But the feature to line does and it worked! Using a semicolon delineated list for the inputs like: FTLTool.in_features = @"D:\Code projects\Trail\Trails.shp;D:\Code projects\Trail\Trails2.shp;"; – Zooloo10 Jun 29 '16 at 15:43

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.