private void UpdateGeometry(string operation, double segmentLength, double deviation)
        {
            // Start with the original polyline.
            Polyline polyline = _originalPolyline;

            // Apply the selected operation.
            if (operation == "Generalize")
            {
                // Reset the other slider.
                _segmentLengthSlider.Progress = 0;

                polyline = (Polyline)GeometryEngine.Generalize(polyline, deviation, true);

                // Update the result label.
                _resultLabel.Text = $"Operation: Generalize, Deviation: {deviation:f}";
            }
            else
            {
                // Reset the other slider.
                _deviationSlider.Progress = 0;

                polyline = (Polyline)GeometryEngine.Densify(polyline, segmentLength);

                // Update the result label.
                _resultLabel.Text = $"Operation: Densify, Segment length: {segmentLength:f}";
            }

            // Update the graphic geometries to show the results.
            _resultPolylineGraphic.Geometry = polyline;
            _resultPointGraphic.Geometry    = new Multipoint(polyline.Parts.SelectMany(m => m.Points));
        }
예제 #2
0
        // Draw and densify a user defined polygon
        private async void DensifyButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _inputOverlay.Graphics.Clear();
                _resultOverlay.Graphics.Clear();

                // Request polygon from the user
                var poly = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon, _polySymbol) as Polygon;

                // Add original polygon and vertices to input graphics layer
                _inputOverlay.Graphics.Add(new Graphic(poly, _polySymbol));
                foreach (var coord in poly.Parts.First().GetPoints())
                {
                    _inputOverlay.Graphics.Add(new Graphic(coord, _origVertexSymbol));
                }

                // Densify the polygon
                var densify = GeometryEngine.Densify(poly, MyMapView.Extent.Width / 100) as Polygon;

                // Add new vertices to result graphics layer
                foreach (var coord in densify.Parts.First().GetPoints())
                {
                    _resultOverlay.Graphics.Add(new Graphic(coord, _newVertexSymbol));
                }
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog("Densify Error: " + ex.Message, "Sample Error").ShowAsync();
            }
        }
예제 #3
0
        private void OnUIChanged(object sender, EventArgs e)
        {
            // Start with the original polyline.
            Polyline polyline = _originalPolyline;

            // Reset the slider if the operation is changed.
            if (sender is UISegmentedControl)
            {
                _slider.Value = 100.0F;
            }

            // Apply the selected operation.
            if (_operationPicker.SelectedSegment == 0)
            {
                polyline = (Polyline)GeometryEngine.Densify(polyline, _slider.Value);

                // Update the result label.
                _resultLabel.Text = $"Densify - Segment length: {_slider.Value:f}";
            }
            else
            {
                polyline = (Polyline)GeometryEngine.Generalize(polyline, _slider.Value, true);

                // Update the result label.
                _resultLabel.Text = $"Generalize - Deviation: {_slider.Value:f}";
            }

            // Update the graphic geometries to show the results.
            _resultPolylineGraphic.Geometry = polyline;
            _resultPointGraphic.Geometry    = new Multipoint(polyline.Parts.SelectMany(m => m.Points));
        }
예제 #4
0
        private void UpdateGeometry(string operation, double value)
        {
            // Start with the original polyline.
            Polyline polyline = _originalPolyline;

            // Apply the selected operation.
            if (operation == "Generalize")
            {
                polyline = (Polyline)GeometryEngine.Generalize(polyline, value, true);

                // Update the result label.
                _resultLabel.Text = $"Generalize - Deviation: {value:f}";
            }
            else
            {
                polyline = (Polyline)GeometryEngine.Densify(polyline, value);

                // Update the result label.
                _resultLabel.Text = $"Densify - Segment length: {value:f}";
            }

            // Update the graphic geometries to show the results.
            _resultPolylineGraphic.Geometry = polyline;
            _resultPointGraphic.Geometry    = new Multipoint(polyline.Parts.SelectMany(m => m.Points));
        }
        private void DensifyPolygonsButton_Click(object sender, RoutedEventArgs e)
        {
            //hide/show ui elements
            try
            {
                var maxSegLength = GetMaxSegmentLength();
                var results      = GeometryEngine.Densify(densifyPolygonGeometry, maxSegLength);
                //show the vertices for the polygon
                foreach (var vert in (results as Polygon).Parts.FirstOrDefault().GetPoints())
                {
                    var graphic = new Graphic {
                        Geometry = new MapPoint(vert.X, vert.Y), Symbol = densifyVertexMarkerSymbol
                    };
                    graphicsLayerVertices.Graphics.Add(graphic);
                }
            }
            catch (Exception ex)
            {
                var dlg = new MessageDialog(ex.Message, "Geometry Engine Failed!");
                var _   = dlg.ShowAsync();
            }

            //Hide/show ui elements
            ResetUI();
        }
예제 #6
0
        // Draw and densify a user defined polygon
        private async void DensifyButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _inputOverlay.Graphics.Clear();
                _resultsOverlay.Graphics.Clear();

                // Request polygon from the user
                var poly = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon, _polySymbol) as Polygon;

                // Add original polygon and vertices to input graphics layer
                _inputOverlay.Graphics.Add(new Graphic(poly, _polySymbol));
                foreach (var mapPoint in poly.Parts.First().GetPoints())
                {
                    _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 polygon
                var densify = GeometryEngine.Densify(poly, viewpointExtent.Width / 100) as Polygon;

                // Add new vertices to result graphics layer
                foreach (var mapPoint in densify.Parts.First().GetPoints())
                {
                    _resultsOverlay.Graphics.Add(new Graphic(mapPoint, _newVertexSymbol));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Densify Error: " + ex.Message, "Densify Geometry Sample");
            }
        }
        // Draw and densify a user defined polygon
        private async void DensifyButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                inputGraphics.Graphics.Clear();
                resultGraphics.Graphics.Clear();

                // Request polygon from the user
                var poly = await mapView.Editor.RequestShapeAsync(DrawShape.Polygon, _polySymbol) as Polygon;

                // Add original polygon and vertices to input graphics layer
                inputGraphics.Graphics.Add(new Graphic(poly, _polySymbol));
                foreach (var coord in poly.Rings.First())
                {
                    inputGraphics.Graphics.Add(new Graphic(new MapPoint(coord, poly.SpatialReference), _origVertexSymbol));
                }

                // Densify the polygon
                var densify = GeometryEngine.Densify(poly, mapView.Extent.Width / 100) as Polygon;

                // Add new vertices to result graphics layer
                foreach (var coord in densify.Rings.First())
                {
                    resultGraphics.Graphics.Add(new Graphic(new MapPoint(coord, poly.SpatialReference), _newVertexSymbol));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Densify Error: " + ex.Message, "Densify Geometry Sample");
            }
        }
예제 #8
0
        /// <summary>
        /// Asynchronous task that splits the current sketch geometry into 100 segments of equal length.
        /// </summary>
        /// <returns>Task{bool}</returns>
        private async Task <bool> ExecuteDensify()
        {
            // get the current sketch geometry from the editing module
            var sketchGeometry = await EditingModule.GetSketchGeometryAsync();

            // check if geometry is valid
            bool isGeometryValid = await QueuingTaskFactory.StartNew <bool>(() =>
            {
                bool validGeometry = true;

                if (sketchGeometry == null || sketchGeometry.IsEmpty)
                {
                    validGeometry = false;
                }

                return(validGeometry);
            });

            if (!isGeometryValid)
            {
                return(false);
            }

            // get the currently selected features from the map
            // the selected feature uses the above selected geometry
            var currentlySelectedFeature = await MappingModule.ActiveMapView.Map.GetSelectionSetAsync();

            // set up an edit operation
            EditOperation editOperation = new EditOperation();

            editOperation.Name = "Densify selected geometry";

            Geometry densifiedGeometry = null;

            // modify the geometry in the sketch geometry
            // the geometry operation needs to run as it own task
            await QueuingTaskFactory.StartNew(() =>
            {
                // compute a length fur the current geometry when divided into 100 segments
                var segmentLength = GeometryEngine.Length(sketchGeometry) / 100;
                // compute a new densified geometry
                densifiedGeometry = GeometryEngine.Densify(sketchGeometry, segmentLength);
            });

            // for the currently selected feature go through the layers to which the feature belongs
            foreach (var mapMember in currentlySelectedFeature.MapMembers)
            {
                // for each of the selections in the layer (map member)
                foreach (var selectedOID in currentlySelectedFeature[mapMember])
                {
                    // provide the densified geometry for the selected feature as part of the modify operation
                    editOperation.Modify((Layer)mapMember, selectedOID, densifiedGeometry);
                }
            }

            // execute the edit operation and return
            return(await editOperation.ExecuteAsync());
        }