/// <summary> /// Called when the sketch finishes. This is where we will create the sketch operation and then execute it. /// </summary> /// <param name="geometry">The geometry created by the sketch.</param> /// <returns>A Task returning a Boolean indicating if the sketch complete event was successfully handled.</returns> protected override Task <bool> OnSketchCompleteAsync(Geometry geometry) { if (geometry.GeometryType == GeometryType.Polygon) { Polygon polygon = (Polygon)geometry; if (polygon.PointCount > 500) { MessageBox.Show("Too many vertices. Please simplify your AOI. Max vertices: 500"); return(base.OnSketchCompleteAsync(geometry)); } } if (_graphic != null) { _graphic.Dispose(); _graphic = null; } addgraphic(geometry); DockPane pane = FrameworkApplication.DockPaneManager.Find("Planet_Data_DocPane"); Data_DocPaneViewModel data_DocPaneViewModel = (Data_DocPaneViewModel)pane; data_DocPaneViewModel.AOIGeometry = geometry; data_DocPaneViewModel.Activate(true); //addwmts("asdasd"); FrameworkApplication.SetCurrentToolAsync(null); return(base.OnSketchCompleteAsync(geometry)); }
protected override async void OnClick() { Polygon polygone = null; await QueuedTask.Run(() => { try { //Get the active map view. var mapView = MapView.Active; if (mapView == null) { return; } //Get the selected features from the map and filter out the standalone table selection. var selectedFeatures = mapView.Map.GetSelection() .Where(kvp => kvp.Key is BasicFeatureLayer) .ToDictionary(kvp => (BasicFeatureLayer)kvp.Key, kvp => kvp.Value); foreach (var item in selectedFeatures) { Console.WriteLine(item.Key); } var rowCursor = mapView.Map.GetSelection(); var selection = mapView.Map.GetSelection(); var keyValuePairs = selection.Where(kvp => (kvp.Key is BasicFeatureLayer) && (kvp.Key as BasicFeatureLayer).ShapeType == esriGeometryType.esriGeometryPolygon); foreach (var kvp in keyValuePairs) { var layer = kvp.Key as BasicFeatureLayer; if (kvp.Value.Count > 1) { var oid = kvp.Value.First(); var oidField = layer.GetTable().GetDefinition().GetObjectIDField(); var qf = new ArcGIS.Core.Data.QueryFilter() { WhereClause = string.Format("{0} = {1}", oidField, oid) }; var cursor = layer.Search(qf); Feature row = null; if (cursor.MoveNext()) { row = cursor.Current as Feature; } if (row == null) { continue; } polygone = (Polygon)row.GetShape(); } else { var oid = kvp.Value.First(); var oidField = layer.GetTable().GetDefinition().GetObjectIDField(); var qf = new ArcGIS.Core.Data.QueryFilter() { WhereClause = string.Format("{0} = {1}", oidField, oid) }; var cursor = layer.Search(qf); Feature row = null; if (cursor.MoveNext()) { row = cursor.Current as Feature; } if (row == null) { continue; } polygone = (Polygon)row.GetShape(); } } } catch (Exception ex) { MessageBox.Show("There was an error getting the geometry of the selected shape. Please try your selection again." + Environment.NewLine + "Error: " + ex.Message); Console.WriteLine("Error getting select shape geom"); return; } }); if (polygone.PointCount > 500) { MessageBox.Show("Too many vertices. Please simplify the selected Polygon or choose another one. Max vertices: 500"); return; } DockPane pane = FrameworkApplication.DockPaneManager.Find("Planet_Data_DocPane"); Data_DocPaneViewModel data_DocPaneViewModel = (Data_DocPaneViewModel)pane; data_DocPaneViewModel.AOIGeometry = (Geometry)polygone; pane.IsVisible = true; data_DocPaneViewModel.Activate(true); }