3

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();
 geoProcessor.setOverwriteOutput(true);
 // 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.setColumns(2);
 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();
 union.setInFeatures(gpvtObject);
 union.setOutFeatureClass("C:\\test\\union.shp");
 geoProcessor.execute(union, null);
 } catch (IOException e) {
 e.printStackTrace();
 }
Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Feb 21, 2018 at 9:20

1 Answer 1

2

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.

answered Feb 21, 2018 at 15:26
1
  • 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' #" Commented Feb 21, 2018 at 16:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.