Using Geoprocessing API to convert Feature Class to Shapefile

1444
2
Jump to solution
10-28-2019 07:40 AM
RawMcGee
New Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

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.

SymbolLookup sample 

Thanks

Uma

View solution in original post

2 Replies
RawMcGee
New Contributor

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. 

0 Kudos
UmaHarano
Esri Regular Contributor

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.

SymbolLookup sample 

Thanks

Uma