Geopreocessing tool execution error. C# SDKPro

1453
6
12-03-2018 06:47 AM
JaewonYang
New Contributor III

Hello,

I am trying to add and XY event layer through a data table generated from a datagridview in Winform. But when trying to make a string of data table object C# RuntimeBinderException occurs, that string converter has some invalid arguments. the code is mention below;

var st = Geoprocessing.MakeValueString(dT);

When I changed this to string expression,

string st = dT.ToString();

the code throws no exception but tool doesn't execute at all. code for tool execution is also mentioned below.

string st = dT.ToString();

var args = Geoprocessing.MakeValueArray(st, "Long", "Lat", "Settlement_m", "", "Settlement");

string tool_path = "MakeXYEventLayer_management";

System.Threading.CancellationTokenSource cts = new System.Threading.CancellationTokenSource();

var result = Geoprocessing.ExecuteToolAsync(tool_path, args, null, cts.Token, (event_name, o) => // implement delegate and handle events, o is message object

{

switch (event_name)

{

case "OnValidate": // stop execute if any warnings

if ((o as IGPMessage[]).Any(it => it.Type == GPMessageType.Warning))

cts.Cancel();

break;

case "OnProgressMessage":

string msg = string.Format("{0}: {1}", new object[] { event_name, (string)o });

System.Windows.MessageBox.Show(msg);

cts.Cancel();

break;

case "OnProgressPos":

string msg2 = string.Format("{0}: {1} %", new object[] { event_name, (int)o });

System.Windows.MessageBox.Show(msg2);

cts.Cancel();

break;

}

}, GPExecuteToolFlags.AddOutputsToMap|GPExecuteToolFlags.RefreshProjectItems);

var ret = await result;

cts = null;

I cannot give a file path for the XY Table because I am calculating Z-layer in runtime and adding it to the table before making the string of DataTable object. Any help would be appreciated.

0 Kudos
6 Replies
ThadTilton
Esri Contributor

Hi!

This is the space for ArcGIS Runtime SDK, it sounds like your question belongs in the ArcGIS Pro SDK space: https://community.esri.com/groups/arcgis-pro-sdk 

GKmieliauskas
Esri Regular Contributor

Hi Jaewon,

Serialize your datatable to csv file and use it as parameter for geoprocessing

JaewonYang
New Contributor III

Gintautas ,

Hello, Thanks for your suggestion. I serialized my data table as per your suggestion but still The tool is not executing. I have tried multiple options, also, gave a database path to physical file but to no avail. May be there is some error in GPTool code if you can spot it out?

I am getting the following error though.

((ArcGIS.Desktop.Core.Geoprocessing.IGPResult)result).ErrorMessages ={System.Linq.Enumerable.WhereListIterator<ArcGIS.Desktop.Core.Geoprocessing.IGPMessage>}

and the serialization code is as follows;

List<string> mydT = new List<string>().ToList();

foreach (DataRow dr in dT.Rows)

{

mydT.Add(Convert.ToString(dr["Lat"]));

mydT.Add(Convert.ToString(dr["Long"]));

mydT.Add(Convert.ToString(dr["Settlement"]));

}

string st_in = string.Join(",", mydT);

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

Have you tried to use your created csv file from ArcGIS Pro toolkit? If it works from ArcGIS Pro toolkit, when problems in your parameters list formatting. Else - problems in your csv file.

0 Kudos
JaewonYang
New Contributor III

Yes, I already checked out my csv file. It worked in the toolkit.

I somehow changed the code and it is working.

try

{

string st_in = @"C:\Users\Aizaz\Documents\ArcGIS\Projects\MyProject\new.csv";

string st_out = @"C:\Users\Aizaz\Documents\ArcGIS\Projects\MyProject";

//var envArray = Geoprocessing.MakeEnvironmentArray(null);

var args = Geoprocessing.MakeValueArray(st_in, "Lat", "Long", st_out, "", "Settlement");

string tool_path = "MakeXYEventLayer_management";

IGPResult ret = await Geoprocessing.ExecuteToolAsync(tool_path, args);

if (ret.IsFailed)

{

ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show($@"Error {ret.ErrorCode} in GP Tool: {ret.ErrorMessages}");

}

// var rset = Geoprocessing.ExecuteToolAsync(tool_path, args, null, null, GPExecuteToolFlags.Default);

}

catch (Exception)

{ }

Can you give your comments about this, why the error was happening in the previous code?

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

In previuous code st_in variable is used for file content, in last code - for file path. You need to save file content to file and use it for geoprocessing