private void ConstructGeoCircle()
        {
            if (Point1 == null || double.IsNaN(Distance))
            {
                return;
            }

            var param = new GeodesicEllipseParameter();

            param.Center          = new Coordinate2D(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polyline;
            param.SemiAxis1Length = Distance;
            param.SemiAxis2Length = Distance;
            param.VertexCount     = VertexCount;

            maxDistance = Math.Max(maxDistance, Distance);

            var geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

            // Hold onto the attributes in case user saves graphics to file later
            RangeAttributes rangeAttributes = new RangeAttributes()
            {
                mapPoint     = Point1, numRings = NumberOfRings,
                distance     = Distance,
                centerx      = Point1.X, centery = Point1.Y,
                distanceunit = LineDistanceType.ToString(), ringorradial = "Ring"
            };

            CreateRangeRingOrRadialFeature(geom, rangeAttributes);
        }
        private void UpdateFeedbackWithGeoCircle()
        {
            if (Point1 == null || double.IsNaN(Distance) || Distance <= 0.0)
            {
                return;
            }

            var param = new GeodesicEllipseParameter();

            param.Center          = new Coordinate2D(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polyline;
            param.SemiAxis1Length = Distance;
            param.SemiAxis2Length = Distance;
            param.VertexCount     = VertexCount;

            var geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

            ClearTempGraphics();

            // Hold onto the attributes in case user saves graphics to file later
            RangeAttributes rangeAttributes = new RangeAttributes()
            {
                mapPoint     = Point1,
                numRings     = NumberOfRings, distance = Distance,
                centerx      = Point1.X, centery = Point1.Y,
                distanceunit = LineDistanceType.ToString()
            };

            AddGraphicToMap(Point1, ColorFactory.Instance.GreenRGB, null, true, 5.0);
            AddGraphicToMap(geom, ColorFactory.Instance.GreyRGB, rangeAttributes, true);
        }
Example #3
0
        private Geometry CreateRangeRings(double radius)
        {
            Geometry geom  = null;
            var      param = new GeodesicEllipseParameter();

            param.Center          = new Coordinate2D(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polyline;
            param.SemiAxis1Length = radius;
            param.SemiAxis2Length = radius;
            param.VertexCount     = VertexCount;

            geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);
            var nameConverter = new EnumToFriendlyNameConverter();
            var displayValue  = nameConverter.Convert(LineDistanceType, typeof(string), new object(), CultureInfo.CurrentCulture);
            // Hold onto the attributes in case user saves graphics to file later
            RangeAttributes rangeAttributes = new RangeAttributes()
            {
                mapPoint     = Point1,
                numRings     = numberOfRings,
                distance     = radius,
                centerx      = Point1.X,
                centery      = Point1.Y,
                distanceunit = displayValue.ToString(),
                ringorradial = "Ring"
            };

            CreateRangeRingOrRadialFeature(geom, rangeAttributes);

            return(geom);
        }
        /// <summary>
        /// Method used to draw the rings at the desired interval
        /// Rings are constructed as geodetic circles
        /// </summary>
        private Geometry DrawRings()
        {
            if (Point1 == null || double.IsNaN(Distance))
            {
                return(null);
            }

            double radius = 0.0;

            try
            {
                Geometry geom = null;
                for (int x = 0; x < numberOfRings; x++)
                {
                    // set the current radius
                    radius += Distance;

                    var param = new GeodesicEllipseParameter();

                    param.Center          = new Coordinate2D(Point1);
                    param.AxisDirection   = 0.0;
                    param.LinearUnit      = GetLinearUnit(LineDistanceType);
                    param.OutGeometryType = GeometryType.Polyline;
                    param.SemiAxis1Length = radius;
                    param.SemiAxis2Length = radius;
                    param.VertexCount     = VertexCount;

                    geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

                    // Hold onto the attributes in case user saves graphics to file later
                    RangeAttributes rangeAttributes = new RangeAttributes()
                    {
                        mapPoint     = Point1, numRings = numberOfRings, distance = radius,
                        centerx      = Point1.X, centery = Point1.Y,
                        distanceunit = LineDistanceType.ToString(), ringorradial = "Ring"
                    };

                    CreateRangeRingOrRadialFeature(geom, rangeAttributes);
                }

                return(geom);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                return(null);
            }
        }
Example #5
0
        private void UpdateFeedbackWithEllipse(bool HasMinorAxis = true)
        {
            if (!HasPoint1 || double.IsNaN(MajorAxisDistance) || double.IsNaN(MinorAxisDistance))
            {
                return;
            }

            var minorAxis = MinorAxisDistance;

            if (!HasMinorAxis || minorAxis == 0.0)
            {
                minorAxis = MajorAxisDistance;
            }

            if (minorAxis > MajorAxisDistance)
            {
                minorAxis = MajorAxisDistance;
            }
            try
            {
                var param = new GeodesicEllipseParameter();

                param.Center          = new Coordinate2D(Point1);
                param.AxisDirection   = GetRadiansFrom360Degrees(GetAzimuthAsDegrees());
                param.LinearUnit      = GetLinearUnit(LineDistanceType);
                param.OutGeometryType = GeometryType.Polyline;
                param.SemiAxis1Length = MajorAxisDistance;
                param.SemiAxis2Length = minorAxis;
                param.VertexCount     = VertexCount;

                var geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

                ClearTempGraphics();

                // Hold onto the attributes in case user saves graphics to file later
                //EllipseAttributes ellipseAttributes = new EllipseAttributes(Point1, minorAxis, majorAxisDistance, para.AxisDirection);

                // Point
                AddGraphicToMap(Point1, ColorFactory.Instance.GreenRGB, null, true, 5.0);
                // Ellipse
                AddGraphicToMap(geom, ColorFactory.Instance.GreyRGB, null, true);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Example #6
0
        private Geometry DrawEllipse()
        {
            if (Point1 == null || double.IsNaN(MajorAxisDistance) || double.IsNaN(MinorAxisDistance))
            {
                return(null);
            }

            try
            {
                var nameConverter = new EnumToFriendlyNameConverter();
                var param         = new GeodesicEllipseParameter();

                param.Center          = new Coordinate2D(Point1);
                param.AxisDirection   = GetRadiansFrom360Degrees(GetAzimuthAsDegrees());
                param.LinearUnit      = GetLinearUnit(LineDistanceType);
                param.OutGeometryType = GeometryType.Polygon;
                param.SemiAxis1Length = MajorAxisDistance;
                param.SemiAxis2Length = MinorAxisDistance;
                param.VertexCount     = VertexCount;

                var geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

                // Hold onto the attributes in case user saves graphics to file later
                var displayValue = nameConverter.Convert(LineDistanceType, typeof(string), new object(), CultureInfo.CurrentCulture);

                EllipseAttributes ellipseAttributes = new EllipseAttributes()
                {
                    mapPoint     = Point1,
                    minorAxis    = MinorAxisDistance * 2, // TRICKY: Label/Attribute always shows the "full" value
                    majorAxis    = MajorAxisDistance * 2,
                    angle        = Azimuth,
                    angleunit    = AzimuthType.ToString(),
                    centerx      = Point1.X,
                    centery      = Point1.Y,
                    distanceunit = displayValue.ToString()
                };

                CreateEllipseFeature(geom, ellipseAttributes);

                return((Geometry)geom);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Example #7
0
        private Geometry DrawEllipse()
        {
            if (Point1 == null || double.IsNaN(MajorAxisDistance) || double.IsNaN(MinorAxisDistance))
            {
                return(null);
            }

            try
            {
                var param = new GeodesicEllipseParameter();

                param.Center          = new Coordinate2D(Point1);
                param.AxisDirection   = GetRadiansFrom360Degrees(GetAzimuthAsDegrees());
                param.LinearUnit      = GetLinearUnit(LineDistanceType);
                param.OutGeometryType = GeometryType.Polygon;
                param.SemiAxis1Length = MajorAxisDistance;
                param.SemiAxis2Length = MinorAxisDistance;
                param.VertexCount     = VertexCount;

                var geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

                // Hold onto the attributes in case user saves graphics to file later
                EllipseAttributes ellipseAttributes = new EllipseAttributes()
                {
                    mapPoint  = Point1, minorAxis = MinorAxisDistance,
                    majorAxis = MajorAxisDistance, angle = Azimuth,
                    angleunit = AzimuthType.ToString(), centerx = Point1.X,
                    centery   = Point1.Y, distanceunit = LineDistanceType.ToString()
                };

                CreateEllipseFeature(geom, ellipseAttributes);

                return((Geometry)geom);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Example #8
0
        /// <summary>
        /// Create geodetic circle
        /// </summary>
        private Geometry CreateCircle(bool isFeedback)
        {
            if (Point1 == null || double.IsNaN(Distance) || Distance <= 0.0)
            {
                return(null);
            }
            var nameConverter = new EnumToFriendlyNameConverter();
            var param         = new GeodesicEllipseParameter();

            param.Center          = new Coordinate2D(Point1);
            param.AxisDirection   = 0.0;
            param.LinearUnit      = GetLinearUnit(LineDistanceType);
            param.OutGeometryType = GeometryType.Polygon;
            if (isFeedback)
            {
                param.OutGeometryType = GeometryType.Polyline;
            }
            param.SemiAxis1Length = Distance;
            param.SemiAxis2Length = Distance;
            param.VertexCount     = VertexCount;

            var geom = GeometryEngine.Instance.GeodesicEllipse(param, MapView.Active.Map.SpatialReference);

            CIMColor color = new CIMRGBColor()
            {
                R = 255, B = 0, G = 0, Alpha = 25
            };

            if (isFeedback)
            {
                color = ColorFactory.Instance.GreyRGB;
                ClearTempGraphics();
                AddGraphicToMap(Point1, ColorFactory.Instance.GreenRGB, null, true, 5.0);
            }

            // Hold onto the attributes in case user saves graphics to file later
            //CircleAttributes circleAttributes = new CircleAttributes(Point1, Distance, CircleType);
            double        dist = 0.0;
            DistanceTypes distunit;

            if (CircleType == CircleFromTypes.Diameter)
            {
                dist = Distance * 2;
            }
            else
            {
                dist = Distance;
            }

            if (IsDistanceCalcExpanded)
            {
                dist     = ConvertFromTo(LineDistanceType, RateUnit, Distance);
                distunit = RateUnit;
            }
            else
            {
                distunit = LineDistanceType;
            }

            var displayValue = nameConverter.Convert(distunit, typeof(string), new object(), CultureInfo.CurrentCulture);
            CircleAttributes circleAttributes = new CircleAttributes()
            {
                mapPoint = Point1, distance = dist, circleFromTypes = CircleType, circletype = CircleType.ToString(), centerx = Point1.X, centery = Point1.Y, distanceunit = displayValue.ToString()
            };

            if (isFeedback)
            {
                AddGraphicToMap(geom, color, (ProGraphicAttributes)circleAttributes, IsTempGraphic: isFeedback);
            }
            else
            {
                CreateCircleFeature(geom, circleAttributes);
            }

            return((Geometry)geom);
        }
Example #9
0
 public async static void CreatePolygonExpantion()
 {
     await QueuedTask.Run(() =>
     {
         using (Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(GeoDataTool.DefaultProject.DefaultGeodatabasePath))))
         {
             gdb.ApplyEdits(() =>
             {
                 using (FeatureClass fcStaticObstructPolygon = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_StaticObstructPolygon))
                 {
                     FeatureClassDefinition fcdStaticObstructPoint = gdb.GetDefinition <FeatureClassDefinition>(ConstDefintion.ConstFeatureClass_StaticObstructPolygon);
                     FeatureClass fcSOPBuffer    = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_SOPBuffer);
                     FeatureClass fc_SOPIDEPoint = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_SOPIDEPoint);
                     fc_SOPIDEPoint.DeleteRows(new QueryFilter()
                     {
                         WhereClause = "OBJECTID >= 1"
                     });
                     using (RowCursor rc = fcStaticObstructPolygon.Search(null, false))
                     {
                         while (rc.MoveNext())
                         {
                             using (Feature f = rc.Current as Feature)
                             {
                                 int affectDis       = Convert.ToInt32(f[ConstDefintion.ConstFieldName_AffectDis]);
                                 double affectDegree = (double)f[ConstDefintion.ConstFieldName_AffectDegree];
                                 MapPoint p          = f[fcdStaticObstructPoint.GetShapeField()] as MapPoint;
                                 GeodesicEllipseParameter geodesic = new GeodesicEllipseParameter()
                                 {
                                     Center          = p.Coordinate2D,
                                     SemiAxis1Length = affectDis,
                                     SemiAxis2Length = affectDis,
                                     LinearUnit      = LinearUnit.Meters,
                                     OutGeometryType = GeometryType.Polygon,
                                     AxisDirection   = 0,
                                     VertexCount     = 800
                                 };
                                 Geometry circle = GeometryEngine.Instance.GeodesicEllipse(geodesic, SpatialReferenceBuilder.CreateSpatialReference(3857));
                                 using (RowBuffer rowBuffer = fcSOPBuffer.CreateRowBuffer())
                                 {
                                     // Either the field index or the field name can be used in the indexer.
                                     rowBuffer[ConstDefintion.ConstFieldName_AffectDegree] = 0;
                                     rowBuffer["Shape"] = circle;
                                     using (Feature feature = fcSOPBuffer.CreateRow(rowBuffer))
                                     {
                                         feature.Store();
                                     }
                                 }
                                 using (RowBuffer rowBuffer = fc_SOPIDEPoint.CreateRowBuffer())
                                 {
                                     // Either the field index or the field name can be used in the indexer.
                                     rowBuffer[ConstDefintion.ConstFieldName_AffectDegree] = affectDegree;
                                     rowBuffer["Shape"] = p;
                                     using (Feature feature = fc_SOPIDEPoint.CreateRow(rowBuffer))
                                     {
                                         feature.Store();
                                     }
                                 }
                             }
                         }
                     }
                 }
             });
         }
     });
 }
        public static async Task GenerateIDEKeyPointAsync(string fcName)
        {
            //1.
            await QueuedTask.Run(() =>
            {
                using (Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(GeoDataTool.DefaultProject.DefaultGeodatabasePath))))
                {
                    gdb.ApplyEdits(() =>
                    {
                        using (FeatureClass fcStaticObstructPoint = gdb.OpenDataset <FeatureClass>(fcName))
                        {
                            FeatureClassDefinition fcdStaticObstructPoint = gdb.GetDefinition <FeatureClassDefinition>(fcName);
                            FeatureClass fcSOPBuffer    = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_SOPBuffer);
                            FeatureClass fc_SOPIDEPoint = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_SOPIDEPoint);
                            fc_SOPIDEPoint.DeleteRows(new QueryFilter()
                            {
                                WhereClause = "OBJECTID >= 1"
                            });
                            using (RowCursor rc = fcStaticObstructPoint.Search(null, false))
                            {
                                while (rc.MoveNext())
                                {
                                    using (Feature f = rc.Current as Feature)
                                    {
                                        int affectDis       = Convert.ToInt32(f[ConstDefintion.ConstFieldName_AffectDis]);
                                        double affectDegree = (double)f[ConstDefintion.ConstFieldName_AffectDegree];
                                        MapPoint p          = f[fcdStaticObstructPoint.GetShapeField()] as MapPoint;
                                        GeodesicEllipseParameter geodesic = new GeodesicEllipseParameter()
                                        {
                                            Center          = p.Coordinate2D,
                                            SemiAxis1Length = affectDis,
                                            SemiAxis2Length = affectDis,
                                            LinearUnit      = LinearUnit.Meters,
                                            OutGeometryType = GeometryType.Polygon,
                                            AxisDirection   = 0,
                                            VertexCount     = 800
                                        };
                                        Geometry circle = GeometryEngine.Instance.GeodesicEllipse(geodesic, SpatialReferenceBuilder.CreateSpatialReference(3857));
                                        using (RowBuffer rowBuffer = fcSOPBuffer.CreateRowBuffer())
                                        {
                                            // Either the field index or the field name can be used in the indexer.
                                            rowBuffer[ConstDefintion.ConstFieldName_AffectDegree] = 0;
                                            rowBuffer["Shape"] = circle;
                                            using (Feature feature = fcSOPBuffer.CreateRow(rowBuffer))
                                            {
                                                feature.Store();
                                            }
                                        }
                                        using (RowBuffer rowBuffer = fc_SOPIDEPoint.CreateRowBuffer())
                                        {
                                            // Either the field index or the field name can be used in the indexer.
                                            rowBuffer[ConstDefintion.ConstFieldName_AffectDegree] = affectDegree;
                                            rowBuffer["Shape"] = p;
                                            using (Feature feature = fc_SOPIDEPoint.CreateRow(rowBuffer))
                                            {
                                                feature.Store();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    });
                }
            });

            //2.运行要素边缘转点
            string inpath = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + ConstDefintion.ConstFeatureClass_SOPBufferPoint;
            var    args   = Geoprocessing.MakeValueArray(inpath);
            var    result = await Geoprocessing.ExecuteToolAsync("Delete_management", args, null, null, null);

            string inpath1 = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + ConstDefintion.ConstFeatureClass_SOPBuffer;
            string outpath = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + ConstDefintion.ConstFeatureClass_SOPBufferPoint;
            var    args1   = Geoprocessing.MakeValueArray(inpath1, outpath, "ALL");
            var    result1 = await Geoprocessing.ExecuteToolAsync("FeatureVerticesToPoints_management", args1, null, null, null);

            //3.
            await QueuedTask.Run(() =>
            {
                using (Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(GeoDataTool.DefaultProject.DefaultGeodatabasePath))))
                {
                    gdb.ApplyEdits(() =>
                    {
                        FeatureClass SOPIDEPoint    = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_SOPIDEPoint);
                        FeatureClass SOPBufferPoint = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_SOPBufferPoint);
                        FeatureClassDefinition SOPIDEPointDefinition = gdb.GetDefinition <FeatureClassDefinition>(ConstDefintion.ConstFeatureClass_SOPIDEPoint);
                        using (RowCursor rowCursor = SOPBufferPoint.Search(null, false))
                        {
                            while (rowCursor.MoveNext())
                            {
                                using (Feature f = rowCursor.Current as Feature)
                                {
                                    using (RowBuffer rowBuffer = SOPIDEPoint.CreateRowBuffer())
                                    {
                                        rowBuffer[ConstDefintion.ConstFieldName_AffectDegree] = 0;
                                        rowBuffer[SOPIDEPointDefinition.GetShapeField()]      = f.GetShape();
                                        using (Feature feature = SOPIDEPoint.CreateRow(rowBuffer))
                                        {
                                            feature.Store();
                                        }
                                    }
                                }
                            }
                        }
                    });
                }
            });
        }
        /// <summary>
        /// Create keyframes centered around a point.
        /// </summary>
        /// <param name="point">The center point around which the keyframes are created.</param>
        internal Task CreateKeyframesAroundPoint(MapPoint point)
        {
            return(QueuedTask.Run(() =>
            {
                var mapView = MapView.Active;
                var degrees = Animation.Settings.Degrees;
                if (mapView == null || degrees == 0)
                {
                    return;
                }

                //Get the camera track from the active map's animation.
                //There will always be only one camera track in the animation.
                var cameraTrack = mapView.Map.Animation.Tracks.OfType <CameraTrack>().First();
                var camera = mapView.Camera;

                //Calculate the number of keys to create.
                var keyEvery = (degrees < 0) ? -10 : 10; //10 degrees
                var numOfKeys = Math.Floor(degrees / keyEvery);
                var remainder = degrees % keyEvery;

                //To maintain a constant speed we need to divide the total time we want the animation to take by the number of degrees of rotation.
                var duration = Animation.Settings.Duration;
                double timeInterval = duration / Math.Abs(degrees);
                double currentTimeSeconds = GetInsertTime(mapView.Map.Animation);

                //Get the distance from the current location to the point we want to rotate around to get the radius.
                var cameraPoint = MapPointBuilder.CreateMapPoint(camera.X, camera.Y, camera.SpatialReference);
                var radius = GeometryEngine.Instance.GeodesicDistance(cameraPoint, point);
                var radian = ((camera.Heading - 90) / 180.0) * Math.PI;

                //If the spatial reference of the point is projected and the unit is not in meters we need to convert the Z values to meters.
                if (!point.SpatialReference.IsGeographic && point.SpatialReference.Unit.ConversionFactor != 1.0)
                {
                    point = MapPointBuilder.CreateMapPoint(point.X, point.Y,
                                                           point.Z * point.SpatialReference.Unit.ConversionFactor, point.SpatialReference);
                }

                //For all geodesic calculations we will use WGS84 so we will project the point if it is not already.
                if (point.SpatialReference.Wkid != SpatialReferences.WGS84.Wkid)
                {
                    var transformation = ProjectionTransformation.Create(point.SpatialReference, SpatialReferences.WGS84);
                    point = GeometryEngine.Instance.ProjectEx(point, transformation) as MapPoint;
                }

                //Create an ellipse around the center point.
                var parameter = new GeodesicEllipseParameter()
                {
                    Center = point.Coordinate2D,
                    SemiAxis1Length = radius,
                    SemiAxis2Length = radius,
                    AxisDirection = radian,
                    LinearUnit = LinearUnit.Meters,
                    OutGeometryType = GeometryType.Polyline,
                    VertexCount = 36
                };
                var ellipse = GeometryEngine.Instance.GeodesicEllipse(parameter, point.SpatialReference) as Polyline;

                //For each key we will progressively rotate around the ellipse and calculate the camera position at each.
                for (int i = 0; i <= numOfKeys; i++)
                {
                    var percentAlong = ((Math.Abs(keyEvery) * i) % 360) / 360.0;
                    if (keyEvery > 0)
                    {
                        percentAlong = 1 - percentAlong;
                    }

                    //Get the camera at the position around the ellipse.
                    camera = OffsetCamera(camera, ellipse, point, percentAlong);

                    //Increment the time by the amount of time per key.
                    if (i != 0)
                    {
                        currentTimeSeconds += (timeInterval * Math.Abs(keyEvery));
                    }

                    //Create a new keyframe for the camera.
                    cameraTrack.CreateKeyframe(camera, TimeSpan.FromSeconds(currentTimeSeconds), AnimationTransition.FixedArc);
                }

                //For any degree rotation left over create a keyframe. For example 155, would have a keyframe every 10 degrees and then one for the final 5 degrees.
                if (remainder != 0.0)
                {
                    var percentAlong = ((Math.Abs(keyEvery) * numOfKeys + Math.Abs(remainder)) % 360) / 360.0;
                    if (remainder > 0)
                    {
                        percentAlong = 1 - percentAlong;
                    }

                    OffsetCamera(camera, ellipse, point, percentAlong);

                    //Increment the time and create the keyframe.
                    currentTimeSeconds += (timeInterval * Math.Abs(remainder));
                    cameraTrack.CreateKeyframe(camera, TimeSpan.FromSeconds(currentTimeSeconds), AnimationTransition.FixedArc);
                }
            }));
        }
Example #12
0
        private static void CreateAllDomain(FeatureClass fc_targetShip)
        {
            //创建船周围的船舶领域
            using (Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(GeoDataTool.DefaultProject.DefaultGeodatabasePath))))
            {
                gdb.ApplyEdits(() =>
                {
                    //置空原船舶领域图层
                    FeatureClass shipDomain = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_ShipDomianEllipse);
                    FeatureClassDefinition shipDomainDefinition = gdb.GetDefinition <FeatureClassDefinition>(ConstDefintion.ConstFeatureClass_ShipDomianEllipse);
                    shipDomain.DeleteRows(new QueryFilter()
                    {
                        WhereClause = "OBJECTID >= 1"
                    });

                    using (RowCursor rowCursor = fc_targetShip.Search(null, false))
                    {
                        while (rowCursor.MoveNext())
                        {
                            using (Row row = rowCursor.Current)
                            {
                                Feature ship    = row as Feature;
                                MapPoint p_ship = ship.GetShape() as MapPoint;

                                double asemi               = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_asemi]) / 2;
                                double bsemi               = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_bsemi]) / 2;
                                double aoffset             = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_aoffset]) / 2;
                                double boffset             = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_boffset]) / 2;
                                double DDV                 = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_CollisionRisk]);
                                double cog                 = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_cog]);
                                cog                        = CommonMethod.GIScoord2ShipCoord(cog);
                                Coordinate2D ellipseCenter = new Coordinate2D()
                                {
                                    X = p_ship.X,
                                    Y = p_ship.Y
                                };
                                GeodesicEllipseParameter geodesic = new GeodesicEllipseParameter()
                                {
                                    Center          = ellipseCenter,
                                    SemiAxis1Length = asemi,
                                    SemiAxis2Length = bsemi,
                                    LinearUnit      = LinearUnit.Meters,
                                    OutGeometryType = GeometryType.Polygon,
                                    AxisDirection   = AngularUnit.Degrees.ConvertToRadians(cog),
                                    VertexCount     = 800
                                };
                                Geometry ellipse       = GeometryEngine.Instance.GeodesicEllipse(geodesic, SpatialReferenceBuilder.CreateSpatialReference(3857));
                                double moveX           = (aoffset * Math.Cos(AngularUnit.Degrees.ConvertToRadians(cog)) + boffset * Math.Sin(AngularUnit.Degrees.ConvertToRadians(cog)));
                                double moveY           = (aoffset * Math.Sin(AngularUnit.Degrees.ConvertToRadians(cog)) - boffset * Math.Cos(AngularUnit.Degrees.ConvertToRadians(cog)));
                                Geometry moved_ellipse = GeometryEngine.Instance.Move(ellipse, moveX, moveY);
                                using (RowBuffer rowBuffer = shipDomain.CreateRowBuffer())
                                {
                                    // Either the field index or the field name can be used in the indexer.
                                    rowBuffer[ConstDefintion.ConstFieldName_asemi]         = asemi;
                                    rowBuffer[ConstDefintion.ConstFieldName_bsemi]         = bsemi;
                                    rowBuffer[ConstDefintion.ConstFieldName_aoffset]       = aoffset;
                                    rowBuffer[ConstDefintion.ConstFieldName_CollisionRisk] = DDV;
                                    rowBuffer[shipDomainDefinition.GetShapeField()]        = moved_ellipse;
                                    using (Feature feature = shipDomain.CreateRow(rowBuffer))
                                    {
                                        feature.Store();
                                    }
                                }
                            }
                        }
                    }
                });
            }
        }
Example #13
0
        public static async Task CreateKeyPoints(string maskName, string unionMaskName, string keyPointName, double factor)
        {
            await QueuedTask.Run(() =>
            {
                StreamReader sr = new StreamReader(System.Environment.CurrentDirectory + ConstDefintion.ConstPath_TimeFilterConfig, Encoding.Default);
                String line;
                //读取状态
                line = sr.ReadLine();
                string filterStatus = line;
                line            = sr.ReadLine();
                int filterValue = Convert.ToInt32(line);
                sr.Close();
                using (Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(GeoDataTool.DefaultProject.DefaultGeodatabasePath))))
                {
                    gdb.ApplyEdits(() =>
                    {
                        //置空原船舶领域图层
                        FeatureClass fc_targetShip = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_TargetShip);
                        FeatureClass voyageMask    = gdb.OpenDataset <FeatureClass>(maskName);
                        FeatureClassDefinition voyageMaskDefinition = gdb.GetDefinition <FeatureClassDefinition>(maskName);
                        FeatureClass fc_ownShip             = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_OwnShip);
                        FeatureClass TargetShipObstacleLine = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_TargetShipObstacleLine);
                        TargetShipObstacleLine.DeleteRows(new QueryFilter()
                        {
                            WhereClause = "OBJECTID >= 1"
                        });
                        double own_x;
                        double own_y;
                        double own_cog;
                        using (RowCursor rowCursor = fc_ownShip.Search(null, false))
                        {
                            rowCursor.MoveNext();
                            using (Feature row = rowCursor.Current as Feature)
                            {
                                own_x   = (row.GetShape() as MapPoint).X;
                                own_y   = (row.GetShape() as MapPoint).Y;
                                own_cog = Convert.ToDouble(row[ConstDefintion.ConstFieldName_cog]);
                            }
                        }

                        voyageMask.DeleteRows(new QueryFilter()
                        {
                            WhereClause = "OBJECTID >= 1"
                        });
                        using (RowCursor rowCursor = fc_targetShip.Search(null, false))
                        {
                            while (rowCursor.MoveNext())
                            {
                                using (Row row = rowCursor.Current)
                                {
                                    Feature ship         = row as Feature;
                                    MapPoint p_ship      = ship.GetShape() as MapPoint;
                                    double CollisionRisk = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_CollisionRisk]);
                                    double asemi         = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_asemi]) * factor * 0.78;
                                    double bsemi         = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_bsemi]) * factor * 0.78;
                                    double aoffset       = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_aoffset]) * factor;
                                    double boffset       = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_boffset]) * factor;
                                    double cog           = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_cog]);
                                    double sog           = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_sog]);
                                    double tdv1          = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_tdv1]);
                                    double tdv2          = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_tdv2]);
                                    double ddv           = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_ddv]);
                                    double tcr           = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_tcr]);
                                    double tmin          = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_tmin]);
                                    long objectID        = Convert.ToInt64(ship[voyageMaskDefinition.GetObjectIDField()]);
                                    cog = CommonMethod.GIScoord2ShipCoord(cog);
                                    Coordinate2D ellipseCenter = new Coordinate2D()
                                    {
                                        X = p_ship.X,
                                        Y = p_ship.Y
                                    };
                                    if (!(CollisionRisk > 0))
                                    {
                                        continue;
                                    }
                                    //根据时间过滤器
                                    if (filterStatus != ConstDefintion.ConstStr_TimeFilterStatusOFF)
                                    {
                                        int time = filterValue * 60;
                                        if (tdv1 > time)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            if (tdv2 > time)
                                            {
                                                tdv2 = time;
                                            }
                                        }
                                    }
                                    //if (CommonMethod.JungeLeft(own_x - ellipseCenter.X, own_y - ellipseCenter.Y, own_cog) && CollisionRisk != 1) continue;
                                    GeodesicEllipseParameter geodesic = new GeodesicEllipseParameter()
                                    {
                                        Center          = ellipseCenter,
                                        SemiAxis1Length = asemi,
                                        SemiAxis2Length = bsemi,
                                        LinearUnit      = LinearUnit.Meters,
                                        OutGeometryType = GeometryType.Polygon,
                                        AxisDirection   = AngularUnit.Degrees.ConvertToRadians(cog),
                                        VertexCount     = 800
                                    };
                                    //创建原始位置的椭圆
                                    Geometry ellipse          = GeometryEngine.Instance.GeodesicEllipse(geodesic, SpatialReferenceBuilder.CreateSpatialReference(3857));
                                    double moveX              = (aoffset *Math.Cos(AngularUnit.Degrees.ConvertToRadians(cog))) + boffset *Math.Sin(AngularUnit.Degrees.ConvertToRadians(cog));
                                    double moveY              = (aoffset *Math.Sin(AngularUnit.Degrees.ConvertToRadians(cog))) - boffset *Math.Cos(AngularUnit.Degrees.ConvertToRadians(cog));
                                    Geometry moved_ellipse    = GeometryEngine.Instance.Move(ellipse, moveX, moveY);
                                    Coordinate2D centerRevise = new Coordinate2D()
                                    {
                                        X = p_ship.X + moveX,
                                        Y = p_ship.Y + moveY
                                    };
                                    //基于TDV创建船舶领域与动界
                                    double moveXs = (tdv1 *sog *ConstDefintion.ConstDouble_mpersTOkn *Math.Cos(AngularUnit.Degrees.ConvertToRadians(cog)));
                                    double moveYs = (tdv1 *sog *ConstDefintion.ConstDouble_mpersTOkn *Math.Sin(AngularUnit.Degrees.ConvertToRadians(cog)));
                                    Geometry moved_start_ellipse = GeometryEngine.Instance.Move(moved_ellipse, moveXs, moveYs);
                                    Coordinate2D centerTs        = new Coordinate2D()
                                    {
                                        X = centerRevise.X + moveXs,
                                        Y = centerRevise.Y + moveYs
                                    };
                                    double moveXe = (tdv2 *sog *ConstDefintion.ConstDouble_mpersTOkn *Math.Cos(AngularUnit.Degrees.ConvertToRadians(cog)));
                                    double moveYe = (tdv2 *sog *ConstDefintion.ConstDouble_mpersTOkn *Math.Sin(AngularUnit.Degrees.ConvertToRadians(cog)));
                                    Geometry moved_end_ellipse = GeometryEngine.Instance.Move(moved_ellipse, moveXe, moveYe);
                                    Coordinate2D centerTe      = new Coordinate2D()
                                    {
                                        X = centerRevise.X + moveXe,
                                        Y = centerRevise.Y + moveYe
                                    };

                                    //最终图形由两个椭圆和连接椭圆的长方形组成
                                    Geometry e_s_start    = GeometryEngine.Instance.SimplifyAsFeature(moved_start_ellipse, false);
                                    Geometry e_s_end      = GeometryEngine.Instance.SimplifyAsFeature(moved_end_ellipse, false);
                                    MapPoint p_1          = MapPointBuilder.CreateMapPoint(centerTs.X - (bsemi *Math.Sin(AngularUnit.Degrees.ConvertToRadians(cog))) * 1.29, centerTs.Y + (bsemi *Math.Cos(AngularUnit.Degrees.ConvertToRadians(cog))) * 1.29);
                                    MapPoint p_2          = MapPointBuilder.CreateMapPoint(centerTs.X + (bsemi *Math.Sin(AngularUnit.Degrees.ConvertToRadians(cog))) * 1.29, centerTs.Y - (bsemi *Math.Cos(AngularUnit.Degrees.ConvertToRadians(cog))) * 1.29);
                                    MapPoint p_3          = MapPointBuilder.CreateMapPoint(centerTe.X + (bsemi *Math.Sin(AngularUnit.Degrees.ConvertToRadians(cog))) * 1.29, centerTe.Y - (bsemi *Math.Cos(AngularUnit.Degrees.ConvertToRadians(cog))) * 1.29);
                                    MapPoint p_4          = MapPointBuilder.CreateMapPoint(centerTe.X - (bsemi *Math.Sin(AngularUnit.Degrees.ConvertToRadians(cog))) * 1.29, centerTe.Y + (bsemi *Math.Cos(AngularUnit.Degrees.ConvertToRadians(cog))) * 1.29);
                                    IList <MapPoint> p1_4 = GetInternPoints(p_1, p_4);
                                    IList <MapPoint> p2_3 = GetInternPoints(p_2, p_3);
                                    p2_3 = p2_3.Reverse <MapPoint>().ToList();
                                    List <MapPoint> list2D = new List <MapPoint>();
                                    list2D.Add(p_1);
                                    foreach (MapPoint p in p1_4)
                                    {
                                        list2D.Add(p);
                                    }
                                    list2D.Add(p_4);
                                    list2D.Add(p_3);
                                    foreach (MapPoint p in p2_3)
                                    {
                                        list2D.Add(p);
                                    }
                                    list2D.Add(p_2);
                                    Polygon connect_R = PolygonBuilder.CreatePolygon(list2D, SpatialReferenceBuilder.CreateSpatialReference(3857));
                                    Geometry simple_r = GeometryEngine.Instance.SimplifyAsFeature(connect_R, false);
                                    //融合图形
                                    IList <Geometry> g_List = new List <Geometry>()
                                    {
                                        e_s_start, simple_r, e_s_end
                                    };
                                    Geometry ellInstance = GeometryEngine.Instance.Union(g_List);
                                    using (RowBuffer rowBuffer = voyageMask.CreateRowBuffer())
                                    {
                                        // Either the field index or the field name can be used in the indexer.
                                        rowBuffer[ConstDefintion.ConstFieldName_ddv]      = CollisionRisk;
                                        rowBuffer[ConstDefintion.ConstFieldName_tdv1]     = tdv1;
                                        rowBuffer[ConstDefintion.ConstFieldName_tdv2]     = tdv2;
                                        rowBuffer[ConstDefintion.ConstFieldName_asemi]    = asemi;
                                        rowBuffer[ConstDefintion.ConstFieldName_bsemi]    = bsemi;
                                        rowBuffer[ConstDefintion.ConstFieldName_cog]      = cog;
                                        rowBuffer[ConstDefintion.ConstFieldName_sog]      = sog;
                                        rowBuffer[ConstDefintion.ConstFieldName_centerX1] = centerTs.X;
                                        rowBuffer[ConstDefintion.ConstFieldName_centerY1] = centerTs.Y;
                                        rowBuffer[ConstDefintion.ConstFieldName_centerX2] = centerTe.X;
                                        rowBuffer[ConstDefintion.ConstFieldName_centerY2] = centerTe.Y;
                                        rowBuffer[voyageMaskDefinition.GetShapeField()]   = ellInstance;

                                        using (Feature feature = voyageMask.CreateRow(rowBuffer))
                                        {
                                            feature.Store();
                                        }
                                    }
                                    //创建本船与他船的冲突路径
                                    Coordinate2D ts_location = ellipseCenter;
                                    Coordinate2D ts_Ts       = new Coordinate2D()//目标船冲突起点
                                    {
                                        X = ts_location.X + moveXs,
                                        Y = ts_location.Y + moveYs
                                    };
                                    Coordinate2D ts_Te = new Coordinate2D()//目标船冲突终点
                                    {
                                        X = ts_location.X + moveXe,
                                        Y = ts_location.Y + moveYe
                                    };
                                    List <Coordinate2D> ts_obstaclePointList = new List <Coordinate2D>()
                                    {
                                        ts_Ts, ts_Te
                                    };
                                    Polyline ts_obstacleLine = PolylineBuilder.CreatePolyline(ts_obstaclePointList, SpatialReferenceBuilder.CreateSpatialReference(3857));
                                    double kj_risk           = 0;
                                    if (ddv > 1)
                                    {
                                        kj_risk = 0;
                                    }
                                    else if (ddv < 0.5)
                                    {
                                        kj_risk = 1;
                                    }
                                    else
                                    {
                                        kj_risk = Math.Pow(2 - 2 * ddv, 3.03);
                                    }
                                    using (RowBuffer rowBuffer = TargetShipObstacleLine.CreateRowBuffer())
                                    {
                                        // Either the field index or the field name can be used in the indexer.
                                        rowBuffer[ConstDefintion.ConstFieldName_dcr]   = kj_risk;
                                        rowBuffer[ConstDefintion.ConstFieldName_tcr]   = tcr;
                                        rowBuffer[ConstDefintion.ConstFieldName_risk]  = CollisionRisk;
                                        rowBuffer[ConstDefintion.ConstFieldName_tdv1]  = tdv1;
                                        rowBuffer[ConstDefintion.ConstFieldName_tdv2]  = tdv2;
                                        rowBuffer[ConstDefintion.ConstFieldName_tmin]  = tmin;
                                        rowBuffer[ConstDefintion.ConstFieldName_Shape] = ts_obstacleLine;

                                        using (Feature feature = TargetShipObstacleLine.CreateRow(rowBuffer))
                                        {
                                            feature.Store();
                                        }
                                    }
                                }
                            }
                        }
                    });
                }
            });

            //创建航行位置Mask

            await QueuedTask.Run(async() =>
            {
                //Mask边缘
                //合并要素
                using (Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(GeoDataTool.DefaultProject.DefaultGeodatabasePath))))
                {
                    gdb.ApplyEdits(() =>
                    {
                        using (FeatureClass u_VoyageMask = gdb.OpenDataset <FeatureClass>(unionMaskName))
                        {
                            u_VoyageMask.DeleteRows(new QueryFilter()
                            {
                                WhereClause = "OBJECTID >= 1"
                            });
                            using (FeatureClass voyageMask = gdb.OpenDataset <FeatureClass>(maskName))
                            {
                                IList <Geometry> u_list = new List <Geometry>();
                                FeatureClassDefinition u_voyageMaskDefinition = gdb.GetDefinition <FeatureClassDefinition>(unionMaskName);
                                using (RowCursor rowCursor = voyageMask.Search(null, false))
                                {
                                    while (rowCursor.MoveNext())
                                    {
                                        using (Feature f = rowCursor.Current as Feature)
                                        {
                                            u_list.Add(f.GetShape());
                                        }
                                    }
                                    //赋值
                                    using (RowBuffer rowBuffer = u_VoyageMask.CreateRowBuffer())
                                    {
                                        Geometry geometry = GeometryEngine.Instance.Union(u_list);
                                        rowBuffer[u_voyageMaskDefinition.GetShapeField()] = geometry;
                                        using (Feature feature = u_VoyageMask.CreateRow(rowBuffer))
                                        {
                                            feature.Store();
                                        }
                                    }
                                }
                            }
                        }
                    });
                }
                //运行要素边缘转点
                string inpath = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + keyPointName;
                var args      = Geoprocessing.MakeValueArray(inpath);
                var result    = await Geoprocessing.ExecuteToolAsync("Delete_management", args, null, null, null);

                string inpath1 = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + unionMaskName;
                string outpath = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + keyPointName;
                var args1      = Geoprocessing.MakeValueArray(inpath1, outpath, "ALL");
                var result1    = await Geoprocessing.ExecuteToolAsync("FeatureVerticesToPoints_management", args1, null, null, null);
            });
        }