I am currently working with the Union tool of ArcObjects but I do not know how to properly pass the input_features to the union object. I´ve tried several methods but all throw an Automation Exception (0x80004005 - Unspecified Error). I could not find a single sample for the Union tool in Java.

   GeoProcessor geoProcessor = null;
   try {
        geoProcessor = new GeoProcessor();
        // Get featureclass objects of both shapes
        IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
        IWorkspace workspace = workspaceFactory.openFromFile("C:\\test", 0);
        IFeatureWorkspace featureWorkspace = (IFeatureWorkspace) workspace;
        IFeatureClass fc1 = featureWorkspace.openFeatureClass("a.shp");
        IFeatureClass fc2 = featureWorkspace.openFeatureClass("b.shp");
        // Create IGPValueTableObject and and add featureclasses
        IGpValueTableObject gpvtObject = new GpValueTableObject();
        gpvtObject.setRow(0, fc1);
        gpvtObject.setValue(0, 1, 1);
        gpvtObject.setRow(1, fc2);
        gpvtObject.setValue(1, 1, 2);
         * Also tried this:
         * gpvtObject.addRow(fc1);
         * gpvtObject.addRow(fc2);
        Union union = new Union();
        geoProcessor.execute(union, null);
    } catch (IOException e) {

It looks like the input features are specified as follows:

"X #;Y #;Z #;"

Where X, Y, and Z are either a layer or a path to a feature class and '#' is either a number representing the rank of the feature class or '#' if the feature class has no rank.

So your input would be something like:

"C:\test\a.shp #; C:\test\b.shp #"

I found this by running Union in ArcMap and looking at the Geoprocessing Results window message which lists the input arguments.

  • Your answer really helped me! I´ve tried it and if I specify my input features like this it works: "'X' #; 'Y' #" --- "'C:\test\a.shp' #; 'C:\test\b.shp' #"
    – David
    Feb 21 '18 at 16:28

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.