// Draw and densify a user defined polygon private async void DensifyButton_Click(object sender, RoutedEventArgs e) { try { resultsPanel.Visibility = Visibility.Collapsed; inputGraphics.Graphics.Clear(); resultGraphics.Graphics.Clear(); // Request polygon or polyline from the user DrawShape drawShape = (DrawShape)comboShapeType.SelectedItem; var original = await mapView.Editor.RequestShapeAsync(drawShape, _fillSymbol); // Add original shape vertices to input graphics layer var coordsOriginal = ((IEnumerable <CoordinateCollection>)original).First(); foreach (var coord in coordsOriginal) { inputGraphics.Graphics.Add(new Graphic(new MapPoint(coord, original.SpatialReference), _origVertexSymbol)); } // Densify the shape var densify = GeometryEngine.GeodesicDensify(original, mapView.Extent.Width / 100, LinearUnits.Meters); inputGraphics.Graphics.Add(new Graphic(densify, _fillSymbol)); // Add new vertices to result graphics layer var coordsDensify = ((IEnumerable <CoordinateCollection>)densify).First(); foreach (var coord in coordsDensify) { resultGraphics.Graphics.Add(new Graphic(new MapPoint(coord, original.SpatialReference), _newVertexSymbol)); } // Results Dictionary <string, object> results = new Dictionary <string, object>(); results["Length"] = GeometryEngine.GeodesicLength(densify) * METERS_TO_MILES; if (original is Polygon) { results["Area"] = GeometryEngine.GeodesicArea(densify) * SQUARE_METERS_TO_MILES; } else { results["Area"] = "N/A"; } results["Vertices Before"] = coordsOriginal.Count(); results["Vertices After"] = coordsDensify.Count(); resultsListView.ItemsSource = results; resultsPanel.Visibility = Visibility.Visible; } catch (TaskCanceledException) { } catch (Exception ex) { MessageBox.Show("Densify Error: " + ex.Message, "Geodesic Densify Sample"); } }
// Draw and densify a user defined polygon private async void DensifyButton_Click(object sender, RoutedEventArgs e) { try { resultsPanel.Visibility = Visibility.Collapsed; _inputGraphics.Graphics.Clear(); _resultGraphics.Graphics.Clear(); // Request polygon or polyline from the user DrawShape drawShape = (DrawShape)comboShapeType.SelectedValue; var original = await mapView.Editor.RequestShapeAsync(drawShape, _fillSymbol); // Add original shape vertices to input graphics layer var coordsOriginal = ((IEnumerable <CoordinateCollection>)original).First(); foreach (var coord in coordsOriginal) { _inputGraphics.Graphics.Add(new Graphic(new MapPoint(coord, original.SpatialReference), _origVertexSymbol)); } // Densify the shape var densify = GeometryEngine.GeodesicDensify(original, mapView.Extent.Width / 100, LinearUnits.Meters); _inputGraphics.Graphics.Add(new Graphic(densify, _fillSymbol)); // Add new vertices to result graphics layer var coordsDensify = ((IEnumerable <CoordinateCollection>)densify).First(); foreach (var coord in coordsDensify) { _resultGraphics.Graphics.Add(new Graphic(new MapPoint(coord, original.SpatialReference), _newVertexSymbol)); } // Results var results = new List <Tuple <string, object> >() { new Tuple <string, object>("Length", GeometryEngine.GeodesicLength(densify) * METERS_TO_MILES), new Tuple <string, object>("Area", (original is Polygon) ? (GeometryEngine.GeodesicArea(densify) * SQUARE_METERS_TO_MILES).ToString("0.000") : "N/A"), new Tuple <string, object>("Vertices Before", coordsOriginal.Count()), new Tuple <string, object>("Vertices After", coordsDensify.Count()) }; resultsListView.ItemsSource = results; resultsPanel.Visibility = Visibility.Visible; } catch (TaskCanceledException) { } catch (Exception ex) { var _ = new MessageDialog("Densify Error: " + ex.Message, "Sample Error").ShowAsync(); } }
// Draw and densify a user defined polygon private async void DensifyButton_Click(object sender, RoutedEventArgs e) { try { resultsPanel.Visibility = Visibility.Collapsed; _inputOverlay.Graphics.Clear(); _resultsOverlay.Graphics.Clear(); // Request polygon or polyline from the user DrawShape drawShape = (DrawShape)comboShapeType.SelectedValue; // Use polyline as default Symbol symbolToUse = _lineSymbol; if (drawShape == DrawShape.Polygon) { symbolToUse = _fillSymbol; } var original = await MyMapView.Editor.RequestShapeAsync(drawShape, symbolToUse); // Account for WrapAround var normalized = GeometryEngine.NormalizeCentralMeridian(original); // Add original shape vertices to input graphics layer var coordsOriginal = (normalized as Multipart).Parts.First().GetPoints(); foreach (var mapPoint in coordsOriginal) { _inputOverlay.Graphics.Add(new Graphic(mapPoint, _origVertexSymbol)); } // Get current viewpoints extent from the MapView var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry); var viewpointExtent = currentViewpoint.TargetGeometry.Extent; // Densify the shape var densify = GeometryEngine.GeodesicDensify(normalized, viewpointExtent.Width / 100, LinearUnits.Meters); if (densify.GeometryType == GeometryType.Polygon) { _inputOverlay.Graphics.Add(new Graphic(densify, _fillSymbol)); } else { _inputOverlay.Graphics.Add(new Graphic(densify, _lineSymbol)); } // Add new vertices to result graphics layer var coordsDensify = (densify as Multipart).Parts.First().GetPoints(); foreach (var mapPoint in coordsDensify) { _resultsOverlay.Graphics.Add(new Graphic(mapPoint, _newVertexSymbol)); } // Results Dictionary <string, object> results = new Dictionary <string, object>(); results["Length"] = GeometryEngine.GeodesicLength(densify) * METERS_TO_MILES; if (normalized is Polygon) { results["Area"] = GeometryEngine.GeodesicArea(densify) * SQUARE_METERS_TO_MILES; } else { results["Area"] = "N/A"; } results["Vertices Before"] = coordsOriginal.Count(); results["Vertices After"] = coordsDensify.Count(); resultsListView.ItemsSource = results; resultsPanel.Visibility = Visibility.Visible; } catch (TaskCanceledException) { } catch (Exception ex) { MessageBox.Show("Densify Error: " + ex.Message, "Geodesic Densify Sample"); } }
// Draw and densify a user defined polygon private async void DensifyButton_Click(object sender, RoutedEventArgs e) { try { DensifyButton.IsEnabled = false; resultsPanel.Visibility = Visibility.Collapsed; _inputOverlay.Graphics.Clear(); _resultsOverlay.Graphics.Clear(); DrawShape drawShape; drawShape = (RadioPolyline.IsChecked.Value) ? drawShape = DrawShape.Polyline : drawShape = DrawShape.Polygon; // Use polyline as default Symbol symbolToUse = _lineSymbol; if (drawShape == DrawShape.Polygon) { symbolToUse = _fillSymbol; } var original = await MyMapView.Editor.RequestShapeAsync(drawShape, symbolToUse); // Account for WrapAround var normalized = GeometryEngine.NormalizeCentralMeridian(original); // Add original shape vertices to input graphics layer var coordsOriginal = (normalized as Multipart).Parts.First().GetPoints(); foreach (var coord in coordsOriginal) { _inputOverlay.Graphics.Add(new Graphic(coord, _origVertexSymbol)); } // Get current viewpoints extent from the MapView var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry); var viewpointExtent = currentViewpoint.TargetGeometry.Extent; // Densify the shape var densify = GeometryEngine.GeodesicDensify(normalized, viewpointExtent.Width / 100, LinearUnits.Meters); if (densify.GeometryType == GeometryType.Polygon) { _inputOverlay.Graphics.Add(new Graphic(densify, _fillSymbol)); } else { _inputOverlay.Graphics.Add(new Graphic(densify, _lineSymbol)); } // Add new vertices to result graphics layer var coordsDensify = (densify as Multipart).Parts.First().GetPoints(); foreach (var coord in coordsDensify) { _resultsOverlay.Graphics.Add(new Graphic(coord, _newVertexSymbol)); } // Results var results = new List <Tuple <string, object> >() { new Tuple <string, object>("Length", GeometryEngine.GeodesicLength(densify) * METERS_TO_MILES), new Tuple <string, object>("Area", (normalized is Polygon) ? (GeometryEngine.GeodesicArea(densify) * SQUARE_METERS_TO_MILES).ToString("0.000") : "N/A"), new Tuple <string, object>("Vertices Before", coordsOriginal.Count()), new Tuple <string, object>("Vertices After", coordsDensify.Count()) }; resultsListView.ItemsSource = results; resultsPanel.Visibility = Visibility.Visible; } catch (TaskCanceledException) { } catch (Exception ex) { var _x = new MessageDialog("Densify Error: " + ex.Message, "Sample Error").ShowAsync(); } finally { DensifyButton.IsEnabled = true; } }