How do I convert a GPFeatureRecordSetLayer Feature Set to a Feature Class?

4461
4
Jump to solution
08-06-2013 04:52 PM
Labels (1)
ReneeCammarere
Occasional Contributor
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.
0 Kudos
1 Solution

Accepted Solutions
ReneeCammarere
Occasional Contributor
I did end 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;

            // 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();           

        }

View solution in original post

0 Kudos
4 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

The ArcObjects API is not available in the ArcGIS Runtime SDK for WPF. Therefore, you wouldn't use the IFeatureclass approach to write to a File Geodatabase.

We're currently working on an improved API for direct access to a geodatabase on disk (look out for the beta soon) but in the interim you have several options:

#1. Start a LocalFeatureService from a Map Package and edit a feature class within that local service (either included in the package or referenced from the package).
#2. Use a Python script with a cursor to insert features (e.g. http://resources.arcgis.com/en/help/main/10.1/index.html#//018z0000009r000000).
#3. Use the File Geodatabase API (I'd encourage you to stay within the same API, but I mention the File GDB API for completeness).


For more info on what we'll be releasing in the beta see: http://blogs.esri.com/esri/arcgis/2013/07/05/the-history-and-future-of-the-arcgis-sdks-for-net/.

Cheers

Mike
0 Kudos
ReneeCammarere
Occasional Contributor
Option #1 is something that I may have tried before.  I'll give that a shot and let you know how it goes.  Thanks!
0 Kudos
ReneeCammarere
Occasional Contributor
@mbranscomb I've included these lines of code in an attempt to start a local feature service . . .
           string mpkPath_features = ConfigurationManager.AppSettings["EsriRuntimeMapPackageLocation"];
            LocalFeatureService localFeatureService = LocalFeatureService.GetService(mpkPath_features);
            //CoverAreasResult Feature
            arcGISLocalFeatureLayer = new ArcGISLocalFeatureLayer();
            arcGISLocalFeatureLayer.Service = localFeatureService;
            arcGISLocalFeatureLayer.Editable = true;
            arcGISLocalFeatureLayer.LayerId = 0;
            arcGISLocalFeatureLayer.ID = "CoverAreasResult";
            arcGISLocalFeatureLayer.Path = mpkPath_features;
            arcGISLocalFeatureLayer.DisableClientCaching = true;
            arcGISLocalFeatureLayer.AutoSave = false;
            arcGISLocalFeatureLayer.Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.OnDemand;
            arcGISLocalFeatureLayer.OutFields = new OutFields() { "*" };
            _map.Layers.Insert(1, arcGISLocalFeatureLayer);

When I used this before, it was with the Editor Widget.  I'm not wanting to modify the existing feature class in a type of "draw" mode, I need to replace the existing feature class with the result in the GPFeatureRecordSetLayer.  I don't think that I can use this for that, can I?  Thanks.
0 Kudos
ReneeCammarere
Occasional Contributor
I did end 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;

            // 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();           

        }
0 Kudos