Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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. Any ideas as to what might cause this? I just don't know what to look for anymore. Thanks!

share|improve this question
    
I did check the box for ArcGIS Runtime. This is a simple test (I was not able to get my original tool to run). I created a simple model using Modelbuilder, that just uses the CopyFeatures tool to make a copy of a polygon. There are no inputs or output parameters. It runs successfully in ArcMap. –  Renee Cammarere Jul 22 '13 at 17:20
add comment

1 Answer

up vote 1 down vote accepted

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");
            }
        });
        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();
    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.