Spatial reference for Geoprocessing Task

1988
5
06-14-2016 09:20 AM
DougCollins
Occasional Contributor

I am using the JS 4.0 API and am trying to get the return result from an asynchronous service, but I keep getting the error:

TypeError: d.spatialReference is undefined

on the result.

When I created the GP task I set the output spatial reference to that of the base map ...

gp = new Geoprocessor(testURL);

  gp.outSpatialReference = {

  wkid: 102100

  };

However, when I try to get the result image, I get the error stating that spatialReference is undefined.  I am getting the result as follows:

var resultImage = gp.getResultImageLayer(result.jobId, "myImage", imageParams);

Is there any way to force or set the spatialReference on the return result image?  Maybe in the "imageParams"?  But the docs on imageParameters don't really seem to say that I can set the spatialReference.  Is it possible?

Thanks,

Charlie

0 Kudos
5 Replies
KristianEkenes
Esri Regular Contributor

Try setting the outSpatialReference to an instance of SpatialReference. This property doesn't appear to be autocastable. So instead of this:

gp = new Geoprocessor(testURL);
gp.outSpatialReference = {
  wkid: 102100
};

Try this:

gp = new Geoprocessor(testURL);
gp.outSpatialReference = new SpatialReference({
  wkid: 102100
});
0 Kudos
DougCollins
Occasional Contributor

Thanks for the reply Kristian.

I tried as you suggested by setting to an instance of SpatialReference, however when I run it, I still get the same error.  If I look at the result in Firebug, it shows that the result image has a SpatialReference of 102008 (NAD_1983_Albers).  I suspect that because my base map (and 3D view) are Web Mercator (102100), that it will not display and will give me the "TypeError: d.spatialReference is undefined" message when I try to do   map.add(resultImage);

Is there another way around this?

Thanks,

Charlie

0 Kudos
KristianEkenes
Esri Regular Contributor

Ah. I see now. Yeah. I don't think all of the Geoprocessor code is complete yet, but you can try setting the spatial reference on the ImageParameters using the imageSpatialReference property. This isn't documented in 4.0, but it may (or may not) work.

Another thing to note is that SceneView in global mode does not support projected coordinate systems. However, SceneView in local mode does. So if you switch to a local viewingMode and add the image to the view, then you may be able to see it then. Keep in mind that the SceneView must be constructed with that SR - 102008 (NAD_1983_Albers). You can't change the spatial reference of the view after it's been created (yet anyway).

Try those ways and let me know if either of them work out for you.

0 Kudos
DougCollins
Occasional Contributor

I tried setting the imageSpatialReference property but it gave another error this time:

"Error: [accessor] cannot access unknown property 'layerDefinitions' on instance of esri.layers.support.ImageParameters."

So I also tried setting layerDefinitions as well, but I still got the same 'layerDefinitions' error.

Maybe I will wait until the 4.0 API is more complete.   I hope that they add a bit more documentation to the geoprocessing section as well.  Maybe more example snippets would help.

Thanks for your help.

Charlie

0 Kudos
KristianEkenes
Esri Regular Contributor

Thanks for the feedback Charlie. I think it is apparent that our Geoprocessing documentation isn't complete at the moment. We will make sure to revisit it, including with more snippets so it is more clear.

0 Kudos