Select to view content in your preferred language

Get FeatureSet from GraphicsLayer

2348
6
05-21-2010 10:15 AM
MikeLowe
Emerging Contributor
Looking at the sample code for the Query, I see that it is possible to set a GraphicsLayer's graphicProvider property as the FeatureSet returned from the QueryTask. I was wondering how to do the opposite of this, specifically, how to get a FeatureSet from a GraphicsLayer?

Thanks
Tags (2)
0 Kudos
6 Replies
DasaPaddock
Esri Regular Contributor
You can get all the features from the graphicslayer's graphicProvider, which is an ArrayCollection.

e.g.

new FeatureSet(ArrayCollection(myGL.graphicProvider).toArray())
0 Kudos
MikeLowe
Emerging Contributor
Ahh thank you...I had something similar to this, I was just missing the toArray()...that helps very much!
0 Kudos
MikeLowe
Emerging Contributor
Hi, I've implemented this, and started testing. To test if it was working I did two things:

I looped through all the graphics in featureSet.features and created a new MapPoint from the geometry property of each graphic, then used the Alert to display the x and y values of the MapPoint. Always, this showed "0 0".

Then I created another graphics layer and tried to set the featureSet.features to the graphicProvider of the layer. No geometry is displayed.

The reason I need the featureSet is because I need to use it as an input parameter for a network analyst model.


Thanks
0 Kudos
DasaPaddock
Esri Regular Contributor
0 Kudos
MikeLowe
Emerging Contributor
I am populating the GraphicsLayer initially from an HTTPService connected to an external XML file with 4 properties (two of which are POINT_X and POINT_Y). I set the result of the HTTPService to an array and create a new graphic which is then added it to the GraphicsLayer while looping through the array.

This succesfully maps each point, but I would like the user to be able to choose a subset of these points (backcountry campsites) as parameters for a route solving geoprocessing model. The subset is a new GraphicLayer symbolized by a Red Flag (to indicate destination). The user drags the campsites into a List control and a new graphic is added to the destinations GraphicsLayer on the dragDrop event using the data from the newly created list item.

Is it possible to create a new FeatureSet, loop through the graphics in the destinations layer and manually add a new feature for each graphic?

I suppose if there is no way to to this, I could Query the original service and use the names of the points in the graphics layer as a filter for the Query.

I hope this isn't too confusing. I can clarify further if need be.

Thanks
0 Kudos
MikeLowe
Emerging Contributor
Ok, I've worked around this problem by creating a query on the service which returns the geometry of the selected points.
0 Kudos