I am trying to create an empty feature class in a file geodatabase, but it's not working. The geoprocessing tool doesn't provide a specific error message. When I run the tool on a folder, it creates an empty shapefile without any issues. Here is my code:
string path = analysis.Path + "\\CVAnalysis.gdb"; // This doesn't work. The CVAnalysis.gdb exists, and I have no problem creating a feature class when running the geoprocessing tool manually in ArcGIS Pro.
string path = analysis.Path; // This works and output a shapefile.
var parameters = Geoprocessing.MakeValueArray(
path,
"NewLayer",
"Polygon"
);
string toolName = "management.CreateFeatureclass";
var result = await Geoprocessing.ExecuteToolAsync(toolName, parameters, null, null, null);
if (result.IsFailed)
{
foreach (var message in result.Messages)
{
MessageBox.Show(message.Text); // There is no message in the error
}
}
else
{
System.Diagnostics.Debug.WriteLine("Feature class created successfully.");
}
Solved! Go to Solution.
Hi,
Your code works fine. There are some reasons why you can't create featureclass within geodatabase:
1. analysis.Path ends with "\". I would recommend to use Path.Combine method to construct full path.
2. Your geodatabase already contains "NewLayer" featureclass.
I would recommend to use ExecuteToolAsync method with GPToolExecuteEventHandler parameter as in API reference sample. It will show issues with input parameters.
System.Threading.CancellationTokenSource _cts;
string ozone_points = @"C:\data\ca_ozone.gdb\O3_Sep06_3pm";
string[] args = { ozone_points, "OZONE", "", "in_memory\\raster", "300",
"EMPIRICAL", "300", "5", "5000",
"NBRTYPE=StandardCircular RADIUS=310833.272442914 ANGLE=0 NBR_MAX=10 SECTOR_TYPE=ONE_SECTOR",
"PREDICTION", "0.5", "EXCEED", "", "K_BESSEL" };
string tool_path = "ga.EmpiricalBayesianKriging";
_cts = new System.Threading.CancellationTokenSource();
var result = await Geoprocessing.ExecuteToolAsync(tool_path, args, null, _cts.Token,
(event_name, o) => // implement delegate and handle events
{
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;
}
});
var ret = result;
_cts = null;
The problem was invalid featureclass name with number at the beginning and space. With the code sample shared by @GKmieliauskas, I was able to se the error message. Thank you @GKmieliauskas !
Hi,
Your code works fine. There are some reasons why you can't create featureclass within geodatabase:
1. analysis.Path ends with "\". I would recommend to use Path.Combine method to construct full path.
2. Your geodatabase already contains "NewLayer" featureclass.
I would recommend to use ExecuteToolAsync method with GPToolExecuteEventHandler parameter as in API reference sample. It will show issues with input parameters.
System.Threading.CancellationTokenSource _cts;
string ozone_points = @"C:\data\ca_ozone.gdb\O3_Sep06_3pm";
string[] args = { ozone_points, "OZONE", "", "in_memory\\raster", "300",
"EMPIRICAL", "300", "5", "5000",
"NBRTYPE=StandardCircular RADIUS=310833.272442914 ANGLE=0 NBR_MAX=10 SECTOR_TYPE=ONE_SECTOR",
"PREDICTION", "0.5", "EXCEED", "", "K_BESSEL" };
string tool_path = "ga.EmpiricalBayesianKriging";
_cts = new System.Threading.CancellationTokenSource();
var result = await Geoprocessing.ExecuteToolAsync(tool_path, args, null, _cts.Token,
(event_name, o) => // implement delegate and handle events
{
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;
}
});
var ret = result;
_cts = null;
The problem was invalid featureclass name with number at the beginning and space. With the code sample shared by @GKmieliauskas, I was able to se the error message. Thank you @GKmieliauskas !