/// <summary> /// Raises the <see cref="MeasureUpdated"/> and updates display based on <see cref="MeasureItemCollection"/>, /// <see cref="TotalLength"/> and <see cref="Area"/> properties. /// </summary> private void UpdateDisplay(Polyline polyline) { Polygon area = null; if (polyline != null && polyline.Parts[0].Count > 2) { area = new Polygon(polyline.Parts, polyline.SpatialReference); } OnMeasureUpdated((Geometry)area ?? polyline); MapPoint previousPoint = null; int coordinateIndex = 0; foreach (var measureItem in MeasureItemCollection) { measureItem.CoordinateIndex = coordinateIndex++; if (previousPoint != null) { measureItem.Length = GeometryEngine.GeodesicLength( new Polyline(new MapPoint[] { previousPoint, measureItem.Location }, measureItem.Location.SpatialReference), GeodeticCurveType.GreatElliptic); } previousPoint = measureItem.Location; } MeasureSummary.TotalLength = polyline == null || polyline.Parts[0].Count < 2 ? 0 : GeometryEngine.GeodesicLength(polyline); MeasureSummary.Area = area == null ? 0 : GeometryEngine.GeodesicArea(area); }
// 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(); } }
private async void MeasureButton_Click(object sender, RoutedEventArgs e) { string message = null; try { var geometry = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polyline); var polyline = geometry as Polyline; if (polyline != null && polyline.Parts != null && polyline.Parts.Count > 0) { var vertices = polyline.Parts[0].GetPoints(); var count = vertices != null?vertices.Count() : 0; if (count > 1) { var result = new StringBuilder(); var totalLength = GeometryEngine.GeodesicLength(polyline); result.AppendFormat("Total Length\t:\t{0:0} m\n", totalLength); if (count > 2) { var polygon = new Polygon(polyline.Parts, polyline.SpatialReference); var area = GeometryEngine.GeodesicArea(polygon); result.AppendFormat("Area\t\t:\t{0:0} m²\n", area); } if (result.Length > 0) { message = string.Format("Measure results:\n{0}", result); } } } } catch (TaskCanceledException) { } catch (Exception ex) { message = ex.Message; } if (!string.IsNullOrWhiteSpace(message)) { await new MessageDialog(message).ShowAsync(); } }
private async Task doCalculateAreaAndLength() { try { //Wait for user to draw var geom = await mapView1.Editor.RequestShapeAsync(DrawShape.Polygon); //show geometry on map _graphicsOverlay.Graphics.Clear(); var g = new Graphic { Geometry = geom, Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol }; _graphicsOverlay.Graphics.Add(g); //Calculate results var areaPlanar = GeometryEngine.Area(geom); ResultsAreaPlanar.Text = string.Format("{0} millas cuad.", (areaPlanar * toSqMilesConversion).ToString("n3")); var perimPlanar = GeometryEngine.Length(geom); ResultsPerimeterPlanar.Text = string.Format("{0} millas", (perimPlanar * toMilesConversion).ToString("n3")); var areaGeodesic = GeometryEngine.GeodesicArea(geom); ResultsAreaGeodesic.Text = string.Format("{0} millas cuad.", (areaGeodesic * toSqMilesConversion).ToString("n3")); var perimGeodesic = GeometryEngine.GeodesicLength(geom); ResultsPerimeterGeodesic.Text = string.Format("{0} millas cuad.", (perimGeodesic * toMilesConversion).ToString("n3")); //Instructions.Visibility = Windows.UI.Xaml.Visibility.Collapsed; Results.Visibility = Windows.UI.Xaml.Visibility.Visible; Reiniciar.IsEnabled = true; } catch (System.Threading.Tasks.TaskCanceledException) { var dlg = new MessageDialog("El trazado actual ha sido cancelado.", "Tarea Cancelada!"); var _x = dlg.ShowAsync(); } }
private async Task DoCalculateAreaAndLengthAsync() { try { //Wait for user to draw var geom = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon); //show geometry on map _graphicsOverlay.Graphics.Clear(); var g = new Graphic { Geometry = geom, Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol }; _graphicsOverlay.Graphics.Add(g); //Calculate results var areaPlanar = GeometryEngine.Area(geom); ResultsAreaPlanar.Text = string.Format("{0} sq. miles", (areaPlanar * toSqMilesConversion).ToString("n3")); var perimPlanar = GeometryEngine.Length(geom); ResultsPerimeterPlanar.Text = string.Format("{0} miles", (perimPlanar * toMilesConversion).ToString("n3")); var areaGeodesic = GeometryEngine.GeodesicArea(geom); ResultsAreaGeodesic.Text = string.Format("{0} sq. miles", (areaGeodesic * toSqMilesConversion).ToString("n3")); var perimGeodesic = GeometryEngine.GeodesicLength(geom); ResultsPerimeterGeodesic.Text = string.Format("{0} miles", (perimGeodesic * toMilesConversion).ToString("n3")); Instructions.Visibility = Windows.UI.Xaml.Visibility.Collapsed; Results.Visibility = Windows.UI.Xaml.Visibility.Visible; } catch (TaskCanceledException) { var _x = new MessageDialog("Current sketch has been canceled.", "Task Canceled!").ShowAsync(); } }
private async Task doCalculateAreaAndLength() { try { // Wait for user to draw var geom = await mapView.Editor.RequestShapeAsync(DrawShape.Polygon); // show geometry on map graphicsLayer.Graphics.Clear(); var graphic = new Graphic { Geometry = geom, Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol }; graphicsLayer.Graphics.Add(graphic); // Calculate results var areaPlanar = GeometryEngine.Area(geom); ResultsAreaPlanar.Text = string.Format("{0} sq. miles", (areaPlanar * toSqMilesConversion).ToString("n3")); var perimPlanar = GeometryEngine.Length(geom); ResultsPerimeterPlanar.Text = string.Format("{0} miles", (perimPlanar * toMilesConversion).ToString("n3")); var areaGeodesic = GeometryEngine.GeodesicArea(geom); ResultsAreaGeodesic.Text = string.Format("{0} sq. miles", (areaGeodesic * toSqMilesConversion).ToString("n3")); var perimGeodesic = GeometryEngine.GeodesicLength(geom); ResultsPerimeterGeodesic.Text = string.Format("{0} miles", (perimGeodesic * toMilesConversion).ToString("n3")); Instructions.Visibility = Visibility.Collapsed; Results.Visibility = Visibility.Visible; } catch (TaskCanceledException) { MessageBox.Show("Current sketch has been canceled.", "Task Canceled!"); } }
public void Work(object obj) { int type = Convert.ToInt32(obj); DrawShape drawType; _points = null; _tempTextGraphic = null; totalLength = 0; Symbol symbol = null; switch (type) { case 0: _points = new List <MapPoint>(); _tempTextGraphic = new List <Graphic>(); symbol = new SimpleLineSymbol(); ((SimpleLineSymbol)symbol).Color = System.Windows.Media.Colors.Orange; ((SimpleLineSymbol)symbol).Style = SimpleLineStyle.Dash; ((SimpleLineSymbol)symbol).Width = 2; drawType = DrawShape.Polyline; break; case 1: symbol = new SimpleLineSymbol(); ((SimpleLineSymbol)symbol).Color = System.Windows.Media.Colors.Orange; ((SimpleLineSymbol)symbol).Style = SimpleLineStyle.Dash; ((SimpleLineSymbol)symbol).Width = 2; drawType = DrawShape.Polygon; break; default: throw new ArgumentOutOfRangeException(); } Geometry geo; if (symbol != null) { _map.Dispatcher.Invoke( new Action( async delegate { if (_map.MapView.Editor.IsActive) { _map.MapView.Editor.Cancel.Execute(null); } try { geo = await _map.MapView.Editor.RequestShapeAsync(drawType, symbol); } catch { geo = null; IsObsolete = true; //clearTextGraphic(); Callback?.Invoke(null); return; } if (geo != null) { // create a new graphic; set the Geometry and Symbol Graphic graphic = new Graphic { Geometry = geo, Symbol = symbol }; MapPoint mp; string text; if (geo is Polyline) { mp = (geo as Polyline).Parts.Last().Last().EndPoint; text = distanceToStr(GeometryEngine.Length(geo) * 111000); } else { mp = (geo as Polygon).Parts.Last().Last().EndPoint; text = areaToStr(GeometryEngine.GeodesicArea(geo) * 111000 * 111000); } addTextSymbol(text, mp); _map.GetGraphicLayer("Drawing").Graphics.Add(graphic); IsObsolete = true; Callback?.Invoke(text); } })); } }
// 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; } }
private void OnStatusUpdated(GeometryEditStatus status) { _measurements.Clear(); var polyline = status.NewGeometry as Polyline; if (polyline == null || polyline.Parts == null || polyline.Parts.Count == 0) { return; } var vertices = polyline.Parts[0].GetPoints(); if (vertices == null || !vertices.Any()) { return; } var count = vertices.Count(); if (count <= 1) { return; } MapPoint previous = null; int i = 1; foreach (var point in vertices) { if (previous == null) { previous = point; continue; } var lineSegment = new Polyline(new MapPoint[] { previous, point }, polyline.SpatialReference); var intermediateLength = GeometryEngine.GeodesicLength(lineSegment); _measurements.Add(string.Format("[{0}-{1}]\t:\t{2:0} m\n", i, i + 1, intermediateLength)); previous = point; i++; } var totalLength = GeometryEngine.GeodesicLength(polyline); TotalLength.Text = string.Format("Total Length\t:\t{0:0} m\n", totalLength); if (count <= 2) { return; } var layer = MyMapView.Map.Layers["ResultLayer"] as GraphicsLayer; if (layer == null) { return; } var graphic = layer.Graphics.FirstOrDefault(); var polygon = new Polygon(vertices, polyline.SpatialReference); if (graphic != null) { graphic.Geometry = polygon; } else { layer.Graphics.Add(new Graphic(polygon)); } if (count <= 1) { return; } if (count <= 2) { return; } var area = GeometryEngine.GeodesicArea(polygon); TotalArea.Text = string.Format("Area\t\t:\t{0:0} m²\n", area); }