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();
}
1 Answer 1
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– David2018年02月21日 16:28:32 +00:00Commented Feb 21, 2018 at 16:28