Broken geometryservice

611
5
11-02-2010 11:36 AM
BenSainsbury
New Contributor
Struggling to debug a problem with a geometryservice projectasync call

code (and I've verified the arguments)
       Dim svcGeom As GeometryService = New GeometryService()
        svcGeom.Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"
        AddHandler svcGeom.ProjectCompleted, AddressOf projectCompleted
        AddHandler svcGeom.Failed, AddressOf svcGeom_Failed

        svcGeom.ProjectAsync(gfxLyr.Graphics.ToList(), New SpatialReference("2838"))


StackTrace:

at ESRI.ArcGIS.Client.Tasks.GeometryService.GetProjectParameter(IList`1 graphics, SpatialReference outSpatialReference, GeometryType& geomType)
   at ESRI.ArcGIS.Client.Tasks.GeometryService.ProjectAsync(IList`1 graphics, SpatialReference outSpatialReference, Object userToken)
   at ESRI.ArcGIS.Client.Tasks.GeometryService.ProjectAsync(IList`1 graphics, SpatialReference outSpatialReference)
   at SL1.MainPage.dlGeomComplete(Object sender, DownloadStringCompletedEventArgs e)
   at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
   at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)

I know that the error does not lie with the URL nor the event handlers since it never makes it there.  The error I get is a null reference exception. I'm totally lost here...

Thanks to anyone who can help,
Ben Sainsbury
Oregon Metro
Portland, OR
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
I think the NullReference exception comes from resolving the SpatialReference.

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Geometry.S...

Note that if you want to specify WKID, it's passed as an integer not as string.

It is also possible that the Graphics' Geometry have null SpatialReference. Thank you for reporting this - we should add a check in case parameters were incorrect.
0 Kudos
BenSainsbury
New Contributor
Thanks for the quick response but no, that's not the problem

Added a new var:

Dim sr As ESRI.ArcGIS.Client.Geometry.SpatialReference = New ESRI.ArcGIS.Client.Geometry.SpatialReference(2838)

and passed it in...

svcGeom.ProjectAsync(gfxLyr.Graphics.ToList(), sr)

and I still get a null reference exception.
0 Kudos
JenniferNery
Esri Regular Contributor
The graphics you are passing probably have Geometry with null SpatialReference.

We will try to get more null checks in our API but for the time-being, please check that the Graphics' Geometry SpatialReference is not null.
0 Kudos
BenSainsbury
New Contributor
Yes, you are right.  For the sake of posterity I will explain further.

I load geometry from a JSON string:

Dim geometry As userShape = DeserializeJson(Of userShape)(strGeom)
Dim gfxLyr As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)
gfxLyr.ClearGraphics()
Dim gfxList As List(Of ESRI.ArcGIS.Client.Graphic) = New List(Of ESRI.ArcGIS.Client.Graphic)
For Each Polygon As MainPage.Polygon In geometry.geometry
    Dim pointconverter As New PointCollectionConverter
    Dim pointCollection1 As ESRI.ArcGIS.Client.Geometry.PointCollection = TryCast(pointconverter.ConvertFromString(Polygon.coords), ESRI.ArcGIS.Client.Geometry.PointCollection)
    Dim g As New Graphic()
    Dim p As ESRI.ArcGIS.Client.Geometry.Polygon = New ESRI.ArcGIS.Client.Geometry.Polygon()
    p.SpatialReference = New SpatialReference(2269)
    p.Rings.Add(pointCollection1)
    g.Geometry = p
    IDList.Add(Polygon.ID)
    gfxList.Add(g)
Next


The key line I was missing was to assign a spatial reference to each polygon.  It wasn't really clear to me what the graphics were deriving their s.r. from...esp. since the graphics layer's spatial reference is readonly (no setter) - derived from the map object(?)

Yeah, a little more info from the API for stuff like this...Not the first time that geometry service params have totally befuddled me.

Thanks for your time
0 Kudos
JenniferNery
Esri Regular Contributor
0 Kudos