GPTool Table Results

4309
16
Jump to solution
05-23-2012 08:01 AM
BrianLeroux
Occasional Contributor III
Hi-
I created a geoprocessing service that outputs a table in the scratch GDB. I am trying to retrieve the results to diplay in a datagrid but I am having issues. I have tried many methods with no luck. Below I try to count the outparameters but it is always 0. Does anyone know how to retruieve the table data?

private void GeoprocessorTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.GPExecuteCompleteEventArgs args)         {             btnPoint.IsEnabled = true;             MessageBox.Show(args.Results.OutParameters.Count().ToString());          }


Thanks!
0 Kudos
16 Replies
BrianLeroux
Occasional Contributor III
Update:
I tied the GetResultDataAsync to the onclick event of a button and specified the jobID of a know job that has results in the server jobs folder. When I click the button nothing happens. I had fiddler running so I could see if a request was being sent. Nothing shows in fiddler. I am not sure why GetResultDataAsync is not firing at all.
Geoprocessor geoprocessorTask = sender as Geoprocessor;
            geoprocessorTask.GetResultDataCompleted += GeoprocessorTask_GetResultDataCompleted;
            geoprocessorTask.Failed += GeoprocessorTask_Failed;
            geoprocessorTask.GetResultDataAsync("j0ecca8fcfee3406ba977cb29b53d09dd", "output");


I put in some exception handling in my code to see what is going wrong. I get an "object reference not set to an instance of an object" in this code.
foreach (GPParameter gpParameter in e.Results.OutParameters)
                {
                    GPFeatureRecordSetLayer gpLayer = gpParameter as GPFeatureRecordSetLayer;

                    foreach (Graphic graphic in gpLayer.FeatureSet.Features)
                    {
                        graphicsLayer.Graphics.Add(graphic);
                    }
                }
0 Kudos
BrianLeroux
Occasional Contributor III
So I am getting my reults back as I can get a correct feature count on the GPParameter. I still can't get my results to show in a datagrid. The code below give me a datagrid with the correct # of items but the data is showing information about the data and not the data itself. Any help is appreciated.
foreach (GPParameter gpParameter in e.Results.OutParameters)
                    if (gpParameter.Name == "output_dbf")
                    {
                        GPRecordSet gpLayer = gpParameter as GPRecordSet;
                        MessageBox.Show(gpLayer.FeatureSet.Count().ToString()); 
                        dg1.ItemsSource = gpLayer.FeatureSet.Features;                       
                    }
       


[ATTACH=CONFIG]16934[/ATTACH]
0 Kudos
BrianLeroux
Occasional Contributor III
I am getting close but can;t quite get it to populate the datagrid. The code below gets me the correct number of features that should be in the datagrid and even adds the correct number of rows to the table. However, the table rows do not contain any data. So close and I feel like it is something very easy that I am missing. Ideas anyone?

XAML
 <sdk:DataGrid AutoGenerateColumns="True" Height="236" HorizontalAlignment="Left" Margin="12,52,0,0" Name="dg1" VerticalAlignment="Top" Width="476">
            <sdk:DataGrid.Columns>
                <!--<sdk:DataGridTextColumn Binding="{Binding Path=OID}" SortMemberPath="OID" Header="OID"/>-->
                <!--<sdk:DataGridTextColumn Binding="{Binding Path=LossDt}" SortMemberPath="LossDt" Header="LossDt"/>-->
                <!--<sdk:DataGridTextColumn Binding="{Binding Path=FREQUENCY}" SortMemberPath="FREQUENCY" Header="FREQUENCY"/>-->
                <sdk:DataGridTextColumn Binding="{Binding MEAN_LossA}" SortMemberPath="MEAN_LossA" Header="MEAN_LossA"/>
                <!--<sdk:DataGridTextColumn Binding="{Binding Path=SUM_LossAm}" SortMemberPath="SUM_LossAm" Header="SUM_LossAm"/>-->
                <!--<sdk:DataGridTextColumn Binding="{Binding Path=MEAN_ExpAm}" SortMemberPath="MEAN_ExpAm" Header="MEAN_ExpAm"/>-->
                <!--<sdk:DataGridTextColumn Binding="{Binding Path=SUM_ExpAmt}" SortMemberPath="SUM_ExpAmt" Header="SUM_ExpAmt"/>-->

            </sdk:DataGrid.Columns>
        </sdk:DataGrid>


XAML CS
 public interface HailData {} 
        public class HailAttributes : HailData
        {
            //public double OID;
            //public string LossDt;
           // public double FREQUENCY;
            public string MEAN_LossA;
            //public double SUM_LossAm;
            //public double MEAN_ExpAm;
            //public double SUM_ExpAmt;
        }

        public string MEAN_LossA
        {
            get { return MEAN_LossA; }
        }


        private void GeoprocessorTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.GPExecuteCompleteEventArgs e)
        {
            try
            {
                this.dg1.ItemsSource = null;
                
                foreach (GPParameter gpParameter in e.Results.OutParameters)
                    if (gpParameter.Name == "output_dbf")
                    {
                        GPRecordSet gpLayer = gpParameter as GPRecordSet;

                        List<HailData> theList = new List<HailData>();

                        foreach (Graphic feature in gpLayer.FeatureSet.Features)
                        {
                            //MessageBox.Show(feature.Attributes["MEAN_LossA"].ToString());
                            theList.Add(new HailAttributes()
                            {
                                //OID = Convert.ToDouble(feature.Attributes["OID"]),
                                //LossDt = feature.Attributes["LossDt"].ToString(),
                                //FREQUENCY = Convert.ToDouble(feature.Attributes["FREQUENCY"]),
                                MEAN_LossA = feature.Attributes["MEAN_LossA"].ToString(),
                                //SUM_LossAm = Convert.ToDouble(feature.Attributes["SUM_LossAm"]),
                                //MEAN_ExpAm = Convert.ToDouble(feature.Attributes["MEAN_ExpAm"]),
                                //SUM_ExpAmt = Convert.ToDouble(feature.Attributes["SUM_ExpAmt"]),
                            });
                            
                        }
                        MessageBox.Show(theList.Count().ToString());                       
                        this.dg1.ItemsSource = theList;
                       
                    }
                                                
                btnPoint.IsEnabled = true; 
            }
            catch (OverflowException oEx)
            {
                MessageBox.Show(oEx.Message);
                btnPoint.IsEnabled = true; 
            }
            catch (FormatException fEx)
            {
                MessageBox.Show(fEx.Message);
                btnPoint.IsEnabled = true; 
            }
            catch (Exception ex)
            {
                
                MessageBox.Show(ex.Message + " stacktrace:" + ex.StackTrace);
                btnPoint.IsEnabled = true; 
            }
           

        }
0 Kudos
DominiqueBroux
Esri Frequent Contributor
If you come back to your ItemSources set to the Features:

dg1.ItemsSource = gpLayer.FeatureSet.Features;


you should be able to bind your columns by using the Attributes dictionary:

<sdk:DataGridTextColumn Binding="{Binding Path=Attributes[OID]}" Header="OID"/>
0 Kudos
BrianLeroux
Occasional Contributor III
Thanks dbroux, that did the trick.
0 Kudos
GaryBushek
New Contributor III
Jennifer,
    Based on something Brian said above. He changed his task to asynchronous so he could see results.  I'm using synchronous and don't see results.  I'd rather not switch to asynchronous if I can avoid it.  Is there some reason the published model wouldn't return the results as a GPRecordSet?  Is this something to do with how I defined the final output in the model?  I have
%scratchGDB%\Site_Results.  Running the model on the server works fine but like I said, when I publish it and run from a client I don't get results.  Im not that familiar with how to set up output for synchronous tasks.  asynchronous is kind of obvious with the job folder specific to the task that has to be referenced by job id to retrieve status and results.

Thanks, Gary
0 Kudos
JenniferNery
Esri Regular Contributor
0 Kudos