Sample for calling a GP Service Task with a feature layer with multiple features

4068
8
Jump to solution
05-01-2013 01:51 PM
ThomasIsraelsen
New Contributor III
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 there is 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, and so 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);
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
8 Replies
MatthewBrown1
Occasional Contributor
Hi Thomas,

I have set up my GP params using a foreach to add each graphic:

GPFeatureRecordSetLayer gpFeatures = new GPFeatureRecordSetLayer("input features");
foreach (var g in _localFeatureLayer.Graphics)
    {
            gpFeatures.FeatureSet.Features.Add(g);
    }


so I can check the geometry going in for each graphics during debugging.

But I wonder what inputs you have set for your model (e.g. feature class/layer/set). Could you post your input parameter info from the REST endpoint? I recall having a similar problem and the inputs were GPString instead of GPFeatureRecordSetLayer (due to the way I set up the model in ArcGIS Desktop).

The other thing I often do when debugging GP services is to use CopyFeatures in the model to write out my inputs to the scratch.gdb and use ArcGIS Desktop to check them.
0 Kudos
ThomasIsraelsen
New Contributor III
See REST info below. I'll try the CopyFeatures trick to see if I can get a look at them that way. Don't have much hope though, since GetCount reports "0 records".

Thomas


Task: Buf3
Display Name: Buf3

Description: (null)

Category:

Help URL: http://server:6080/arcgis/rest/directories/arcgisoutput/Buf3_GPServer/Buf3/Buf3.htm

Execution Type: esriExecutionTypeAsynchronous

Parameters:

Parameter: locations

Data Type: GPFeatureRecordSetLayer
Display Name locations
Description: l
Direction: esriGPParameterDirectionInput
Default Value:
Geometry Type: esriGeometryPoint
HasZ: false
HasM: false
Spatial Reference: 25832  (25832)

Fields:
OBJECTID ( type: esriFieldTypeOID , alias: OBJECTID )
ID ( type: esriFieldTypeInteger , alias: ID )
Description ( type: esriFieldTypeString , alias: Description , length: 255 )
Features: None.



Parameter Type: esriGPParameterTypeRequired
Category:

//////////////
3 more input parameters which work fine
//////////////


Parameter: locations_Buffer1

Data Type: GPFeatureRecordSetLayer
Display Name locations_Buffer1
Description: lb
Direction: esriGPParameterDirectionOutput
Default Value:
Geometry Type: esriGeometryPolygon
HasZ: false
HasM: false
Spatial Reference: 25832  (25832)

Fields:
OBJECTID ( type: esriFieldTypeOID , alias: OBJECTID )
ID ( type: esriFieldTypeInteger , alias: ID )
Description ( type: esriFieldTypeString , alias: Description , length: 255 )
BUFF_DIST ( type: esriFieldTypeDouble , alias: BUFF_DIST )
Shape_Length ( type: esriFieldTypeDouble , alias: Shape_Length )
Shape_Area ( type: esriFieldTypeDouble , alias: Shape_Area )
Features: None.



Parameter Type: esriGPParameterTypeRequired
Category:





Supported Operations:   Submit Job
0 Kudos
ThomasIsraelsen
New Contributor III
Hmm. Looking at it now, isn't it suspicious that it says "Features: None." for the input parameter in the fields list?

I don't know why it would say that. The input parameter in the model I published has the data type "Feature Class".

This is what I get back from the service's StatusUpdated event (running with 'informative' messaging):

Submitted.
Executing...
Executing (Buf3): Buf3 "Feature Set" "Record Set" "Record Set" "Record Set" c:\arcgisserver\directories\arcgisjobs\buf3_gpserver\jef2879d669e649a6b6be2b1e65e5f2e3\scratch\scratch.gdb\locations_Buffer1
Start Time: Wed May 08 17:06:52 2013
Executing (Buf3): Buf3 "Feature Set" "Record Set" "Record Set" "Record Set" c:\arcgisserver\directories\arcgisjobs\buf3_gpserver\jef2879d669e649a6b6be2b1e65e5f2e3\scratch\scratch.gdb\locations_Buffer1
Start Time: Wed May 08 17:06:52 2013
Executing (Get Count): GetCount "Feature Set"
Start Time: Wed May 08 17:06:52 2013
Row Count = 0
Succeeded at Wed May 08 17:06:52 2013 (Elapsed Time: 0,00 seconds)
Executing (Buffer): Buffer "Feature Set" c:\arcgisserver\directories\arcgisjobs\buf3_gpserver\jef2879d669e649a6b6be2b1e65e5f2e3\scratch\scratch.gdb\locations_Buffer1 "400 Meters" FULL ROUND NONE #
Start Time: Wed May 08 17:06:52 2013
The process did not execute because the precondition is false.
Succeeded at Wed May 08 17:06:52 2013 (Elapsed Time: 0,00 seconds)
Succeeded at Wed May 08 17:06:52 2013 (Elapsed Time: 0,27 seconds)
Succeeded at Wed May 08 17:06:52 2013 (Elapsed Time: 0,27 seconds)
Invalid return value: c:\arcgisserver\directories\arcgisjobs\buf3_gpserver\jef2879d669e649a6b6be2b1e65e5f2e3\scratch\scratch.gdb\locations_Buffer1
Failed.


The preconditions is just to have GetCount execute first. Returning 0 causes the "false" value and skipping buffer entirely.
0 Kudos
MatthewBrown1
Occasional Contributor
Hi Thomas,

Can you confirm that the tool parameter in ArcGIS Desktop is feature class? This has caused me some problems with GP services and packages. I use Feature Set as the input for the tool in ArcGIS Desktop, especially when using in-memory data such as graphic layers,

The other thing to check is that the input coordinates you are using are valid for the coordinate system that you use, although I expect you would get an out of bounds error or something similar. (Although I recently found and instance where the error I would get in ArcGIS Desktop didn't appear in the Runtime and the operation failed but returned no error.)

Good luck,

Matt
0 Kudos
ThomasIsraelsen
New Contributor III
Matt: Thanks for helping out.

Yes. It's a Feature Class.

I'll try Feature Set, but it is my understanding, that the requirement to use the special data types designed for publication on Server is no longer there in 10.1. The publication wizard should transform the data types for us.

See this

Quoting:

Differences between 10.0 and 10.1

If you authored geoprocessing services in 10.0, there were specific ModelBuilder techniques you used to author services, noted below. You no longer need to use these techniques in 10.1.

Legacy:

Prior to 10.1, geoprocessing tasks were required to have Feature Set data types to input features in geoprocessing tasks, and Record Sets to input tables. You do not need to use feature sets or record sets for services at 10.1; you need only specify an Input mode of User defined value for an input feature or table parameter when editing the task in the Service Editor. If your model (or script) currently uses a Feature Set or Record Set, you don't have to change it; it will publish as is.


Thomas
0 Kudos
ThomasIsraelsen
New Contributor III
Using FeatureSet in the model doesn't make any difference. The REST service looks exactly the same and the application behaves the same.
0 Kudos
ThomasIsraelsen
New Contributor III
My problem is definitely in the client code and not in the service.

i found an Esri sample GP service using ArcGIS Server 10.1, and its REST definition for input features looks excactly like mine.  It is here:

http://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/GPServer/Generat...

And if I adapt my code slightly to call this service rather than my own, I get an equivalent error:

StatusUpdated: esriJobFailed
Submitted.
Executing...
ERROR 030117: Insufficient input. Need at least one facility and one break value.
Failed to execute (Generate Service Areas).
Failed to execute (GenerateServiceAreas).
Failed to execute (Generate Service Areas).
Failed.

So it probably did not get any facilities, which were the features.

I will try once more to compare what I do to the code posted by Mike in the other thread:
http://forums.arcgis.com/threads/83867-Sample-for-calling-a-GP-Service-Task-with-with-multiple-featu...
0 Kudos
ThomasIsraelsen
New Contributor III
Figured it out: I got the parameter name slightly wrong (location vs. locations).
0 Kudos