1

I have C# code to run a geoprocessing package that produces an output which is stored in a GPFeatureRecordSetLayer. Right now I have code that displays the result on the GUI when the job is complete . . .

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_Areas");
 }

 private void _localGPService_GetResultDataCompleted(object sender, GPParameterEventArgs e)
 {

 ESRI.ArcGIS.Client.Tasks.GPFeatureRecordSetLayer gpLayer = e.Parameter as ESRI.ArcGIS.Client.Tasks.GPFeatureRecordSetLayer;
 foreach (Graphic graphic in gpLayer.FeatureSet.Features)
 {
 // Code to add graphic to map
 graphic.Symbol = this.Resources["InputPolygonSymbol"] as ESRI.ArcGIS.Client.Symbols.SimpleFillSymbol;
 graphic.Geometry.SpatialReference = _graphicsLayer.SpatialReference;
 _graphicsLayer.Graphics.Add(graphic);
 _map.ZoomTo(graphic.Geometry);
 }
 }

What I need to do is to iterate through each graphic and convert the graphic features to an ArcObjects IFeatureClass that I can write to a file geodatabase. In other words, I want to convert a Runtime object to an ArcObject.

1

I ended up using the ArcGISLocalFeatureLayer object to accomplish what I was trying to do, which was to write the resulting feature class that was created from running the gpk to a geodatabase location of my choosing. I had to grab the GPFeatureRecordSetLayer when the gpk was completed, and use that result to populate the feature class using the Local Feature Layer service. Here is my code . . .

// Initialize objects for manipulating result of running gpk
ArcGISLocalFeatureLayer arcGISLocalFeatureLayer;
public ESRI.ArcGIS.Client.Tasks.GPFeatureRecordSetLayer _gpFeatureRecordSetLayer;

public void StartGeoprocessing()
{
    // start the geoprocessing package
    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_Result");//the name of the output in the model
}

private void _localGPService_GetResultDataCompleted(object sender, GPParameterEventArgs e)
{
    _gpFeatureRecordSetLayer = e.Parameter as ESRI.ArcGIS.Client.Tasks.GPFeatureRecordSetLayer;

    EditMyFeatureLayer();
}

private void EditMyFeatureLayer()
{
    // Get the Local Feature Layer service that is used for editing the Result feature class
    string mpkPath_features = ConfigurationManager.AppSettings["EsriRuntimeEditMapPackageLocation"];

    LocalFeatureService localFeatureService = LocalFeatureService.GetService(mpkPath_features);

    arcGISLocalFeatureLayer = new ArcGISLocalFeatureLayer();
    arcGISLocalFeatureLayer.Service = localFeatureService;
    arcGISLocalFeatureLayer.Editable = true;
    arcGISLocalFeatureLayer.ValidateEdits = true;
    arcGISLocalFeatureLayer.LayerId = 0;
    arcGISLocalFeatureLayer.ID = "Result";
    arcGISLocalFeatureLayer.Path = mpkPath_features;
    arcGISLocalFeatureLayer.DisableClientCaching = true;
    arcGISLocalFeatureLayer.AutoSave = true;
    arcGISLocalFeatureLayer.Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.Snapshot;
    arcGISLocalFeatureLayer.ShowLegend = true;

    GraphicCollection aGCollection = arcGISLocalFeatureLayer.Graphics;

    arcGISLocalFeatureLayer.Initialized += (sender, eventArgs) =>
    {
        arcGISLocalFeatureLayer.Update();
    };

    arcGISLocalFeatureLayer.UpdateCompleted += (sender, e) =>
    {
        foreach (Graphic aGraphic in _gpFeatureRecordSetLayer.FeatureSet.Features)
        {
            aGCollection.Add(aGraphic);
            _map.ZoomTo(aGraphic.Geometry);
        }
        arcGISLocalFeatureLayer.Graphics = aGCollection;
        arcGISLocalFeatureLayer.SaveEdits();
        _map.Layers.Insert(1, arcGISLocalFeatureLayer);

    };

    arcGISLocalFeatureLayer.Initialize();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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