How can I input several files for tools in arcobject?

625
6
Jump to solution
05-11-2012 09:52 AM
InsuHong1
New Contributor
Hi,

How can I input several shp files or feature classes for tools?

for example, if I implement code for 'Intersect' tool to intersect shp files: testA.shp, testB.shp

Intersect Inter = new Intersect(); Inter.in_features = features;  Inter.out_feature_class = 'result.shp';  gp.Execute(Inter, null);


How can I input 'testA.shp' and 'testB.shp' as parameters for 'in_features' ?

I know how input single object: @"C:\data\aaa.shp" . like this. I know.

But I cannot find any document for multiple features. other answers just repeat see reference and sample. I saw them, but I could not figure out because all of samples only showed single parameter!

I tried 'List' of files, 'Array' of files, and just , or ; but all of them failed to compile.
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
Here's an example that ESRI support sent to me on using several inputs for the Intersect tool

ESRI.ArcGIS.Geoprocessor.Geoprocessor GP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); GP.OverwriteOutput = true; IGPUtilities2 gpUtils = new GPUtilitiesClass(); IFeatureClass inFeature1 = gpUtils.OpenFeatureClassFromString(@"E:\Test.gdb\states"); IFeatureClass inFeature2 = gpUtils.OpenFeatureClassFromString(@"E:\Test.gdb\us_rivers"); IGpValueTableObject vt = new GpValueTableObjectClass(); //vt.SetColumns(1); vt.SetColumns(2); object weight; weight = 1 as object; object obj1 = inFeature1; vt.AddRow(ref obj1); vt.SetValue(0, 1, ref weight); object obj2 = inFeature2; vt.AddRow(ref obj2); vt.SetValue(1, 1, ref weight); ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect(); intersect.in_features = vt; intersect.out_feature_class = "E:\testout.shp"; GP.Execute(intersect, null);

View solution in original post

0 Kudos
6 Replies
AlexanderGray
Occasional Contributor III
Not sure why you are using single quotes in C#...  They are for defining a char (char i = 'i';) Passing in a string array should work fine.  If it is not compiling check if you have option strict on.  If you do it is a good thing, it just means you can't pass a string array into a property expecting an object without doing as explicit type conversion.  The following compiles ok on my machine, I haven't run it because I don't have the shapefiles and can't be bothered right now.

      
      Geoprocessor gp = new Geoprocessor();
      Intersect Inter = new Intersect();
      string[] features = {"c:\\shape1.shp", "c:\\shape2.shp"} ; 
      Inter.in_features =  features as object;
      Inter.out_feature_class = "c:\\result.shp"; 
      gp.Execute(Inter, null);
0 Kudos
KenBuja
MVP Esteemed Contributor
Here's an example that ESRI support sent to me on using several inputs for the Intersect tool

ESRI.ArcGIS.Geoprocessor.Geoprocessor GP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); GP.OverwriteOutput = true; IGPUtilities2 gpUtils = new GPUtilitiesClass(); IFeatureClass inFeature1 = gpUtils.OpenFeatureClassFromString(@"E:\Test.gdb\states"); IFeatureClass inFeature2 = gpUtils.OpenFeatureClassFromString(@"E:\Test.gdb\us_rivers"); IGpValueTableObject vt = new GpValueTableObjectClass(); //vt.SetColumns(1); vt.SetColumns(2); object weight; weight = 1 as object; object obj1 = inFeature1; vt.AddRow(ref obj1); vt.SetValue(0, 1, ref weight); object obj2 = inFeature2; vt.AddRow(ref obj2); vt.SetValue(1, 1, ref weight); ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect(); intersect.in_features = vt; intersect.out_feature_class = "E:\testout.shp"; GP.Execute(intersect, null);
0 Kudos
InsuHong1
New Contributor
agray: I don't know why, your code did not work my PC. anyway, thanks.

kenbuja: yours is worked!!!!!  Thank you. I reaally appriciate.
0 Kudos
KenBuja
MVP Esteemed Contributor
Glad to help. Don't forget to mark the question as answered.
0 Kudos
InsuHong1
New Contributor
Strange...

code from kenbuja worked fine with Intersect tool, but it failed with other tools, such as Merge, FeatureToPolygon.


This drives me crazy. I struck this damn problem 2 weeks..

I completed lost.

What's the problem. Somebody please help me.
0 Kudos
KenBuja
MVP Esteemed Contributor
See your other question for the answer
0 Kudos