Select to view content in your preferred language

Need to query graphics inside of a polygon

611
2
04-13-2011 03:45 PM
GaryButler
New Contributor
Sorry for the newbie question...

I have two graphics layers on my map.  One layer contains graphics of the data I'm interested in - in this case it is leaking pipe information.  The second layer contains the DrawSurface where I can draw a rectangle or other geometry to "select" these graphics.

My question is now that I can draw rectangles and display my graphics, how can I query the graphics that are located within the geometry I've drawn.

I've seen other posts that mention converting the drawn rectangle to an envelope and use Linq but I don't know where to start.  Can someone point me in the right direction?

Thanks in advance for your help.
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
If your first layer is a feature layer you can use a spatial query. In this case the server is doing the geometry calculations : see sample http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SpatialQuery

If your first layer is a pure graphics layer with objects only existing at the client side, it's not that easy.
You can approximate the search by using the intersection of envelopes : see documentation http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Geometry.E...

If you need more precision by taking care of the polygon edges, you will have either to write some math and geometry code or to use a geometry service (sample)
0 Kudos
GaryButler
New Contributor
Thanks so much for the help.  The query below gives me exactly what I'm looking for.

env is the envelope of the rectangle drawn on the DrawSurface. 
MyGraphics is the graphics layer containing the data points I'm trying to select.
SearchResults is a List<Graphic> of the graphics inside the drawn box.

SearchResults = (from Graphic g in ((GraphicsLayer)MyMap.Layers["MyGraphics"]).Graphics where  env.Intersects(g.Geometry.Extent) select g).ToList();
0 Kudos