protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            if (Module1.Current.SelectedGraphicsLayerTOC == null)
            {
                MessageBox.Show("Select a graphics layer in the TOC", "No graphics layer selected",
                                System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
                return(Task.FromResult(true));
            }
            return(QueuedTask.Run(() => {
                var lineSketched = geometry as Polyline;
                //Create MultipPoints from the sketched line
                var multiPoints = MultipointBuilderEx.CreateMultipoint(lineSketched);
                //specify a symbol
                var point_symbol = SymbolFactory.Instance.ConstructPointSymbol(
                    ColorFactory.Instance.GreenRGB);

                //create a CIMGraphic  using the Multi-points
                var graphic = new CIMMultipointGraphic
                {
                    Symbol = point_symbol.MakeSymbolReference(),
                    Multipoint = multiPoints
                };
                //Add the graphic to the layer
                Module1.Current.SelectedGraphicsLayerTOC.AddElement(graphic);
                return true;
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a single multi-point feature that is comprised of 20 points.
        /// </summary>
        /// <param name="multiPointLayer">Multi-point geometry feature layer used to add the multi-point feature.</param>
        /// <returns></returns>
        private Task ConstructSampleMultiPoints(FeatureLayer multiPointLayer)
        {
            // create a random number generator
            var randomGenerator = new Random();

            // the database and geometry interactions are considered fine-grained and need to be executed on
            // a separate thread
            return(QueuedTask.Run(() =>
            {
                // get the feature class associated with the layer
                var featureClass = multiPointLayer.GetTable() as FeatureClass;
                var featureClassDefinition = featureClass.GetDefinition() as FeatureClassDefinition;

                // store the spatial reference as its own variable
                var spatialReference = featureClassDefinition.GetSpatialReference();

                // define an area of interest. Random points are generated in the allowed
                // confines of the allow extent range
                var areaOfInterest = MapView.Active.Extent;

                // start an edit operation to create new (random) multi-point feature
                var createOperation = new EditOperation()
                {
                    Name = "Generate multipoints"
                };

                // retrieve the class definition of the point feature class
                var classDefinition = featureClass.GetDefinition() as FeatureClassDefinition;

                Multipoint newPoints = null;
                // generate either 2D or 3D geometries
                if (classDefinition.HasZ())
                {
                    // 3D
                    // create a list to hold the 20 coordinates of the multi-point feature
                    IList <Coordinate3D> coordinateList = new List <Coordinate3D>(20);
                    for (int i = 0; i < 20; i++)
                    {
                        coordinateList.Add(randomGenerator.NextCoordinate3D(areaOfInterest));
                    }
                    newPoints = MultipointBuilderEx.CreateMultipoint(coordinateList, classDefinition.GetSpatialReference());
                }
                else
                {
                    // 2D
                    // create a list to hold the 20 coordinates of the multi-point feature
                    IList <Coordinate2D> coordinateList = new List <Coordinate2D>(20);
                    for (int i = 0; i < 20; i++)
                    {
                        coordinateList.Add(randomGenerator.NextCoordinate2D(areaOfInterest));
                    }
                    newPoints = MultipointBuilderEx.CreateMultipoint(coordinateList, classDefinition.GetSpatialReference());
                }
                // create and execute the feature creation operation
                createOperation.Create(multiPointLayer, newPoints);

                return createOperation.ExecuteAsync();
            }));
        }