Пример #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);
        }
Пример #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);
        }
Пример #6
0
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            outputGraphicsLayer.Graphics.Clear();

            InstructionsTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible;

            InstructionsTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible;
            StartButton.Visibility           = Windows.UI.Xaml.Visibility.Collapsed;
            ResetButton.Visibility           = Windows.UI.Xaml.Visibility.Visible;

            // wait for user to draw difference polygon
            Polygon inputDifferencePolygonGeometry = await mapView1.Editor.RequestShapeAsync(DrawShape.Polygon) as Polygon;

            // Take account of WrapAround
            Polygon polygon = GeometryEngine.NormalizeCentralMeridian(inputDifferencePolygonGeometry) as Polygon;

            // Get the user input geometry and add it to the map
            drawGraphicsLayer.Graphics.Clear();
            drawGraphicsLayer.Graphics.Add(new Graphic {
                Geometry = inputDifferencePolygonGeometry
            });

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

            //Generate the difference geometries
            var inputGeometries1 = inputGraphicsLayer.Graphics.Select(x => x.Geometry).ToList();
            var inputGeometries2 = new List <Geometry> {
                simplifyGeometry
            };
            var differenceOutputGeometries = GeometryEngine.Difference(inputGeometries1, inputGeometries2);

            //Add the difference geometries to the amp
            foreach (var geom in differenceOutputGeometries)
            {
                outputGraphicsLayer.Graphics.Add(new Graphic {
                    Geometry = geom
                });
            }

            ResetButton.IsEnabled = true;
        }
Пример #7
0
        private GraphicsLayer Difference(GraphicsLayer firstGrLayer, GraphicsLayer secondGrLayer, Color color)
        {
            var differenceGrLayer = new GraphicsLayer()
            {
                ID          = firstGrLayer.ID + secondGrLayer.ID + "Difference",
                DisplayName = firstGrLayer.DisplayName + secondGrLayer.DisplayName + "Difference"
            };

            MyMapView.Map.Layers.Add(differenceGrLayer);
            AddItemToListBox(differenceGrLayer.DisplayName);
            var    geometries1        = firstGrLayer.Graphics.Select(graphic => graphic.Geometry);
            var    unionGeometry1     = GeometryEngine.Union(geometries1);
            var    geometries2        = secondGrLayer.Graphics.Select(graphic => graphic.Geometry);
            var    unionGeometry2     = GeometryEngine.Union(geometries2);
            var    differenceGeometry = GeometryEngine.Difference(unionGeometry1, unionGeometry2);
            Symbol bufferSymbol       = GetGraphicStyle(color);

            differenceGrLayer.Graphics.Add(new Graphic(differenceGeometry, bufferSymbol));
            return(differenceGrLayer);
        }
Пример #8
0
        public void CreateSmallCircles()
        {
            var mapOL = new GraphicsOverlay();

            mapOL.SceneProperties.SurfacePlacement = SurfacePlacement.Draped;

            var sceneOL = new GraphicsOverlay();

            sceneOL.SceneProperties.SurfacePlacement = SurfacePlacement.Draped;

            double lat      = -180;
            double lon      = 0;
            double radiuskm = 500;
            Color  colorRed = Colors.Red;

            colorRed.A = 180;
            int zOrder = 1;

            var polyA1  = CreateCirclePolygon(lat, lon, radiuskm);
            var polyA2  = CreateCirclePolygon(lat, lon, radiuskm / 2);
            var polyA12 = GeometryEngine.Difference(polyA1, polyA2);

            mapOL.Graphics.Add(CreateGraphic(polyA12, colorRed, zOrder, false)[0]);
            _mapgraphicsOverlays.Clear();
            _mapgraphicsOverlays.Add(mapOL);

            var polyB1  = CreateCirclePolygon(lat, lon, radiuskm);
            var polyB2  = CreateCirclePolygon(lat, lon, radiuskm / 2);
            var polyB12 = GeometryEngine.Difference(polyB1, polyB2);

            sceneOL.Graphics.Add(CreateGraphic(polyB12, colorRed, zOrder, false)[0]);
            _scenegraphicsOverlays.Clear();
            _scenegraphicsOverlays.Add(sceneOL);

            OnPropertyChanged("MapGraphicsOverlays");
            OnPropertyChanged("SceneGraphicsOverlays");
        }
Пример #9
0
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            outputGraphicsLayer.Graphics.Clear();

            InstructionsTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible;

            InstructionsTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible;
            StartButton.Visibility           = Windows.UI.Xaml.Visibility.Collapsed;
            ResetButton.Visibility           = Windows.UI.Xaml.Visibility.Visible;

            //Get the user's input geometry and add it to the map
            inputDifferencePolygonGeometry = (await mapView1.Editor.RequestShapeAsync(DrawShape.Polygon)) as Polygon;
            drawGraphicsLayer.Graphics.Clear();
            drawGraphicsLayer.Graphics.Add(new Graphic {
                Geometry = inputDifferencePolygonGeometry
            });

            //Simplify the input geometry
            var simplifyGeometry = GeometryEngine.Simplify(inputDifferencePolygonGeometry);

            //Generate the difference geometries
            var inputGeometries1 = inputGraphicsLayer.Graphics.Select(x => x.Geometry).ToList();
            var inputGeometries2 = new List <Geometry> {
                simplifyGeometry
            };
            var differenceOutputGeometries = GeometryEngine.Difference(inputGeometries1, inputGeometries2);

            //Add the difference geometries to the amp
            foreach (var geom in differenceOutputGeometries)
            {
                outputGraphicsLayer.Graphics.Add(new Graphic {
                    Geometry = geom
                });
            }

            ResetButton.IsEnabled = true;
        }
Пример #10
0
        private Task <bool> createFunnyGarden(Geometry geometry)
        {
            if (geometry == null)
            {
                return(Task.FromResult(false));
            }

            // get the point layer from the active map
            var pointLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>()
                             .Where(lyr => lyr.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPoint).FirstOrDefault();

            if (pointLayer == null)
            {
                return(Task.FromResult(false));
            }

            // get the polygon layer from the active map
            var polygonLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>()
                               .Where(lyr => lyr.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPolygon).FirstOrDefault();

            if (polygonLayer == null)
            {
                return(Task.FromResult(false));
            }

            // Create an edit operation
            var createOperation = new EditOperation();

            createOperation.Name = string.Format("Create green");

            // we'll use the sketch geometry to create a spatial filter
            SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter();

            spatialQueryFilter.FilterGeometry      = geometry;
            spatialQueryFilter.SpatialRelationship = SpatialRelationship.Contains;

            // retrieve the point features that are inside the sketch geometry
            var searchCursor = pointLayer.Search(spatialQueryFilter);

            // Construct a polygon placeholder for the point buffers
            var treeBuffers = PolygonBuilder.CreatePolygon(geometry.SpatialReference);

            // TODO
            // 1. for each point geometry
            //     2. buffer the geometry  (Hint : use the MapView.Active.Extent.Width/50 as the buffer distance)
            //     3. union this result with the existing treeBuffers
            // 4. subtract the collection of buffers from the sketch geometry
            // HINT: use the GeometryEngine to buffer, union and subtract (difference) the geometries
            // Polygon greenGeometry = null;

            // for each found feature
            while (searchCursor.MoveNext())
            {
                // retrieve the geometry
                var treeFeature = searchCursor.Current as Feature;
                var treePoint   = treeFeature.GetShape() as MapPoint;

                // buffer the the location
                var treeBuffer = GeometryEngine.Buffer(treePoint, MapView.Active.Extent.Width / 50);

                // and union the new buffer to the existing buffer polygons
                treeBuffers = GeometryEngine.Union(treeBuffer, treeBuffers) as Polygon;
            }

            // ensure the sketch geometry is simple
            if (!GeometryEngine.IsSimpleAsFeature(geometry, true))
            {
                geometry = GeometryEngine.SimplifyAsFeature(geometry);
            }

            // construct the difference geometry between the sketch geometry and the buffered point polygons
            var greenGeometry = GeometryEngine.Difference(geometry, treeBuffers);

            // cue the create
            createOperation.Create(polygonLayer, greenGeometry);

            // execute the operation
            return(createOperation.ExecuteAsync());
        }