Sample for calling a GP Service Task with with multiple features??

2089
3
Jump to solution
05-06-2013 08:41 AM
Labels (1)
ThomasIsraelsen
New Contributor III
[Apologies for re-posting, but I wanted to change the title as it was misleading, and the forum wouldn't let me change anything.]

I would like to call a Geoprocessing Service from the WPF SDK, but I am having problems.

The model I published has several inputs - most of the non-spatial table data and those work fine, but in addition it has a feature layer / class, for which I cannot get data into the service.

I was hoping that someone could point me to a sample that does this.

There are plenty of samples, but they all seem to load just one single feature into the service. This is unfortunate, since the API has a specific "shorthand" for this single-feature-case, whereas the more general case is not shown.

I can see that the features are actually being transmitted to the server, since I have found them in JSON form in a file called definitions.dat under the server jobs folder. But I still think I must be doing something wrong since the model that is running on the server "sees" an empty input (as evidenced by my use of the GetCount Tool).

Here is an abbreviated version of my code:
m_gp = new Geoprocessor("http://server:6080/arcgis/rest/services/Name/GPServer/Name");
List<GPParameter> parameters = new List<GPParameter>();
List<Graphic> graphics = new List<Graphic>();
while(notDone)
{
Graphic graphic = new Graphic();
IDictionary<string, object> record = graphic.Attributes;
point = new MapPoint();
point.X = x_value;
point.Y = y_value;
record.Add("field1","value1");
point.SpatialReference = new SpatialReference(25832);
graphic.Geometry = point;
}
graphics.Add(graphic);

GPParameter prm;
FeatureSet fSet = new FeatureSet(graphics);
fSet.SpatialReference = new SpatialReference(25832);
prm = new GPFeatureRecordSetLayer(recordSetName, fSet);
parameters.Add(prm)

// add more parameters

m_gp.SubmitJobAsync(parameters);

Help please! I am completely stuck.
0 Kudos
1 Solution

Accepted Solutions
ThomasIsraelsen
New Contributor III
Figured it out: I got the parameter name slightly wrong (location vs. locations).

View solution in original post

0 Kudos
3 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

I've modified the Buffer sample in the SDK to demonstrate how to submit multiple features:

private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
{
    _gpTask.CancelAsync();
    GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
    graphicsLayer.ClearGraphics();
    e.MapPoint.SpatialReference = MyMap.SpatialReference;
    Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
    {
        Geometry = e.MapPoint,
        Symbol = LayoutRoot.Resources["DefaultClickSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
    };
    graphic.SetZIndex(1);
    graphicsLayer.Graphics.Add(graphic);
            
    // Build paramaters
    List<GPParameter> gpParams = new List<GPParameter>();
    double dist = System.Convert.ToDouble(500);
            
    // Old code from Buffer sample (single graphic approach)
    //var g = new Graphic { Geometry = e.MapPoint };
    //var fs = new FeatureSet(new List<Graphic> { g });

    List<Graphic> graphicsList = new List<Graphic>();
    Random random = new Random();

    for (int i = 0; i < 5; i++)
    {
        var g = new Graphic { Geometry = new MapPoint(random.Next(-20000000, 20000000), random.Next(-20000000, 20000000), MyMap.SpatialReference), };
        graphicsList.Add(g);
    }

    var fs = new FeatureSet(graphicsList);

    gpParams.Add(new GPFeatureRecordSetLayer("InputFeatures", fs));
    gpParams.Add(new GPLinearUnit("Distance", esriUnits.esriKilometers, dist));

    _gpTask.ExecuteCompleted += (s, e1) =>
    {
        GPExecuteResults results = e1.Results;
        GPFeatureRecordSetLayer rs = results.OutParameters[0] as GPFeatureRecordSetLayer;

        List<Graphic> resultGraphics = new List<Graphic>();

        for (int i = 0; i < rs.FeatureSet.Features.Count; i++)
        {
            Graphic graphicBuff = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = rs.FeatureSet.Features.Geometry,
                Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
            };
            resultGraphics.Add(graphicBuff);
        }
        graphicsLayer.Graphics.AddRange(resultGraphics);
               
    };
    _gpTask.Failed += (s2, e2) =>
    {
        MessageBox.Show(e2.Error.Message);
                
    };
    _gpTask.ExecuteAsync(gpParams);
}


Cheers

Mike
0 Kudos
ThomasIsraelsen
New Contributor III
Mike,

Thanks for a quick answer.

As far as I can tell your code is equivalent to what I do. Can you help me figure out why the GP Task I have published cannot "see" the features I load in the client? The task works fine when I call it fra ArcGIS Desktop.

I use the GetCount GP tool at part of the model, and it reports back "Row Count = 0" for the features. On the other hand, the Task aso has som parameters, which are not features, but just table data. They work find and I use largely the same code for loading them.

Any thought? I am quite stuck and do not know how to track this down.
0 Kudos
ThomasIsraelsen
New Contributor III
Figured it out: I got the parameter name slightly wrong (location vs. locations).
0 Kudos