示例#1
0
        // Checks the specified relationship of the two shapes
        private void RelateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (graphicsLayer.Graphics.Count < 2)
                {
                    throw new ApplicationException("No shapes abailable for relationship test");
                }

                var shape1 = graphicsLayer.Graphics[0].Geometry;
                var shape2 = graphicsLayer.Graphics[1].Geometry;

                string relate = comboRelate.Text;
                if (relate.Length < 9)
                {
                    throw new ApplicationException("DE-9IM relate string must be 9 characters");
                }

                relate = relate.Substring(0, 9);

                bool isRelated = GeometryEngine.Relate(shape1, shape2, relate);

                resultPanel.Visibility  = Visibility.Visible;
                resultPanel.Background  = new SolidColorBrush((isRelated) ? Color.FromArgb(0x66, 0, 0xFF, 0) : Color.FromArgb(0x66, 0xFF, 0, 0));
                resultPanel.DataContext = string.Format("Relationship: '{0}' is {1}", relate, isRelated.ToString());
            }
            catch (Exception ex)
            {
                resultPanel.Visibility = Visibility.Collapsed;
                MessageBox.Show("Error: " + ex.Message, "Relationship Sample");
            }
        }
示例#2
0
        // Checks the specified relationship of the two shapes
        private void RelateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_graphicsOverlay.Graphics.Count < 2)
                {
                    throw new Exception("No shapes available for relationship test");
                }

                var shape1 = _graphicsOverlay.Graphics[0].Geometry;
                var shape2 = _graphicsOverlay.Graphics[1].Geometry;

                string relate = txtRelation.Text;
                if (relate.Length < 9)
                {
                    throw new Exception("DE-9IM relate string must be 9 characters");
                }

                relate = relate.Substring(0, 9);

                bool isRelated = GeometryEngine.Relate(shape1, shape2, relate);

                resultPanel.Visibility  = Visibility.Visible;
                resultPanel.Background  = new SolidColorBrush((isRelated) ? Color.FromArgb(0x66, 0, 0xFF, 0) : Color.FromArgb(0x66, 0xFF, 0, 0));
                resultPanel.DataContext = string.Format("Relationship: '{0}' is {1}", relate, isRelated.ToString());
            }
            catch (Exception ex)
            {
                resultPanel.Visibility = Visibility.Collapsed;
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
        /// <summary>
        /// Method to perform the cut operation on the geometry and change attributes
        /// </summary>
        /// <param name="geometry">Line geometry used to perform the cut against in the polygon features
        /// in the active map view.</param>
        /// <returns>If the cut operation was successful.</returns>
        protected Task <bool> ExecuteCut(Geometry geometry)
        {
            if (geometry == null)
            {
                return(Task.FromResult(false));
            }

            // create an edit operation
            EditOperation cutOperation = new EditOperation();

            cutOperation.Name                   = "Cut Elements";
            cutOperation.ProgressMessage        = "Working...";
            cutOperation.CancelMessage          = "Operation canceled.";
            cutOperation.ErrorMessage           = "Error cutting polygons";
            cutOperation.SelectModifiedFeatures = false;
            cutOperation.SelectNewFeatures      = false;

            // create a collection of feature layers that can be edited
            var editableLayers = ActiveMapView.Map.GetLayersAsFlattenedList()
                                 .OfType <FeatureLayer>()
                                 .Where(lyr => lyr.CanEditData() == true).Where(lyr =>
                                                                                lyr.ShapeType == esriGeometryType.esriGeometryPolygon);

            // ensure that there are target layers
            if (editableLayers.Count() == 0)
            {
                return(Task.FromResult(false));
            }

            // initialize a list of ObjectIDs that need to be cut
            var cutOIDs = new List <long>();

            // for each of the layers
            foreach (FeatureLayer editableFeatureLayer in editableLayers)
            {
                // find the features crossed by the sketch geometry
                var rowCursor = editableFeatureLayer.Search(geometry, SpatialRelationship.Crosses);

                // get the feature class associated with the layer
                Table fc = editableFeatureLayer.GetTable();

                // find the field index for the 'Description' attribute
                int descriptionIndex = -1;
                descriptionIndex = fc.GetDefinition().FindField("Description");

                // add the feature IDs into our prepared list
                while (rowCursor.MoveNext())
                {
                    var feature = rowCursor.Current as Feature;
                    if (feature.GetShape() != null)
                    {
                        // we are looking for polygons are completely intersected by the cut line
                        if (GeometryEngine.Relate(geometry, feature.GetShape(), "TT*F*****"))
                        {
                            // add the current feature to the overall list of features to cut
                            cutOIDs.Add(rowCursor.Current.GetObjectID());

                            // adjust the attribute before the cut
                            if (descriptionIndex != -1)
                            {
                                cutOperation.Modify(rowCursor.Current, descriptionIndex, "Pro Sample");
                            }
                        }
                    }
                }
                // add the elements to cut into the edit operation
                cutOperation.Cut(editableFeatureLayer, cutOIDs, geometry);
            }

            //execute the operation
            var operationResult = cutOperation.Execute();

            return(Task.FromResult(operationResult));
        }