I'm trying to use the "CreateXYEventLayer" tool to create a point event layer from a .csv file. It works when I use the tool from within the project, but when I try to do it via the SDK (with the same .csv file), it fails. Is something wrong with my parameters or the way that I am executing the tool? P.S. I'm very new to the ArcGIS SDK. Thanks in advance! Here is the code:
public async Task CreatePointEventLayerFromCsv(string csvPath)
{
var parameters = Geoprocessing.MakeValueArray(
csvPath,
"X",
"Y",
"NewEventLayer",
SpatialReferenceBuilder.CreateSpatialReference(4326)
);
var result = await QueuedTask.Run(() =>
{
return Geoprocessing.ExecuteToolAsync("CreateXYEventLayer_management", parameters);
});
if (result.IsFailed)
{
MessageBox.Show("Failed to create point event layer from CSV");
}
else
{
MessageBox.Show("Success");
}
}
Hello @LandonPrince , please can you describe a bit more about what happens when it "fails". Perhaps post some screenshots or other details.
Make sure your CSV is:
Accessible from ArcGIS Pro (e.g., absolute path).
Compliant with ArcGIS standards (e.g., no mixed datatypes in fields).
Ideally added to the map or project — sometimes tools resolve better when it’s registered.
public async Task CreatePointEventLayerFromCsv(string csvPath)
{
// Ensure the path is valid and the CSV is accessible
if (!File.Exists(csvPath))
{
MessageBox.Show("CSV file not found.");
return;
}
var parameters = Geoprocessing.MakeValueArray(
csvPath, // Input Table
"X", // X Field
"Y", // Y Field
"xy_layer", // Layer Name (not a path)
SpatialReferenceBuilder.CreateSpatialReference(4326) // WGS84
);
// Run tool
var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);
var result = await Geoprocessing.ExecuteToolAsync(
"CreateXYEventLayer_management",
parameters,
environments,
null,
null,
GPExecuteToolFlags.Default
);
if (result.IsFailed)
{
MessageBox.Show("Failed to create point event layer from CSV:\n" + result.ErrorMessages);
}
else
{
MessageBox.Show("Success");
}
}