private void ExecuteSpatialSelectionButton_Click(object sender, RoutedEventArgs e) { GraphicsLayer selectionGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer; selectionGraphicslayer.ClearGraphics(); //My Point layer that will be queried QueryTask queryTask = new QueryTask((PointsSelected.SelectedItem as FeatureLayer).Url); queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted; queryTask.Failed += QueryTask_Failed; Query query = new ESRI.ArcGIS.Client.Tasks.Query(); //Specify fields to return from query...all fields query.OutFields.Add("*"); //Here's where I'm having problems: I can't figure out how to set the second combo box (the polygon selected layer) to a graphic layer or maybe it needs to be a featurelayer?? GraphicsLayer polyGraphicLayer = new GraphicsLayer((PolySels.SelectedItem as GraphicsLayer).Url); //FeatureLayer polyFeatureLayer = new FeatureLayer((PolySels.SelectedItem as FeatureLayer).Url); //Here's the second part that is confusing me based on what I do above should I preform my query with the graphiclayer and use the fullextent or with the feature layer and use the geometry?? query.Geometry = polyGraphicLayer.FullExtent; // query.SpatialRelationship = SpatialRelationship.esriSpatialRelContains; // query.Geometry = polyFeatureLayer.Geometry; // Return geometry with result features query.ReturnGeometry = true; queryTask.ExecuteAsync(query); }
If I drop the code that I was questions and instead add:
int layernum = PolySels.SelectedIndex;
query.Geometry = Map.Layers[layernum].FullExtent;
It works but it returns every single point...no matter what. It doesn't matter if the point fall inside or outside of the poly?
private void ExecuteSpatialSpeciesNameButton_Click(object sender, RoutedEventArgs e) { GeometryService geometryService = new GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Geometry/GeometryServer"); geometryService.RelationCompleted += GeometryService_RelationCompleted; GraphicsLayer pointGraphicsLayer = Map.Layers["MyPointGraphicsLayer"] as GraphicsLayer; pointGraphicsLayer = Map.Layers[0] as GraphicsLayer; GraphicsLayer polygonGraphicsLayer = Map.Layers["MyPolygonGraphicsLayer"] as GraphicsLayer; int layernum = PolySels.SelectedIndex; polygonGraphicsLayer = Map.Layers[layernum] as GraphicsLayer; geometryService.RelationAsync(pointGraphicsLayer.Graphics.ToList(), polygonGraphicsLayer.Graphics.ToList(), GeometryRelation.esriGeometryRelationWithin, null); } private void GeometryService_RelationCompleted(object sender, RelationEventArgs args) { List<GeometryRelationPair> results = args.Results; foreach (GeometryRelationPair pair in results) { //I'm unsure how to grap the reults (graphics) and set the symbol and then add the results to the map and my featuredatagrid...similar to my query operations // results.Symbol = LayoutRoot.Resources["ResultsMarkerSymbol"] as SimpleMarkerSymbol; }
If I drop the code that I was questions and instead add:
int layernum = PolySels.SelectedIndex;
query.Geometry = Map.Layers[layernum].FullExtent;
It works but it returns every single point...no matter what. It doesn't matter if the point fall inside or outside of the poly?
private void MyDrawSurface_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args) query.Geometry = args.Geometry;
FeatureLayer polyLayer = Map.Layers[5] as FeatureLayer; query.Geometry = polyLayer.Geometry;
private void ExecuteSpatialSpeciesNameButton_Click(object sender, RoutedEventArgs e) { GraphicsLayer selectionGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer; selectionGraphicslayer.ClearGraphics(); QueryTask queryTask = new QueryTask((Layers.SelectedItem as FeatureLayer).Url); queryTask.ExecuteCompleted += QuerySpa_ExecuteCompleted; queryTask.Failed += QuerySpa_Failed; Query query = new ESRI.ArcGIS.Client.Tasks.Query(); query.OutFields.Add("*"); GraphicsLayer polygonGraphicsLayer = Map.Layers["MyPolygonGraphicsLayer"] as GraphicsLayer; //--------------HERE"S MY CHANGE INSTEAD OF POINT TO A MAP LAYER I"M SETTING IT TO A SERVICE -------------------------------------------------------------- string baseUrl = "http://servername/ArcGIS/rest/services/servicename/MapServer"; FeatureLayer featureLayermodel = new FeatureLayer() { Url = string.Format("{0}/{1}", baseUrl, PolySels.SelectedIndex) }; featureLayermodel.Initialize(); // query.Geometry = featureLayermodel.Graphics[0].Geometry; //-----------THIS RETURNS NOTHING -----SEE BELOW FOR ERROR ----// query.Geometry = featureLayermodel.FullExtent; // Return geometry with result features query.ReturnGeometry = true; queryTask.ExecuteAsync(query); }