Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new camera offset from the provided camera around an ellipse.
        /// </summary>
        /// <param name="camera">The starting camera.</param>
        /// <param name="ellipse">The ellipse around which the camera will rotate.</param>
        /// <param name="centerPoint">The center point of the ellipse.</param>
        /// <param name="percentAlong">The percentage around the ellipse to create the camera.</param>
        private Camera OffsetCamera(Camera camera, Polyline ellipse, MapPoint centerPoint, double percentAlong)
        {
            camera = CloneCamera(camera);

            var fromPoint = GeometryEngine.MovePointAlongLine(ellipse, percentAlong, true, 0);

            var segment = LineBuilder.CreateLineSegment(new Coordinate2D(centerPoint.X, centerPoint.Y), new Coordinate2D(fromPoint.X, centerPoint.Y), centerPoint.SpatialReference);
            var difX    = GeometryEngine.GeodesicLength(PolylineBuilder.CreatePolyline(segment, segment.SpatialReference));

            if (centerPoint.X - fromPoint.X < 0)
            {
                difX *= -1;
            }

            segment = LineBuilder.CreateLineSegment(new Coordinate2D(centerPoint.X, centerPoint.Y), new Coordinate2D(centerPoint.X, fromPoint.Y), centerPoint.SpatialReference);
            var difY = GeometryEngine.GeodesicLength(PolylineBuilder.CreatePolyline(segment, segment.SpatialReference));

            if (centerPoint.Y - fromPoint.Y < 0)
            {
                difY *= -1;
            }

            var radian  = Math.Atan2(difX, difY);
            var heading = radian * -180 / Math.PI;

            camera.Heading = heading;

            var difZ       = centerPoint.Z - (camera.Z * ((camera.SpatialReference.IsGeographic) ? 1.0 : camera.SpatialReference.Unit.ConversionFactor));
            var hypotenuse = GeometryEngine.GeodesicDistance(fromPoint, centerPoint);

            radian = Math.Atan2(difZ, hypotenuse);
            var pitch = radian * 180 / Math.PI;

            camera.Pitch = pitch;

            if (fromPoint.SpatialReference.Wkid != camera.SpatialReference.Wkid)
            {
                var transformation = ProjectionTransformation.Create(fromPoint.SpatialReference, camera.SpatialReference);
                fromPoint = GeometryEngine.ProjectEx(fromPoint, transformation) as MapPoint;
            }

            camera.X = fromPoint.X;
            camera.Y = fromPoint.Y;
            return(camera);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Divide the first selected feature into equal parts or by map unit distance.
        /// </summary>
        /// <param name="numberOfParts">Number of parts to create.</param>
        /// <param name="value">Value for number or parts or distance.</param>
        /// <returns></returns>
        private static Task DivideLinesAsync(bool numberOfParts, double value)
        {
            //Run on MCT
            return(QueuedTask.Run(() =>
            {
                //get selected feature
                var selectedFeatures = MapView.Active.Map.GetSelection();

                //get the layer of the selected feature
                var featLayer = selectedFeatures.Keys.First() as FeatureLayer;
                var oid = selectedFeatures.Values.First().First();

                var feature = featLayer.Inspect(oid);

                //get geometry and length
                var origPolyLine = feature.Shape as Polyline;
                var origLength = GeometryEngine.Length(origPolyLine);

                //List of mappoint geometries for the split
                var splitPoints = new List <MapPoint>();

                var enteredValue = (numberOfParts) ? origLength / value : value;
                var splitAtDistance = 0 + enteredValue;

                while (splitAtDistance < origLength)
                {
                    //create a mapPoint at splitDistance and add to splitpoint list
                    splitPoints.Add(GeometryEngine.MovePointAlongLine(origPolyLine, splitAtDistance, false, 0));
                    splitAtDistance += enteredValue;
                }

                //create and execute the edit operation
                var op = new EditOperation();
                op.Name = "Divide Lines";
                op.SelectModifiedFeatures = false;
                op.SelectNewFeatures = false;
                op.SplitAtPoints(featLayer, oid, splitPoints);
                op.Execute();

                //clear selection
                //MapView.Active.Map.SetSelection(null);
                featLayer.ClearSelection();
            }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Divide the first selected feature into equal parts or by map unit distance.
        /// </summary>
        /// <param name="numberOfParts">Number of parts to create.</param>
        /// <param name="value">Value for number or parts or distance.</param>
        /// <returns></returns>
        private static Task DivideLinesAsync(bool numberOfParts, double value)
        {
            //Run on MCT
            return(QueuedTask.Run(() =>
            {
                //get selected feature
                var selectedFeatures = MapView.Active.Map.GetSelection();

                //get the layer of the selected feature
                var featLayer = selectedFeatures.Keys.First() as FeatureLayer;
                var oid = selectedFeatures.Values.First().First();

                var feature = featLayer.Inspect(oid);

                //get geometry and length
                var origPolyLine = feature.Shape as Polyline;
                var origLength = GeometryEngine.Length(origPolyLine);

                string xml = origPolyLine.ToXML();

                //List of mappoint geometries for the split
                var splitPoints = new List <MapPoint>();

                var enteredValue = (numberOfParts) ? origLength / value : value;
                var splitAtDistance = 0 + enteredValue;

                while (splitAtDistance < origLength)
                {
                    //create a mapPoint at splitDistance and add to splitpoint list
                    MapPoint pt = null;
                    try
                    {
                        pt = GeometryEngine.MovePointAlongLine(origPolyLine, splitAtDistance, false, 0, GeometryEngine.SegmentExtension.NoExtension);
                    }
                    catch (GeometryObjectException)
                    {
                        // line is an arc?
                    }

                    if (pt != null)
                    {
                        splitPoints.Add(pt);
                    }
                    splitAtDistance += enteredValue;
                }

                if (splitPoints.Count == 0)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Divide lines was unable to process your selected line. Please select another.", "Divide Lines");
                    return;
                }
                //create and execute the edit operation
                var op = new EditOperation();
                op.Name = "Divide Lines";
                op.SelectModifiedFeatures = false;
                op.SelectNewFeatures = false;
                op.SplitAtPoints(featLayer, oid, splitPoints);
                op.Execute();

                //clear selection
                featLayer.ClearSelection();
            }));
        }