Can't add GPResultImagelayer to map

2856
4
Jump to solution
08-06-2015 04:26 AM
JanneEriksson
New Contributor

I have created an GPK package that results in a raster. I'm using SubmitJob to run it and GPResultImagelayer to add the geoprocessing result to the map. But it fails at map.Layers.Add(gpResultLayer) with the error shown in attached picture.

When testing gpResultLayer.ServiceUri in a browser, I can fetch the tif-image and it looks okey.

This is a bit of the code, a little simplified:

if (result.JobStatus == GPJobStatus.Succeeded)

{

     var gpResultLayer = await _gpTask.GetResultImageLayerAsync(result.JobID, "outraster") as GPResultImageLayer;

     await gpResultLayer.InitializeAsync();

     if (gpResultLayer.Status == Esri.ArcGISRuntime.Layers.LayerStatus.Initialized)

     {

               gpResultLayer.Opacity = 0.5;

               gpResultLayer.ID = "raster";

               map.Layers.Add(gpResultLayer);

     }

}

What can be the reason for this problem?

I'm not sure if I provided information enough, but I give it a try.

0 Kudos
1 Solution

Accepted Solutions
MichaelBranscomb
Esri Frequent Contributor

Hi,

Thanks for the reproducer. In your code you need to change the result request to use "GetResultMapServiceLayer(JobID)" instead of the result image layer request. However, when doing so in your example it still failed to create the layer. I re-confirmed that this workflow is ok by using the WPF 10.2.5 sample  for Spatial Analyst Contours which uses the "Contour.gpk" file.

I notice in your GPK there's a Python script. This in itself is ok, but it does require some care to get everything lined up correctly since the Analyzers which run in ArcMap and the packaging magic which happens behind the scenes to wire everything up may not be able handle the complexity of the Python script.

My advice is to double check your script - take a look at inputs and outputs and make sure all the spatial references line up for inputs, processing and outputs and also that you're using the ScratchWorkspace variable which allows the LocalServer to handle the output....

... I just noticed on disk I have C:\outraster\... - I think that's the culprit. Try to use ScratchWorkspace or the in_memory workspace which facilitate all the packaging magic.

Cheers

Mike

View solution in original post

0 Kudos
4 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

Please can you supply the full code - including the section where you create and start the local GP service?

If you're able to supply the project and GPK that would help significantly.

Cheers

Mike

0 Kudos
JanneEriksson
New Contributor

Hi Mike

I have attached codebehind, xaml and the GPK.

The GPK is making a raster from a Kernel Density calculation.

I see now that the title of my thread is misleading; the layer IS added but it gives System.Exception and is not visible.

Thanks

//janne

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

Thanks for the reproducer. In your code you need to change the result request to use "GetResultMapServiceLayer(JobID)" instead of the result image layer request. However, when doing so in your example it still failed to create the layer. I re-confirmed that this workflow is ok by using the WPF 10.2.5 sample  for Spatial Analyst Contours which uses the "Contour.gpk" file.

I notice in your GPK there's a Python script. This in itself is ok, but it does require some care to get everything lined up correctly since the Analyzers which run in ArcMap and the packaging magic which happens behind the scenes to wire everything up may not be able handle the complexity of the Python script.

My advice is to double check your script - take a look at inputs and outputs and make sure all the spatial references line up for inputs, processing and outputs and also that you're using the ScratchWorkspace variable which allows the LocalServer to handle the output....

... I just noticed on disk I have C:\outraster\... - I think that's the culprit. Try to use ScratchWorkspace or the in_memory workspace which facilitate all the packaging magic.

Cheers

Mike

0 Kudos
JanneEriksson
New Contributor

MIke

I followed your advice to use GetResultMapServiceLayer instead. And I replaced my Pythonscript to the origin Kernel Density tool, to make things easier. It now works as I want. Thank you so much for showing me the right way to do it.

Regards

Janne

0 Kudos