Exemple #1
0
        /// <summary>
        /// Create sample polyline feature using the geometries from the point feature layer.
        /// </summary>
        /// <param name="polylineLayer">Polyline geometry feature layer used to add the new features.</param>
        /// <param name="pointLayer">The geometries from the point layer are used as vertices for the new line features.</param>
        /// <returns></returns>
        private Task <bool> constructSamplePolylines(FeatureLayer polylineLayer, FeatureLayer pointLayer)
        {
            // execute the fine grained API calls on the CIM main thread
            return(QueuingTaskFactory.StartNew(() =>
            {
                // get the underlying feature class for each layer
                var polylineFeatureClass = polylineLayer.GetTableAsync().Result as FeatureClass;
                var pointFeatureClass = pointLayer.GetTableAsync().Result as FeatureClass;

                // construct a cursor for all point features, since we want all feature there is no
                // QueryFilter required
                var pointCursor = pointFeatureClass.Search(null, false);

                // retrieve the feature class schema information for the feature classes
                var polylineDefinition = polylineFeatureClass.Definition as FeatureClassDefinition;
                var pointDefinition = pointFeatureClass.Definition as FeatureClassDefinition;

                // initialize a counter variable
                int pointCounter = 0;
                // initialize a list to hold 5 coordinates that are used as vertices for the polyline
                var lineCoordinates = new List <Coordinate>(5);

                // set up the edit operation for the feature creation
                var createOperation = EditingModule.CreateEditOperation();
                createOperation.Name = "Create polylines";

                // loop through the point features
                while (pointCursor.MoveNext())
                {
                    pointCounter++;

                    var pointFeature = pointCursor.Current as Feature;
                    // add the feature point geometry as a coordinate into the vertex list of the line
                    // - ensure that the projection of the point geometry is converted to match the spatial reference of the line
                    lineCoordinates.Add(((MapPoint)GeometryEngine.Project(pointFeature.Shape, polylineDefinition.SpatialReference)).Coordinate);

                    // for every 5 geometries, construct a new polyline and queue a feature create
                    if (pointCounter % 5 == 0)
                    {
                        var newPolyline = new Polyline(lineCoordinates, polylineDefinition.SpatialReference);
                        createOperation.Create(polylineLayer, newPolyline);
                        lineCoordinates = new List <Coordinate>(5);
                    }
                }

                // execute the edit (create) operation
                var t = createOperation.ExecuteAsync().Result;

                // save the edits
                return EditingModule.SaveEditsAsync();
            }));
        }
Exemple #2
0
        /// <summary>
        /// Create random sample points in the extent of the spatial reference
        /// </summary>
        /// <param name="pointLayer">Point geometry feature layer used to the generate the points.</param>
        /// <returns>Task of bool</returns>
        private Task <bool> constructSamplePoints(FeatureLayer pointLayer)
        {
            // create a random number generator
            var randomGenerator = new Random();

            // the database and geometry interactions are considered fine-grained and must be executed on
            // the main CIM thread
            return(QueuingTaskFactory.StartNew(() =>
            {
                // get the feature class associated with the layer
                var featureClass = pointLayer.GetTableAsync().Result as FeatureClass;
                // retrieve the class definition of the point feature class
                var classDefinition = featureClass.Definition as FeatureClassDefinition;

                // store the spatial reference as its own variable
                SpatialReference spatialReference = featureClass.SpatialReference;

                // define an area of interest. Random points are generated in the allowed
                // confines of the allow extent range
                var areaOfInterest = MappingModule.ActiveMapView.GetExtentAsync().Result;

                // start an edit operation to create new (random) point features
                var createOperation = EditingModule.CreateEditOperation();
                createOperation.Name = "Generate points";

                // create 20 new point geometries and queue them for creation
                for (int i = 0; i < 20; i++)
                {
                    MapPoint newMapPoint = null;

                    // generate either 2D or 3D geometries
                    if (classDefinition.HasZ)
                    {
                        newMapPoint = new MapPoint(randomGenerator.NextCoordinate(areaOfInterest, true), spatialReference);
                    }
                    else
                    {
                        newMapPoint = new MapPoint(randomGenerator.NextCoordinate(areaOfInterest, false), spatialReference);
                    }

                    // queue feature creation
                    createOperation.Create(pointLayer, newMapPoint);
                }

                // execute the edit (feature creation) operation
                var t = createOperation.ExecuteAsync().Result;
                return EditingModule.SaveEditsAsync().Result;
            }));
        }
Exemple #3
0
        /// <summary>
        /// Create sample polygon feature using the point geometries from the multi-point feature using the
        /// ConvexHull method provided by the GeometryEngine.
        /// </summary>
        /// <param name="polygonLayer">Polygon geometry feature layer used to add the new feature.</param>
        /// <param name="lineLayer">The polyline feature layer containing the features used to construct the polygon.</param>
        /// <returns></returns>
        private Task <bool> constructSamplePolygon(FeatureLayer polygonLayer, FeatureLayer lineLayer)
        {
            // execute the fine grained API calls on the CIM main thread
            return(QueuingTaskFactory.StartNew(() =>
            {
                // get the underlying feature class for each layer
                var polygonFeatureClass = polygonLayer.GetTableAsync().Result as FeatureClass;
                var lineFeatureClass = lineLayer.GetTableAsync().Result as FeatureClass;

                // construct a cursor to retrieve the line features
                var lineCursor = lineFeatureClass.Search(null, false);

                // retrieve the feature class schema information for the feature class
                var polygonDefinition = polygonFeatureClass.Definition as FeatureClassDefinition;
                var polylineDefinition = lineFeatureClass.Definition as FeatureClassDefinition;

                // set up the edit operation for the feature creation
                var createOperation = EditingModule.CreateEditOperation();
                createOperation.Name = "Create polygons";

                List <CoordinateCollection> combinedCoordinates = new List <CoordinateCollection>();

                while (lineCursor.MoveNext())
                {
                    // retrieve the first feature
                    var lineFeature = lineCursor.Current as Feature;

                    // add the coordinate collection of the current geometry into our overall list of collections
                    var polylineGeometry = lineFeature.Shape as Polyline;
                    combinedCoordinates.AddRange(polylineGeometry.Paths);
                }

                // use the ConvexHull method from the GeometryEngine to construct the polygon geometry
                var newPolygon = Polygon.Clone(GeometryEngine.ConvexHull(new Polyline(combinedCoordinates,
                                                                                      lineFeatureClass.SpatialReference))) as Polygon;

                // queue the polygon creation
                createOperation.Create(polygonLayer, newPolygon);

                // execute the edit (polygon create) operation
                var t = createOperation.ExecuteAsync().Result;

                // save the edits
                return EditingModule.SaveEditsAsync();
            }));
        }