Example #1
0
        // Calculates a geometric difference between features and user defined geometry
        private async void DifferenceButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _differenceGraphics.Graphics.Clear();

                // wait for user to draw difference polygon
                var poly = await mapView.Editor.RequestShapeAsync(DrawShape.Polygon);

                // Adjust user polygon for backward digitization
                poly = GeometryEngine.Simplify(poly);

                // get intersecting features from the feature layer
                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.Geometry            = GeometryEngine.Project(poly, _statesLayer.FeatureTable.SpatialReference);
                filter.SpatialRelationship = SpatialRelationship.Intersects;
                filter.MaximumRows         = 52;
                var stateFeatures = await _statesLayer.FeatureTable.QueryAsync(filter);

                // Calc difference between feature geometries and user polygon and add results to graphics layer
                var states = stateFeatures.Select(feature => feature.Geometry);

                var diffGraphics = states
                                   .Select(state => ((bool)useSymmetricDifference.IsChecked)
                        ? GeometryEngine.SymmetricDifference(state, poly)
                        : GeometryEngine.Difference(state, poly))
                                   .Select(geo => new Graphic(geo, _fillSymbol));

                _differenceGraphics.Graphics.AddRange(diffGraphics);
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog("Difference Error: " + ex.Message, "Sample Error").ShowAsync();
            }
        }
        // Handle selection events in the spatial operations picker.
        private void OperationModel_ValueChanged(object sender, EventArgs e)
        {
            // Get the data model that contains the spatial operation choices.
            PickerDataModel operationsModel = (PickerDataModel)_operationPicker.Model;

            // If an operation hasn't been selected, return.
            if (operationsModel.SelectedItem == "")
            {
                return;
            }

            // Remove any currently displayed result.
            _polygonsOverlay.Graphics.Remove(_resultGraphic);

            // Polygon geometry from the input graphics.
            Geometry polygonOne = _graphicOne.Geometry;
            Geometry polygonTwo = _graphicTwo.Geometry;

            // Result polygon for spatial operations.
            Geometry resultPolygon = null;

            // Run the selected spatial operation on the polygon graphics and get the result geometry.
            switch (operationsModel.SelectedItem)
            {
            case "Union":
                resultPolygon = GeometryEngine.Union(polygonOne, polygonTwo);
                break;

            case "Difference":
                resultPolygon = GeometryEngine.Difference(polygonOne, polygonTwo);
                break;

            case "Symmetric difference":
                resultPolygon = GeometryEngine.SymmetricDifference(polygonOne, polygonTwo);
                break;

            case "Intersection":
                resultPolygon = GeometryEngine.Intersection(polygonOne, polygonTwo);
                break;
            }

            // Create a black outline symbol to use for the result polygon.
            SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Black, 1);

            // Create a solid red fill symbol for the result polygon graphic.
            SimpleFillSymbol resultSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Red, outlineSymbol);

            // Create the result polygon graphic and add it to the graphics overlay.
            _resultGraphic = new Graphic(resultPolygon, resultSymbol);
            _polygonsOverlay.Graphics.Add(_resultGraphic);
        }
        private void OperationsPicker_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            // If an operation hasn't been selected, return.
            if (_operationPicker.SelectedItem.ToString() == "")
            {
                return;
            }

            // Remove any currently displayed result.
            _polygonsOverlay.Graphics.Remove(_resultGraphic);

            // Polygon geometry from the input graphics.
            Geometry polygonOne = _graphicOne.Geometry;
            Geometry polygonTwo = _graphicTwo.Geometry;

            // Result polygon for spatial operations.
            Geometry resultPolygon = null;

            // Run the selected spatial operation on the polygon graphics and get the result geometry.
            string selectedOperation = _operationPicker.SelectedItem.ToString();

            switch (selectedOperation)
            {
            case "Union":
                resultPolygon = GeometryEngine.Union(polygonOne, polygonTwo);
                break;

            case "Difference":
                resultPolygon = GeometryEngine.Difference(polygonOne, polygonTwo);
                break;

            case "Symmetric difference":
                resultPolygon = GeometryEngine.SymmetricDifference(polygonOne, polygonTwo);
                break;

            case "Intersection":
                resultPolygon = GeometryEngine.Intersection(polygonOne, polygonTwo);
                break;
            }

            // Create a black outline symbol to use for the result polygon.
            SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Black, 1);

            // Create a solid red fill symbol for the result polygon graphic.
            SimpleFillSymbol resultSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Red, outlineSymbol);

            // Create the result polygon graphic and add it to the graphics overlay.
            _resultGraphic = new Graphic(resultPolygon, resultSymbol);
            _polygonsOverlay.Graphics.Add(_resultGraphic);
        }
Example #4
0
        // Handle the spatial operation selection by performing the operation and showing the result polygon.
        private void SpatialOperationComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            // If an operation hasn't been selected, return.
            if (SpatialOperationComboBox.SelectedItem == null)
            {
                return;
            }

            // Remove any currently displayed result.
            _polygonsOverlay.Graphics.Remove(_resultGraphic);

            // Polygon geometry from the input graphics.
            Geometry polygonOne = _graphicOne.Geometry;
            Geometry polygonTwo = _graphicTwo.Geometry;

            // Result polygon for spatial operations.
            Geometry resultPolygon = null;

            // Run the selected spatial operation on the polygon graphics and get the result geometry.
            string operation = (string)SpatialOperationComboBox.SelectedItem;

            switch (operation)
            {
            case "Union":
                resultPolygon = GeometryEngine.Union(polygonOne, polygonTwo);
                break;

            case "Difference":
                resultPolygon = GeometryEngine.Difference(polygonOne, polygonTwo);
                break;

            case "Symmetric difference":
                resultPolygon = GeometryEngine.SymmetricDifference(polygonOne, polygonTwo);
                break;

            case "Intersection":
                resultPolygon = GeometryEngine.Intersection(polygonOne, polygonTwo);
                break;
            }

            // Create a black outline symbol to use for the result polygon.
            SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Black, 1);

            // Create a solid red fill symbol for the result polygon graphic.
            SimpleFillSymbol resultSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, System.Drawing.Color.Red, outlineSymbol);

            // Create the result polygon graphic and add it to the graphics overlay.
            _resultGraphic = new Graphic(resultPolygon, resultSymbol);
            _polygonsOverlay.Graphics.Add(_resultGraphic);
        }
        void _operationChoiceButton_ValueChanged(object sender, EventArgs e)
        {
            // Remove any currently displayed result.
            _polygonsOverlay.Graphics.Remove(_resultGraphic);

            // Polygon geometry from the input graphics.
            Geometry polygonOne = _graphicOne.Geometry;
            Geometry polygonTwo = _graphicTwo.Geometry;

            // Result polygon for spatial operations.
            Geometry resultPolygon = null;

            // Run the selected spatial operation on the polygon graphics and get the result geometry.
            switch (_operationChoiceButton.SelectedSegment)
            {
            case 0:
                resultPolygon = GeometryEngine.Difference(polygonOne, polygonTwo);
                break;

            case 1:
                resultPolygon = GeometryEngine.Intersection(polygonOne, polygonTwo);
                break;

            case 2:
                resultPolygon = GeometryEngine.SymmetricDifference(polygonOne, polygonTwo);
                break;

            case 3:
                resultPolygon = GeometryEngine.Union(polygonOne, polygonTwo);
                break;
            }

            // Create a black outline symbol to use for the result polygon.
            SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Black, 1);

            // Create a solid red fill symbol for the result polygon graphic.
            SimpleFillSymbol resultSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Red, outlineSymbol);

            // Create the result polygon graphic and add it to the graphics overlay.
            _resultGraphic = new Graphic(resultPolygon, resultSymbol);
            _polygonsOverlay.Graphics.Add(_resultGraphic);
        }