ArcGIS Developer Tip #3: Passing multiple values to the .NET Geoprocessor Class

The ArcGIS ArcObjects .NET Geoprocessing Class provides you with an easy way to execute GP tools in a pure .NET programming environment.  In some cases however, you may want to pass in multiple input values e.g. feature classes, just like you can with the GP tool dialog in ArcCatalog. 

So how can you accomplish this with .NET Geoprocessor class?

Well actually, there are three ways:

1.
Use the parameterized constructor and separate the string parameters with a “;”.

Dim union As ESRI.ArcGIS.AnalysisTools.Union = New ESRI.ArcGIS.AnalysisTools.Union("c:\temp\test.gdb\states;c:\temp\test.gdb\counties", "c:\temp\Union_Output.shp"
GP.Execute(union, Nothing) 

2. Use the object properties and separate parameters with a “;”.

Dim union As ESRI.ArcGIS.AnalysisTools.Union = New ESRI.ArcGIS.AnalysisTools.Union()union.in_features = "C:\temp\test.gdb\states;C:\temp\test.gdb\counties"
union.out_feature_class = "C:\temp\Union_Output.shp"
GP.Execute(union, Nothing) 

3.       Use a GpValueTableObject (probably the least widely known method, but very powerful!)

'Feature Class Objects
Dim gpUtils As IGPUtilities2 = New GPUtilitiesClass()
Dim inFeature1 As IFeatureClass = gpUtils.OpenFeatureClassFromString("C:\temp\test.gdb\states")
Dim inFeature2 As IFeatureClass = gpUtils.OpenFeatureClassFromString("C:\temp\test.gdb\counties")
'Create and populate a Value Table Object
Dim vt As IGpValueTableObject = New GpValueTableObjectClass()       
vt.SetColumns(1)
Dim obj1 As Object = inFeature1
vt.AddRow(obj1)
Dim obj2 As Object = inFeature2
vt.AddRow(obj2)
'Run the Tool
Dim union As ESRI.ArcGIS.AnalysisTools.Union = New ESRI.ArcGIS.AnalysisTools.Union()
union.in_features = vt
union.out_feature_class = "C:\temp\Union_Output.shp"
GP.Execute(union, Nothing)


NOTE: If you want to union more than two feature classes then you will need an ArcInfo-level license.   See these links for more info:    

How to Access Licensing and Extensions for the Geoprocessor
Licensing for Geoprocessing Tools

Learn more about programming with GP in .NET.  

What is Geoprocessing?
Geoprocessing Class
How to access geoprocessing tools and toolboxes
How to run a Geoprocessing tool

EDN Team

With contributions from Ralf Gottschalk, ESRI Technical Support

Published Monday, June 08, 2009 10:30 AM by alaframboise

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

jacobsj said:

The name of the "union" variable is mispelled in the last two GP.Execute statements as "uniom".

June 9, 2009 10:34 AM
 

santoshf2 said:

Hi,

I have been assigned the job of creating a standalone application on ARCOBJECTS using C#.net

What I want to know is, whether I can develop a standalone application on .net without using ArcEngine

I hope its a easy question to be answered by members of ESRI..

Please do.

santhosh@pixelsoftek.com

July 24, 2009 5:54 AM
 

Jim Barry said:

Yes, you can create a standalone application using the ArcGIS ArcObjects API with a .NET development environment, without needing ArcGIS Engine.

However...

a.  You must have a license of ArcGIS Desktop, which is sounds like you do.

b.  When you install ArcGIS Desktop, choose the option to install the ArcGIS Desktop Developer Kit.  That will install the components you can use in Visual Studio.

c.  Not all of the controls included with ArcGIS Engine are included in the ArcGIS Desktop Developer Kit install.  The ones that are included are the Map control and the PageLayout control.  Some controls are not included, like the TOC control and Toolbar control.

d.  Machines on which you will deploy your standalone application must also have a license of ArcGIS Desktop.  (That's an important advantage of ArcGIS Engine, is that apps you create with it can run on machines which do not have any ESRI products on them previously.  They only need a registered copy of the ArcGIS Engine Runtime installed.)

I hope this helps.

July 24, 2009 9:52 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit