Geoprocessing results in wrong projection

502
4
07-27-2011 12:06 PM
DavidChevrier
Occasional Contributor II
Hi,   I've created a geoprocessing service that takes a few string inputs and creates a random point feature class (well, it's a little more complex than that, but that is basically what it does).  It works fine inside of arcmap.

I then created a test page using the new beta version of the ArcGIS Viewer for Silverlight, adding the tool.  It also works perfectly and displays the results exactly where they should be. 

Now I'm creating a custom silverlight page for the tool.  I followed all the example code I've seen and while it correctly makes the points (as I can see in the arcgisjobs folder), it displays them all around 0,0 (off of Africa).  So it seems the projection is off.  The app uses the regular web_mercator_aux, but my geoprocessing script uses a geographic coordinate system (and I need to keep it as such, gcs_north_american_1983). 

I've tried setting the task's "OutputSpatialReference" and "ProcessSpatialReference" to mymap.SpatialReference as well setting the graphics' geometry.SpatialReference to the same thing, all with no luck.

So, 2 questions.  One, since the viewer displays them correctly, any chance we could get at the outputted source code??  And two, more realistically, any idea how I can convert the points to the correct system?

Thanks

private void GeoprocessorTask_GetResultDataCompleted(object sender, GPParameterEventArgs e)
{
     GraphicsLayer graphicsLayer = MyMap.Layers["StationLayer"] as GraphicsLayer;
    
     GPFeatureRecordSetLayer gpLayer = e.Parameter as GPFeatureRecordSetLayer;
     foreach (Graphic graphic in gpLayer.FeatureSet.Features)
     {
          graphic.Symbol = LayoutRoot.Resources["RedMarkerSymbol"] as Symbol;
          graphicsLayer.Graphics.Add(graphic);
     }
}
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
By setting the task's 'OutputSpatialReference' to the map spatial reference i.e. a web mercator projection should be OK and your task should return features using this spatial reference.
Try using Fiddler to look at the GeoProcessing request and at the result, this may give a clue.

Else you might convert the coordinates (using ESRI.ArcGIS.Client.Projection.WebMercator) in your GeoprocessorTask_GetResultDataCompleted method.
0 Kudos
DavidChevrier
Occasional Contributor II
Thanks for the reply, however I did try
_geoprocessorTask.OutputSpatialReference = MyMap.SpatialReference;

already and it didn't work.   I've also tried adding the geometry line here:

private static WebMercator _mercator = new WebMercator();
.
.
.

foreach (Graphic graphic in gpLayer.FeatureSet.Features)
{
                graphic.Symbol = LayoutRoot.Resources["RedMarkerSymbol"] as Symbol;
                graphic.Geometry = _mercator.FromGeographic(graphic.Geometry);
  graphicsLayer.Graphics.Add(graphic);
}


But then it just gets in a loop and never outputs anything.  How does the Viewer for Silverlight handle the point results of a geoprocess?  (Since that outputs the results correctly.)
0 Kudos
DavidChevrier
Occasional Contributor II
Also, I'm somewhat new to fiddler.  What tab should I be looking at to help figure this out?
0 Kudos
DavidChevrier
Occasional Contributor II
And I figured it out...  it was dumb too.  Setting the OutputSpatialReference did work, it was WHERE I was setting it.  I was doing it in the MainPage() function (before the map was even set), so it was setting it to a null projection.  I set it after the map was drawn and it works fine.  Thanks for the help!
0 Kudos