Can anyone explain to me how I can use the Geoprocessing API to export a feature class in the currently open map as a shapefile feature class? For one the Geoprocessing calls require a tool name, which is just a string, and I'm not sure where I'd find this information.
I'd also like to know what functions I should call to get symbology definitions for said feature class.
Basically in my add-in I want to the user to be able to select a layer in the current map via some tree view (which I already have working), and then they can click Export which will export said layer as a shapefile with associated symbology. I had this working with ArcObjects but I'm not sure how it is done with ArcGIS Pro.
Solved! Go to Solution.
Hi,
Here is a sample that shows you how you get the JSON representation of a Symbol. You can also get thte XML representation of the symbol by using the CIMSymbol.ToXML method instead.
Thanks
Uma
To answer my own question, this is the easiest way to convert a layer to a shapefile.
protected async Task<string> ConvertShp(string layerpath, string outpath)
{
if (!System.IO.Directory.Exists(outpath))
System.IO.Directory.CreateDirectory(outpath);
var valueArray = await QueuedTask.Run(() =>
{
//input layers list should contain the path of each layer name, i.e. if the root node is "Mapping" and the layer name is "gs_points", path is "Mapping\\gs_points".
List<string> inlayers = new List<string>();
inlayers.Add(layerpath);
//outpath is just the folder to save the shapefiles in
return Geoprocessing.MakeValueArray(inlayers, outpath);
});
// to let the GP tool run asynchronously without blocking the main thread
// use the GPThread option of GPExecuteToolFlasgs
//
GPExecuteToolFlags flags = GPExecuteToolFlags.GPThread; // instruct the tool run non-blocking GPThread
IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("FeatureClassToShapefile_conversion", valueArray, null, null, null, flags);
return string.IsNullOrEmpty(gpResult.ReturnValue)
? $@"Error in gp tool: {gpResult.ErrorMessages}"
: $@"Ok: {gpResult.ReturnValue}";
}
I am still trying to figure out how to export symbology though. Meaning I need some way to enumerate through the symbol definitions for a specified feature layer. So that I can write it out in the format I need (XML).
It basically looks like Geoprocessing is a wrapper for ArcPy stuff? I'm not sure how I'd do more granular modifications to the data when exporting. If I wanted to change a column name or something, seems like there is no easy way to do it.
Hi,
Here is a sample that shows you how you get the JSON representation of a Symbol. You can also get thte XML representation of the symbol by using the CIMSymbol.ToXML method instead.
Thanks
Uma