Select to view content in your preferred language

Local Geoprocessing without packages

7469
47
Jump to solution
11-09-2012 11:26 AM
Labels (1)
GeorgeFaraj
Frequent Contributor
I'm opening feature layers from map packages and now I need to run tools such as Union, Buffer, Intersect, etc. dynamically on those layers, then add the results as a new layer in the map. What is the best way to do this locally without using pre-modeled packages?
47 Replies
KevinHibma
Esri Regular Contributor
I don't have the Runtime explanation, but I can explain it from the GP Service perspective.
With a GP Service you can override the schema by passing in a description (fields tag below) of the fields the output will have...
The following JSON example shows that ID and NAME field have been defined, and then you see those fields attached to the geometry.
{ 
"geometryType" : "esriGeometryPoint",
"spatialReference" : {"wkid" : 4326},
"fields":[
{"name":"Id","type":"esriFieldTypeOID","alias":"Id"},
{"name":"Name","type":"esriFieldTypeString","alias":"Name"}
],
"features"  : [
{
    "geometry" : {"x" : -104.44, "y" : 34.83},
    "attributes" : {"Id" : 43, "Name" : "Feature 1"}
},
{
    "geometry" : {"x" : -100.65, "y" : 33.69},
    "attributes" : {"Id" : 67, "Name" : "Feature 2"}
}
]
}


So to answer your question, you will probably need to define the schema when you pass in the features. I'm not entirely sure how to do that in the Runtime without testing.
0 Kudos
GeorgeFaraj
Frequent Contributor
That's interesting...  I tried doing this to test it out:

var inputFeatures = new GPFeatureRecordSetLayer("InputFeatures");
inputFeatures.FeatureSet.Fields = new List<Field> { new Field() { FieldName = "PROP_ID" } };


but the Geoprocessor fails now and these are the details of the error:

Unable to complete operation.
Error executing tool.: ERROR 000210: Cannot create output C:\Users\gfaraj\AppData\Local\Temp\arcgisruntime_8188\geotools\jobs\_\j13c432afc4014a6a9eed8b1b446e0a6b\scratch\scratch.gdb\OutputFeature
Failed to execute (Buffer).
Failed to execute (BufferModel).
Failed to execute (BufferModel).
Failed to execute (BufferModel).


Any ideas?
0 Kudos
KevinHibma
Esri Regular Contributor
Off the top of my head? No.
I'll try to make some time this afternoon to test it.
0 Kudos
GeorgeFaraj
Frequent Contributor
Any updates, Kevin?

Thanks.
0 Kudos
KevinHibma
Esri Regular Contributor
I got looking at this mid last week and was off Thursday/Friday, so I handed it off to Mike.
Everything I've seen makes it look possible. I had to hand it off to Mike because I wasn't sure of the code to combine features and attributes into a single parameter. I'm not sure if Mike had anytime to look at it.
As for the code you posted earlier, I think you're on the right track. It just didnt look like yours had any geometry being sent, it was only sending the attributes.
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

Apologies for the delay.

Here's an example of creating a FeatureSet in order to pass both geometry and attributes into a GP service:

             /* 
             * Build the GP Parameters...
             */
            // We want to specify input attributes - create a new FeatureSet.
            FeatureSet featureSet = new FeatureSet();

            // Create the Fields and add one called "VALUE".
            featureSet.Fields = new List<Field> { new Field() { FieldName = "VALUE", Type = Field.FieldType.String, Alias = "VALUE" } };
            
            // Create the graphic to submit.
            Graphic g = new Graphic() { Geometry = e.MapPoint };

            // Add the graphic to the FeatureSet
            featureSet.Features.Add(g);

            // Set the graphic's attribute
            featureSet.Features[0].Attributes["VALUE"] = "Hello";

            // Create a new list of GPParameters
            List<GPParameter> parameters = new List<GPParameter>();

            // Add a new GPFeatureRecordSetLayer to the parameter list, passing in the FeatureSet created above.
            parameters.Add(new GPFeatureRecordSetLayer("Input_Features",featureSet));


The above code ensures the input feature has both geometry and attributes. In order to have the input attributes persisted on your output features you'll additional steps within your model/script.

Cheers

Mike
0 Kudos
GeorgeFaraj
Frequent Contributor
Thanks Mike. Still getting the same error when running the tool. Here's the code that gathers the parameters:

var featureSet = new FeatureSet();
var layer = GetSelectedInputLayer();

featureSet.Fields = new List<Field> { new Field() { FieldName = "PROP_ID", Type = Field.FieldType.Double, Alias = "PROP_ID" } };
foreach (var graphic in layer.SelectedGraphics)
{
 featureSet.Features.Add(graphic);
}
parameters.Add(new GPFeatureRecordSetLayer("InputFeatures", featureSet));
parameters.Add(new GPLinearUnit("Distance", esriUnits.esriMeters, Convert.ToDouble(distanceText.Text)));


Again the exception contains the following details:

Unable to complete operation.
Error executing tool.: ERROR 000210: Cannot create output C:\Users\gfaraj\AppData\Local\Temp\arcgisruntime_8188\geotools\jobs\_\j13c432afc4014a6a9eed8b1b446e0a6b\scratch\scratch.gdb\OutputFeature
Failed to execute (Buffer).
Failed to execute (BufferModel).
Failed to execute (BufferModel).
Failed to execute (BufferModel).


If I remove the line that sets the Fields on the feature set, the tool completes, but the resulting graphics don't have the original inputs' attributes.
0 Kudos
GeorgeFaraj
Frequent Contributor
I'm still having this problem. Can someone help?
0 Kudos
MatthewBrown1
Deactivated User
Hi Charles,

This may not be related but we had some problems with local GP tasks intermittently failing on some machines, often returning "Error: 000210 : Cannot create output..." (amongst others). This was related to anti-virus and group policy security settings in our corporate environment. (Everything worked fine in my dev environment, but the same code/data failed elsewhere.)

Are you running 1.0 or 10.1.1? The upgrade solved a few quirky issues we were having, so might be worth a try.

Also, if you have access to ArcGIS Server, try publishing a GP service and calling that from your Runtime app. (In my case the full AGS GP service worked, when the local GPK failed.)

Good luck!
0 Kudos
GeorgeFaraj
Frequent Contributor

This may not be related but we had some problems with local GP tasks intermittently failing on some machines, often returning "Error: 000210 : Cannot create output..." (amongst others). This was related to anti-virus and group policy security settings in our corporate environment. (Everything worked fine in my dev environment, but the same code/data failed elsewhere.)


Interesting. The thing is, the tool runs fine if I don't specify the Fields collection. But then the output doesn't contain the fields of the input features; it contains the fields of the schema set in the GPK; which is the problem I'm trying to resolve.


Are you running 1.0 or 10.1.1? The upgrade solved a few quirky issues we were having, so might be worth a try.


I'm running 10.1.1 already.


Also, if you have access to ArcGIS Server, try publishing a GP service and calling that from your Runtime app. (In my case the full AGS GP service worked, when the local GPK failed.)


I don't have access to ArcGIS Server right now.

Thanks!
0 Kudos