sanjayrana

Dissolve Service Area Lines

Discussion created by sanjayrana on Jul 28, 2013
Hi Everyone,

I would like to dissolve the Lines output in the Service Area based on the common FacilityID. I can do this interactively via ArcToolbox but my attempts to do this programmatically via geoprocessing have failed so far. Has anyone got the experience of doing it? I am using the tips from the following page:

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Sample_Executing_geoprocessing_tools/000100000161000000/


Here's my code:

IFeatureClass SALinesFClass = m_naContext.NAClasses.get_ItemByName("SALines") as IFeatureClass;
IFeatureClass SALinesFClassDissolve = DissolveAdvanced(SALinesFClass,"FacilityID","dissolve"+run.ToString()+".shp");

        private IFeatureClass DissolveAdvanced(IFeatureClass pInFClass, string DissolveField, string OutputName)
        {
            
            Dissolve DissolveDS = new Dissolve();  
            ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult Result;                  
            
            try
            {
                DissolveDS.in_features = pInFClass;
                DissolveDS.dissolve_field = DissolveField;
                //DissolveDS.statistics_fields = "#";
                DissolveDS.multi_part = "MULTI_PART";
                DissolveDS.unsplit_lines = "DISSOLVE_LINES";
                DissolveDS.out_feature_class = @"c:\temp\"+OutputName;                
                
                Result = RunTool(DissolveDS, null);
                
                if (Result==null)
                {
                    Debug.WriteLine("Could not dissolve dataset");
                    return null;
                }           
            
                return ReturnFeatureClassfromResult(Result);
            }           
            catch(Exception ex)
            {
                Debug.WriteLine(ex.ToString()+" Dissolve error");
                return null;
            }
        }

        private static ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult RunTool(ESRI.ArcGIS.Geoprocessor.IGPProcess Process, 
             ESRI.ArcGIS.esriSystem.ITrackCancel2 TC) 
        {     
            ESRI.ArcGIS.Geoprocessor.Geoprocessor GP = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();          
            ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult Result = new GeoProcessorResult();
            GP.AddOutputsToMap = false;

            try
            {
                Result = GP.Execute(Process, null) as GeoProcessorResult;

                if (Result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                    Debug.WriteLine("Geoprocessing Error");
                GP.ClearMessages();
                return Result;
            }
            catch (Exception ex)
            {
                if (Result.MessageCount > 0)
                {
                    for (int count = 0; count < Result.MessageCount; count++)
                    {
                        Debug.WriteLine(Result.GetMessage(count));
                    }
                    Debug.WriteLine("Geoprocessing Failed");
                }
                GP.AddOutputsToMap = true;
                return null;
            }
        }           

        private ESRI.ArcGIS.Geodatabase.IFeatureClass ReturnFeatureClassfromResult(ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult result) 
        {            
            ESRI.ArcGIS.Geodatabase.IGPValue GPVal;
            string InMemFC;
            ESRI.ArcGIS.Geoprocessing.IGPUtilities3 GPUtil  = 
                new ESRI.ArcGIS.Geoprocessing.GPUtilities() as ESRI.ArcGIS.Geoprocessing.IGPUtilities3;
            ESRI.ArcGIS.Geodatabase.IFeatureClass pOutputFC;
            
            try
            {
                GPVal = result.GetOutput(0);
                InMemFC = GPVal.GetAsText();
                pOutputFC = GPUtil.OpenFeatureClassFromString(InMemFC);
                return pOutputFC;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Return FeatureClass error "+ex.ToString());
                return null;
            }
        }


The code breaks up at
Result = GP.Execute(Process, null) as GeoProcessorResult;


Thanks a lot.

Outcomes