Select to view content in your preferred language

Geoprocessor object won't execute

3451
11
07-15-2013 10:50 AM
ReneeCammarere
Deactivated User
I've tried several different approaches to getting the simple geoprocessing package that I created to execute from my C# project . . .

        ESRI.ArcGIS.Client.Tasks.Geoprocessor _localGPService = null;
        string gpkPath = ConfigurationManager.AppSettings["EsriRuntimeGeoPackageLocation"];
        string geoObjectPath = ConfigurationManager.AppSettings["EsriRuntimeGeoProcessorObject"];
    LocalGeoprocessingService.GetServiceAsync(gpkPath, GPServiceType.Execute, (gpService) =>
    {
        if (gpService.Error != null)
        {
         MessageBox.Show(gpService.Error.Message);
        }
        _localGPService = new ESRI.ArcGIS.Client.Tasks.Geoprocessor(gpService.UrlGeoprocessingService + geoObjectPath);
        DataContext = this;
    });
    List<ESRI.ArcGIS.Client.Tasks.GPParameter> parameters = new List<ESRI.ArcGIS.Client.Tasks.GPParameter>();
    _localGPService.ExecuteAsync(parameters);

I've also tried the following . . .

private LocalGeoprocessingService _localGPService = null;
    string gpkPath = ConfigurationManager.AppSettings["EsriRuntimeGeoPackageLocation"];
    _localGPService = new LocalGeoprocessingService(gpkPath, GPServiceType.Execute);

    _localGPService.StartAsync((callback) =>
    {
        if (callback.Error == null)
        {
            CoverButton.IsEnabled = true;
        }
        else
        {
            MessageBox.Show("Error starting gp service");
        }
    });
    string geoObjectPath = ConfigurationManager.AppSettings["EsriRuntimeGeoProcessorObject"];
    ESRI.ArcGIS.Client.Tasks.Geoprocessor gp = new ESRI.ArcGIS.Client.Tasks.Geoprocessor(_localGPService.UrlGeoprocessingService + geoObjectPath);
   List<ESRI.ArcGIS.Client.Tasks.GPParameter> parameters = new List<ESRI.ArcGIS.Client.Tasks.GPParameter>();
   gp.ExecuteAsync(parameters);

When it gets to the last line (execute), I don't get an error, but it also doesn't do anything. I've been tracing through the code, and the geoprocessor object does get created and invoked with a URL, so I don't know why it does nothing. Tracing through, it appears as if everything is OK. The tool that the gpk was created from runs OK when I execute it in ArcMap.  There are no input or output parameters in the model (tool).  
Any ideas as to what might cause this? I just don't know what to look for anymore. Thanks!
0 Kudos
11 Replies
ReneeCammarere
Deactivated User
@sachin The location of the input object is "C:\Projects\Geospatial-Developmental\TestNoGUI\TestNoGUI\Scratch.gdb\TestPolygon".  The output object is at "C:\Projects\Geospatial-Developmental\TestNoGUI\TestNoGUI\Scratch.gdb\TestPolygonCopy".  I honestly don't know where that temp location is coming from.  However, everything in the "Temp" location ("C:\\Users\\Renee Cammarere\\AppData\\Local\\Temp\\arcgisruntime_5528\\simplecopyfeatures2\\jobs) disappears after the process is supposedly complete.  The output is not created in either of the locations where it should be put -  ( 1)output path defined in the model and 2)output path to location where the gpk is unpacked).
0 Kudos
ReneeCammarere
Deactivated User
As it turned out, the gpk was executing and producing a result, but the result was just not being written out to file geodatabase indicated in the model. I was able to solve this problem by manipulating the object ESRI.ArcGIS.Client.Tasks.GPFeatureRecordSetLayer once the gpk was finished executing. Here is the code . . .

   public ESRI.ArcGIS.Client.Tasks.GPFeatureRecordSetLayer _gpFeatureRecordSetLayer;
                     .
                     .
                     .
        // Check for existence of local geoprocessing package name and start local gpk

        string gpkPath = ConfigurationManager.AppSettings["EsriRuntimeGeoPackageLocation"];
        string geoObjectPath = ConfigurationManager.AppSettings["EsriRuntimeGeoProcessorObject"];
        _localGPService = new LocalGeoprocessingService(gpkPath, GPServiceType.SubmitJob);
        _localGPService.StartAsync((callback) =>
        {
            if (callback.Error == null)
            {
                CoverButton.IsEnabled = true;
            }
            else
            {
                MessageBox.Show("Error starting service");
            }
        });

        public void ExecuteMethod()
        {
             string geoObjectPath = ConfigurationManager.AppSettings["EsriRuntimeGeoProcessorObject"];
             ESRI.ArcGIS.Client.Tasks.Geoprocessor gp = new ESRI.ArcGIS.Client.Tasks.Geoprocessor(_localGPService.UrlGeoprocessingService + geoObjectPath);
             gp.OutputSpatialReference = new SpatialReference(4326);
             List<ESRI.ArcGIS.Client.Tasks.GPParameter> parameters = new List<ESRI.ArcGIS.Client.Tasks.GPParameter>();
             SubmitJobAsyncMethod(gp, parameters);
        }

     private void SubmitJobAsyncMethod(ESRI.ArcGIS.Client.Tasks.Geoprocessor gp, List<ESRI.ArcGIS.Client.Tasks.GPParameter> parameters)
     {
            gp.JobCompleted += _localGPService_JobCompleted;
            gp.SubmitJobAsync(parameters);
     }

    private void _localGPService_JobCompleted(object sender, JobInfoEventArgs e)
     {
            ESRI.ArcGIS.Client.Tasks.Geoprocessor geoprocessorTask = sender as ESRI.ArcGIS.Client.Tasks.Geoprocessor;
            geoprocessorTask.GetResultDataCompleted += _localGPService_GetResultDataCompleted;
            geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "Output_Cover_Areas");
        }

        private void _localGPService_GetResultDataCompleted(object sender, GPParameterEventArgs e)
        {
            _gpFeatureRecordSetLayer = e.Parameter as ESRI.ArcGIS.Client.Tasks.GPFeatureRecordSetLayer;
                foreach (Graphic aGraphic in _gpFeatureRecordSetLayer.FeatureSet.Features)
                {
                    DisplayGraphicOnMap(aGraphic);
                }                     
        }

        public void DisplayGraphicOnMap(Graphic graphic)
        {
            //Add input graphic to the map
            graphic.Symbol = this.Resources["InputPolygonSymbol"] as ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol;
            _graphicsLayer.Graphics.Add(graphic);
            _map.ZoomTo(graphic.Geometry);
            _graphicsLayer.Refresh();
        }
0 Kudos