Esempio n. 1
0
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            if (isDockpaneActive)
            {
                List <MapPoint> points = new List <MapPoint>();
                Task            t      = QueuedTask.Run(() =>
                {
                    foreach (MapPoint point in ((Multipoint)geometry).Points)
                    {
                        MapPoint finalPoint = ArcGIS.Desktop.Mapping.MapView.Active.ClientToMap(new System.Windows.Point(point.X, point.Y));
                        points.Add(finalPoint);
                    }

                    getData(MultipointBuilder.CreateMultipoint(points), GeometryDimension.esriGeometry0Dimension);
                });
                t.Wait();
                ((ParcelListViewModel)FrameworkApplication.DockPaneManager.Find(ParcelListViewModel._dockPaneID)).getView(properties);
                return(QueuedTask.Run(() =>
                {
                    if (parcellayer != null)
                    {
                        parcellayer.Select(this.parcelQuery, SelectionCombinationMethod.New);
                    }
                    return true;
                }));
            }
            return(QueuedTask.Run(() =>
            {
                return false;
            }));
        }
Esempio n. 2
0
        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 = MultipointBuilder.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;
            }));
        }
Esempio n. 3
0
        public void CreateMultiPointGraphics()
        {
            var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault();

            if (graphicsLayer == null)
            {
                return;
            }
            QueuedTask.Run(() =>
            {
                #region Multi-point Graphic Element using CIMGraphic
                //On the QueuedTask
                //Place a multipoint graphic using the mapview extent geometry
                var extent = MapView.Active.Extent;
                //Contract the extent
                var polygonEnv = extent.Expand(-100000, -90000, false);
                //create a polygon using the envelope
                var polygon = PolygonBuilder.CreatePolygon(polygonEnv);
                //Create MultipPoints from the polygon
                var multiPoints = MultipointBuilder.CreateMultipoint(polygon);
                //specify a symbol
                var point_symbol = SymbolFactory.Instance.ConstructPointSymbol(
                    ColorFactory.Instance.GreenRGB);

                //create a CIMGraphic
                var graphic = new CIMMultipointGraphic
                {
                    Symbol     = point_symbol.MakeSymbolReference(),
                    Multipoint = multiPoints
                };
                graphicsLayer.AddElement(graphic);
                #endregion
            });
        }
Esempio n. 4
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 = MultipointBuilder.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 = MultipointBuilder.CreateMultipoint(coordinateList, classDefinition.GetSpatialReference());
                }
                // create and execute the feature creation operation
                createOperation.Create(multiPointLayer, newPoints);

                return createOperation.ExecuteAsync();
            }));
        }
Esempio n. 5
0
        private Task <ArcGIS.Core.Geometry.Geometry> createGeometryFromJson(string json)
        {
            return(QueuedTask.Run(() =>
            {
                ArcGIS.Core.Geometry.Geometry retGeom = null;
                //{"xmin":1,"ymin":2,"xmax":3,"ymax":4,"spatialReference":{"wkid":4326}}
                try
                {
                    retGeom = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, json);

                    switch (retGeom.GeometryType)
                    {
                    case GeometryType.Polygon:
                        break;

                    case GeometryType.Envelope:
                        retGeom = PolygonBuilder.CreatePolygon(retGeom as Envelope);
                        break;

                    case GeometryType.Point:
                        retGeom = MapPointBuilder.CreateMapPoint(retGeom as MapPoint);
                        break;

                    case GeometryType.Multipoint:
                        retGeom = MultipointBuilder.CreateMultipoint(retGeom as Multipoint);
                        break;

                    case GeometryType.Polyline:
                        retGeom = PolylineBuilder.CreatePolyline(retGeom as Polyline);
                        break;

                    default:
                        retGeom = null;
                        break;
                    }
                }
                catch
                {
                    this.message = "I can't create a geometry...";
                }

                return retGeom;
            }));
        }
        /// <summary>
        /// Creates 20 random polygons on the given feature layers. This method must be called on the MCT. Use QueuedTask.Run.
        /// </summary>
        /// <param name="featureLayers">The feature layers to create polygons on.</param>
        /// <returns>
        /// The success of the edit operation creating the polygons.
        /// </returns>
        public static bool GenerateRandomPolygons(this IReadOnlyList <FeatureLayer> featureLayers)
        {
            var randomGenerator = new Random();

            var editOperation = new EditOperation {
                Name = "Generate Polygons"
            };

            for (var i = 0; i < 20; i++)
            {
                var index = 0;

                if (featureLayers.Count >= 3)
                {
                    index = i % 3;
                }
                else if (featureLayers.Count == 2)
                {
                    index = i % 2;
                }

                var featureLayer = featureLayers[index];
                var featureClass = featureLayer.GetFeatureClass();

                var featureDataset = featureClass.GetFeatureDataset();

                var spatialReference = featureDataset?.GetDefinition().GetSpatialReference();

                if (spatialReference == null || spatialReference.IsUnknown)
                {
                    spatialReference = featureClass.GetDefinition().GetSpatialReference();
                }

                if (spatialReference == null || spatialReference.IsUnknown)
                {
                    throw new ArgumentException($"No valid spatial reference for feature class '{featureClass.GetName()}'");
                }

                var extent = featureDataset?.GetExtent();

                if (extent == null || extent.IsEmpty || double.IsNaN(extent.Area) || extent.Area == 0)
                {
                    extent = featureClass.GetExtent();
                }

                if (extent == null || extent.IsEmpty || double.IsNaN(extent.Area) || extent.Area == 0)
                {
                    extent = MapView.Active?.Map.CalculateFullExtent();
                }

                if (extent == null || extent.IsEmpty || double.IsNaN(extent.Area) || extent.Area == 0)
                {
                    throw new ArgumentException($"No valid extent for feature class '{featureClass.GetName()}'");
                }

                var numOfVerts = randomGenerator.Next(3, 8);
                var verts      = new List <MapPoint>();

                for (var j = 0; j < numOfVerts; j++)
                {
                    verts.Add(MapPointBuilder.CreateMapPoint(randomGenerator.NextCoordinate2D(extent), spatialReference));
                }

                var multipoint = MultipointBuilder.CreateMultipoint(verts, spatialReference);
                var polygon    = GeometryEngine.Instance.ConvexHull(multipoint) as Polygon;

                editOperation.Create(featureLayer, polygon);
            }

            var success = editOperation.Execute();

            if (!success)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Edit operation failed!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(success);
        }