Select to view content in your preferred language

Export to shapefile in VB.NET

560
2
03-15-2024 04:54 AM
SigurdurGesr
Emerging Contributor

Hi

 

How can I export selected feature in Layer to Shapefile in VB.NET 

 

This is example how it can export in ArcGIS desktop

https://gis.stackexchange.com/questions/121057/arcmap-vb-net-export-map-to-shp-error

 

0 Kudos
2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

You can do it using geoprocessing Feature Class To Shapefile tool.

Geoprocessing API reference is here

0 Kudos
SigurdurGesr
Emerging Contributor

 

I found the solution
is there any expert who can help
need to be able to apply a filter from Layer and determine the file name that will be saved
and know when Geoprocessing has finished processing

 

This is sample from RawMcGee   which I found in the discussion

 

  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}";
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

Thanks

 

 

0 Kudos