Select to view content in your preferred language

GeometryService issues

1243
7
08-16-2010 07:39 AM
JasonKnisley
Deactivated User
I recently switch my base maps from spatial reference 4326 to 102100, and of course all of my distance measuring tools broke.  I'm now trying to use a Geometry Service, but everything I try results in "Object reference not set to an instance of an object".  The graphic geometry is Polyline.
This is all I'm trying to do:

GeometryService geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
geometryService.ProjectCompleted += GeometryService_ProjectCompleted;
geometryService.Failed += GeometryService_Failed;

List<Graphic> graphicList = new List<Graphic>();
graphicList.Add(graphic);

geometryService.ProjectAsync(graphicList, new SpatialReference(4326));



Any thoughts?
0 Kudos
7 Replies
dotMorten_esri
Esri Notable Contributor
Where are you getting that null-ref exception? Do you have a stacktrace you can share?
0 Kudos
GreggLanzing
Deactivated User
Jason and Morten

I am getting the exact (line for line) problem while trying to reproject a point to 102100.  Did you find the answer for this??

Thanks, Gregg
0 Kudos
DaveTimmins
Deactivated User
Hi,

have you verified that the geometry you are trying to project has a valid spatial reference set?

Also, as an alternative method of projecting the geometry there is this helper class that you can use http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Projection...

Cheers
0 Kudos
JackCibor
Frequent Contributor
Hi,

have you verified that the geometry you are trying to project has a valid spatial reference set?



How would you verify that your input geometry has a valid spatial reference set??
0 Kudos
ChristopherHill
Deactivated User
The spatial reference of your input geometry can be found here:

Graphic.Geometry.SpatialReference

Check to make sure your SpatialRefence of your graphic you are trying to project is not null. I would say that it is null.

GeometryService geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
geometryService.ProjectCompleted += GeometryService_ProjectCompleted;
geometryService.Failed += GeometryService_Failed;

List<Graphic> graphicList = new List<Graphic>();
graphicList.Add(graphic); // <-- this graphic.Geometry.SpatialRefence is probably null

geometryService.ProjectAsync(graphicList, new SpatialReference(4326));

There is a client side Projection from 4326 to 102100 and back linked by Dave above that you can use to avoid sending data over the wire.
Here is the link again http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Projection...
0 Kudos
JackCibor
Frequent Contributor
Sweet....that seems to have solved the issues I was having. I was not setting the spatial reference upon creating the graphics that I wanted to use as the input into the Geometry Service.

Thanks
0 Kudos
ChristopherHill
Deactivated User
Yeah, thre graphics can contain geometry that do not have a spatial reference defined, the map will assume that the X and Y of each point is the same spatial reference as the map and if it is your graphics will appear correctlly even with missing spatial reference, but when you project them the spatial reference needs to be there in order for the service to know that its converting from A to B. in your case it was convert from Null to 4326 and the service threw an excepction.
0 Kudos