Maintain graphic attributes when it is reprojected

623
4
09-20-2010 07:27 AM
SethPatrich
New Contributor III
I am using the ESRI Silverlight API to reproject a graphic into GCS_WGS_1984.  The graphic has a single mappoint as it's geometry property.

Here is the code I am using:


           
//mp contains the MapPoint geometry
Graphic projectedGraphic = new Graphic() { Geometry = mp };
projectedGraphic.Attributes.Add("MyAttribute", "Data");

_geometryService.ProjectAsync(new List<Graphic>() {  projectedGraphic  }, new SpatialReference(4326));


The graphic reprojects correctly, however the resulting graphic does not contain the attribute that I previously had assigned.  Is there any way to maintain this attribute across a reprojection?

Thanks,
Seth
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
You can use the 3rd parameter userToken of ProjectAsync like so:
_geometryService.ProjectAsync(new List<Graphic>() {  projectedGraphic  }, new SpatialReference(4326), projectedGraphic);
and in the Completed event, you can retrieve graphic with attributes through the UserState:
void geometryService_ProjectCompleted(object sender, GraphicsEventArgs e)
{
            Graphic projectedGraphic  = e.UserState as Graphic;
// TODO: complete project completed logic here.
}
0 Kudos
AndriusBogvila
New Contributor II
You can use the 3rd parameter userToken of ProjectAsync like so:
_geometryService.ProjectAsync(new List<Graphic>() {  projectedGraphic  }, new SpatialReference(4326), projectedGraphic);
and in the Completed event, you can retrieve graphic with attributes through the UserState:
void geometryService_ProjectCompleted(object sender, GraphicsEventArgs e)
{
            Graphic projectedGraphic  = e.UserState as Graphic;
// TODO: complete project completed logic here.
}


However this works only if you are projecting one geometry. If you pass more of them then you have to add a collection of attributes and then somehow match the correct geometry with the correct attribute value when the projection result is retrieved (assuming that geometries are returned in the same order).

Anyway, I'm a bit confused why instead of taking Geometries it takes Graphics as an argument if it doesn't return back the Graphic.Attributes property. So when you want to re-project a geometry, you have to wrap it inside a Graphic, put it in a collection and then retrieve it back when you get a result. Maybe someone knows why it is done this way and maybe there actually is a way to maintain the Attributes inside a Graphic?
0 Kudos
GaryBushek
New Contributor III
has anyone figured out how to maintain attributes when projecting multiple graphics at once.  Not sure I should trust the projected results are returned in the same order as the original list set as the userToken parameter.

I'd love to call the projectAsync method for each graphic individually but I have a list of potentially hundreds of points.
0 Kudos
DaveTimmins
Occasional Contributor II
Hi,

you can do it by passing a collection as the usertoken and it's returned in the same order. I wrote a blog post about this a while back http://davetimmins.wordpress.com/2011/08/25/using-the-usertoken/

Cheers,
0 Kudos