private async void SelectCourse()
        {
            string fieldName = string.Empty;
            var    oidField  = QueuedTask.Run(() =>
            {
                string name;
                using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(GeoDataTool.DefaultProject.DefaultGeodatabasePath))))
                {
                    FeatureClassDefinition fcd = geodatabase.GetDefinition <FeatureClassDefinition>(ConstDefintion.ConstFeatureClass_Course);
                    name = fcd.GetObjectIDField();
                }
                return(name);
            }).Result;
            string path        = ConstDefintion.ConstFeatureClass_Course;
            string whereClause = $"{oidField} = {CourseListSelectedItem}";

            ProgressDialog progressDialogDomain = new ProgressDialog($"切换选择中", ConstDefintion.ConstStr_GeoprocessCancling, false);
            var            arg  = Geoprocessing.MakeValueArray(path, "NEW_SELECTION", whereClause);
            var            task = await Geoprocessing.ExecuteToolAsync("SelectLayerByAttribute_management", arg, null, new CancelableProgressorSource(progressDialogDomain).Progressor);

            if (!task.IsFailed)
            {
                if (!(MapView.Active == null))
                {
                    await MapView.Active.ZoomToSelectedAsync();
                }
            }
        }
예제 #2
0
        public static async Task <bool> ZoomToExtentAsync(Uri aoiUri, double bufferFactor = 1)
        {
            //Get the active map view.
            var mapView = MapView.Active;

            if (mapView == null)
            {
                return(false);
            }
            string strFileName   = null;
            string strFolderPath = null;

            if (aoiUri.IsFile)
            {
                strFileName   = System.IO.Path.GetFileName(aoiUri.LocalPath);
                strFolderPath = System.IO.Path.GetDirectoryName(aoiUri.LocalPath);
            }

            Envelope zoomEnv = null;
            await QueuedTask.Run(() => {
                // Opens a file geodatabase. This will open the geodatabase if the folder exists and contains a valid geodatabase.
                using (
                    Geodatabase geodatabase =
                        new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(strFolderPath))))
                {
                    // Use the geodatabase.
                    FeatureClassDefinition fcDefinition = geodatabase.GetDefinition <FeatureClassDefinition>(strFileName);
                    zoomEnv = fcDefinition.GetExtent().Expand(bufferFactor, bufferFactor, true);
                }
            });

            //Zoom the view to a given extent.
            return(await mapView.ZoomToAsync(zoomEnv, null));
        }
예제 #3
0
        public static async Task KeyPointsIntegration()
        {
            await QueuedTask.Run(() =>
            {
                using (Geodatabase gdb1 = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(GeoDataTool.DefaultProject.DefaultGeodatabasePath))))
                {
                    gdb1.ApplyEdits(() =>
                    {
                        FeatureClass voyageRiskKeyPoint = gdb1.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_VoyageRiskKeyPoint);
                        FeatureClassDefinition voyageRiskKeyPointDefinition = gdb1.GetDefinition <FeatureClassDefinition>(ConstDefintion.ConstFeatureClass_VoyageRiskKeyPoint);
                        voyageRiskKeyPoint.DeleteRows(new QueryFilter()
                        {
                            WhereClause = "OBJECTID >= 1"
                        });
                        string shapeFieldName = voyageRiskKeyPointDefinition.GetShapeField();

                        RiskAssessment(gdb1, voyageRiskKeyPoint, ConstDefintion.ConstFeatureClass_VoyageMaskInternalPoint, 1);
                        RiskAssessment(gdb1, voyageRiskKeyPoint, ConstDefintion.ConstFeatureClass_VoyageMaskOutlinePoint, 0);
                        double midLocaRisk = Math.Pow(0.5, 3.03);
                        RiskAssessment(gdb1, voyageRiskKeyPoint, ConstDefintion.ConstFeatureClass_VoyageMaskLocaMidPoint, midLocaRisk);
                        RiskAssessment(gdb1, voyageRiskKeyPoint, ConstDefintion.ConstFeatureClass_VoyageMaskRiskMidPoint, 0.5);
                    });
                }
            });
        }
        private async Task <IGPResult> ExtraObstacle(double distance)
        {
            string fieldName = string.Empty;
            var    oidField  = QueuedTask.Run(() =>
            {
                string name;
                using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(GeoDataTool.DefaultProject.DefaultGeodatabasePath))))
                {
                    FeatureClassDefinition fcd = geodatabase.GetDefinition <FeatureClassDefinition>(ConstDefintion.ConstFeatureClass_Course);
                    name = fcd.GetObjectIDField();
                }
                return(name);
            }).Result;
            string         path                 = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + ConstDefintion.ConstFeatureClass_Course;
            string         outpath              = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + ConstDefintion.ConstFeatureClass_SelectedCourse;
            string         whereClause          = $"{oidField} = {CourseListSelectedItem}";
            ProgressDialog progressDialogDomain = new ProgressDialog($"正在创建被选择航线图层", ConstDefintion.ConstStr_GeoprocessCancling, false);
            var            arg = Geoprocessing.MakeValueArray(path, outpath, whereClause);
            var            gp  = await Geoprocessing.ExecuteToolAsync("Select_analysis", arg, null, new CancelableProgressorSource(progressDialogDomain).Progressor);

            if (!gp.IsFailed)
            {
                ProgressDialog progressDialog1 = new ProgressDialog($"正在构造缓冲区", ConstDefintion.ConstStr_GeoprocessCancling, false);
                string         outBufferpath   = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + ConstDefintion.ConstFeatureClass_CourseBuffer;
                string         str_distance    = $"{distance} NauticalMiles";
                var            arg1            = Geoprocessing.MakeValueArray(outpath, outBufferpath, str_distance);
                var            gp1             = await Geoprocessing.ExecuteToolAsync("Buffer_analysis", arg1, null, new CancelableProgressorSource(progressDialog1).Progressor);

                if (!gp1.IsFailed)
                {
                    ProgressDialog progressDialog2   = new ProgressDialog($"正在提取碍航物", ConstDefintion.ConstStr_GeoprocessCancling, false);
                    string         insArgs           = $"{ObstaclePath} 1;{outBufferpath} 2";
                    string         outcourseObstacle = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + ConstDefintion.ConstFeatureClass_CourseObstacle;
                    var            arg2 = Geoprocessing.MakeValueArray(insArgs, outcourseObstacle);
                    var            gp2  = await Geoprocessing.ExecuteToolAsync("Intersect_analysis", arg2, null, new CancelableProgressorSource(progressDialog2).Progressor);

                    if (!gp2.IsFailed)
                    {
                        ProgressDialog progressDialog3            = new ProgressDialog($"正在创建泰森多边形", ConstDefintion.ConstStr_GeoprocessCancling, false);
                        string         outCourseObstacle_Thiessen = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + ConstDefintion.ConstFeatureClass_CourseObstacleThiessen;
                        var            arg3 = Geoprocessing.MakeValueArray(outcourseObstacle, outCourseObstacle_Thiessen);
                        var            gp3  = await Geoprocessing.ExecuteToolAsync("CreateThiessenPolygons_analysis", arg3, null, new CancelableProgressorSource(progressDialog3).Progressor);

                        if (!gp3.IsFailed)
                        {
                            ProgressDialog progressDialog4           = new ProgressDialog($"正在裁剪", ConstDefintion.ConstStr_GeoprocessCancling, false);
                            string         inCourseObstacle_Thiessen = outCourseObstacle_Thiessen;
                            string         inBuffer        = outBufferpath;
                            string         outClipThiessen = GeoDataTool.DefaultProject.DefaultGeodatabasePath + "\\" + ConstDefintion.ConstFeatureClass_CourseObstacleThiessenClip;
                            var            arg4            = Geoprocessing.MakeValueArray(inCourseObstacle_Thiessen, inBuffer, outClipThiessen);
                            var            gp4             = await Geoprocessing.ExecuteToolAsync("Clip_analysis", arg4, null, new CancelableProgressorSource(progressDialog4).Progressor);

                            return(gp4);
                        }
                    }
                }
            }
            return(null);
        }
        public void MainMethodCode()
        {
            Uri serviceUrl = new Uri("https://arcgis.server.example.com:6443/arcgis/rest/services/FeatureServiceName/FeatureServer");

            ServiceConnectionProperties arcGisServer = new ServiceConnectionProperties(serviceUrl)
            {
                User     = "******",
                Password = "******"
            };

            using (Geodatabase serverFeatureService = new Geodatabase(arcGisServer))
            {
                FeatureClassDefinition featureClassDefinition = serverFeatureService.GetDefinition <FeatureClassDefinition>("0");
                string shapeField            = featureClassDefinition.GetShapeField();
                IReadOnlyList <Field> fields = featureClassDefinition.GetFields();

                TableDefinition tableDefinition = serverFeatureService.GetDefinition <TableDefinition>("4");
                string          objectIDField   = tableDefinition.GetObjectIDField();
            }
        }
        private static void ExploreTopologyDefinition(Geodatabase geodatabase, Topology topology)
        {
            // Similar to the rest of the Definition objects in the Core.Data API, there are two ways to open a dataset's
            // definition -- via the Topology dataset itself or via the Geodatabase.

            using (TopologyDefinition definitionViaTopology = topology.GetDefinition())
            {
                OutputDefinition(geodatabase, definitionViaTopology);
            }

            using (TopologyDefinition definitionViaGeodatabase = geodatabase.GetDefinition <TopologyDefinition>(GRAND_TETON_TOPO_NAME))
            {
                //OutputDefinition(geodatabase, definitionViaGeodatabase);
            }
        }
예제 #7
0
        private void ProcessDefinition(Geodatabase geodatabase, Topology topology)
        {
            // Similar to the rest of the Definition objects in the Core.Data API, there are two ways to open a dataset's
            // definition -- via the Topology dataset itself or via the Geodatabase.

            using (TopologyDefinition definitionViaTopology = topology.GetDefinition())
            {
                OutputDefinition(geodatabase, definitionViaTopology);
            }

            using (TopologyDefinition definitionViaGeodatabase = geodatabase.GetDefinition <TopologyDefinition>("Backcountry_Topology"))
            {
                OutputDefinition(geodatabase, definitionViaGeodatabase);
            }
        }
예제 #8
0
        public void MainMethodCode()
        {
            // Opening a Non-Versioned SQL Server instance.

            DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
            {
                AuthenticationMode = AuthenticationMode.DBMS,

                // Where testMachine is the machine where the instance is running and testInstance is the name of the SqlServer instance.
                Instance = @"testMachine\testInstance",

                // Provided that a database called LocalGovernment has been created on the testInstance and geodatabase has been enabled on the database.
                Database = "LocalGovernment",

                // Provided that a login called gdb has been created and corresponding schema has been created with the required permissions.
                User     = "******",
                Password = "******",
                Version  = "dbo.DEFAULT"
            };

            using (Geodatabase geodatabase = new Geodatabase(connectionProperties))
                using (FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition <FeatureClassDefinition>("LocalGovernment.GDB.ServiceRequestComment"))
                {
                    int   rankIndex = featureClassDefinition.FindField("RANK");
                    Field field     = featureClassDefinition.GetFields()[rankIndex];

                    Domain domain = field.GetDomain();

                    RangeDomain rangeDomain = (RangeDomain)domain;

                    // Will be "ServiceRequestRanking".
                    string name = rangeDomain.GetName();

                    // Will be FieldType.Integer.
                    FieldType fieldType = rangeDomain.GetFieldType();

                    // Will be "A factor assigned to unassigned service requests indicating importance".
                    string description = rangeDomain.GetDescription();

                    // Will be 1.
                    int minValue = Convert.ToInt32(rangeDomain.GetMinValue());

                    // Will be 5.
                    int maxValue = Convert.ToInt32(rangeDomain.GetMaxValue());
                }
        }
        /// <summary>
        /// 指定されたファイルジオデータベースに同名称既存のレイヤーの存在を検査する
        /// </summary>
        public bool FeatureClassExists(string geodatabase, string featureClassName)
        {
            try
            {
                var fileGDBpath = new FileGeodatabaseConnectionPath(new Uri(geodatabase));

                using (Geodatabase gdb = new Geodatabase(fileGDBpath))
                {
                    FeatureClassDefinition featureClassDefinition = gdb.GetDefinition <FeatureClassDefinition>(featureClassName);
                    featureClassDefinition.Dispose();
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
 public bool FeatureClassExists(string fileGDBPath, string featureClassName)
 {
     try
     {
         using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(fileGDBPath))))
         {
             FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition <FeatureClassDefinition>(featureClassName);
             featureClassDefinition.Dispose();
             System.Diagnostics.Debug.WriteLine($"Feature class exists");
             return(true);
         }
     }
     catch
     {
         // GetDefinition throws an exception if the definition doesn't exist
         System.Diagnostics.Debug.WriteLine($"Feature class does not exist");
         return(false);
     }
 }
예제 #11
0
        public static void InsertRows(string path,
                                      string featureClassName, Geometry polygon, int rowCount)
        {
            var uri = new Uri(path, UriKind.Absolute);

            using (var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(uri)))
            {
                var    definition = geodatabase.GetDefinition <FeatureClassDefinition>(featureClassName);
                string shapeField = definition.GetShapeField();

                using (var featureClass = geodatabase.OpenDataset <FeatureClass>(featureClassName))
                {
                    for (var i = 0; i < rowCount; i++)
                    {
                        object value = "Bart";
                        InsertRow(featureClass, shapeField, polygon, value);
                    }
                }
            }
        }
예제 #12
0
        public void Can_instantiate_IssueItem()
        {
            var definition =
                _geodatabase.GetDefinition <FeatureClassDefinition>(_issuePointsFeatureClassName);

            var reader = new AttributeReader(definition,
                                             Attributes.IssueCode,
                                             Attributes.IssueCodeDescription,
                                             Attributes.InvolvedObjects,
                                             Attributes.QualityConditionName,
                                             Attributes.TestName,
                                             Attributes.TestDescription,
                                             Attributes.TestType,
                                             Attributes.IssueSeverity,
                                             Attributes.IsStopCondition,
                                             Attributes.Category,
                                             Attributes.AffectedComponent,
                                             Attributes.Url,
                                             Attributes.DoubleValue1,
                                             Attributes.DoubleValue2,
                                             Attributes.TextValue,
                                             Attributes.IssueAssignment,
                                             Attributes.QualityConditionUuid,
                                             Attributes.QualityConditionVersionUuid,
                                             Attributes.ExceptionStatus,
                                             Attributes.ExceptionNotes,
                                             Attributes.ExceptionCategory,
                                             Attributes.ExceptionOrigin,
                                             Attributes.ExceptionDefinedDate,
                                             Attributes.ExceptionLastRevisionDate,
                                             Attributes.ExceptionRetirementDate,
                                             Attributes.ExceptionShapeMatchCriterion);

            foreach (Feature feature in GdbQueryUtils.GetRows <Feature>(_issuePoints))
            {
                var item = new IssueItem(0, feature);
                break;
            }
        }
예제 #13
0
 /// <summary>
 /// Gets all dataset feature class definitions. This method must be called on the MCT or within a method that will be called on the MCT. Use QueuedTask.Run.
 /// </summary>
 /// <returns>
 /// All dataset feature class definitions.
 /// </returns>
 private static IReadOnlyList <FeatureClassDefinition> GetDatasetFeatureClassDefinitions()
 {
     using (var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(Project.Current.DefaultGeodatabasePath))))
         using (var featureDatasetDefinition = geodatabase.GetDefinition <FeatureDatasetDefinition>("FeatureDataset"))
             return(geodatabase.GetRelatedDefinitions(featureDatasetDefinition, DefinitionRelationshipType.DatasetInFeatureDataset).OfType <FeatureClassDefinition>().ToList());
 }
        public void MainMethodCode()
        {
            // Opens a file geodatabase  This will open the geodatabase if the folder exists and contains a valid geodatabase.

            using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb"))))
            {
                RelationshipClassDefinition definition  = fileGeodatabase.GetDefinition <RelationshipClassDefinition>("AddressPointHasSiteAddresses");
                IReadOnlyList <Definition>  definitions = fileGeodatabase.GetRelatedDefinitions(definition, DefinitionRelationshipType.DatasetsRelatedThrough);

                // This will not be null.
                FeatureClassDefinition addressPointDefinition = definitions.First(defn => defn.GetName().Equals("AddressPoint")) as FeatureClassDefinition;

                // This will not be null.
                FeatureClassDefinition siteAddressPointDefinition = definitions.First(defn => defn.GetName().Equals("SiteAddressPoint")) as FeatureClassDefinition;
            }

            // Opening a Non-Versioned SQL Server instance.

            DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
            {
                AuthenticationMode = AuthenticationMode.DBMS,

                // Where testMachine is the machine where the instance is running and testInstance is the name of the SqlServer instance.
                Instance = @"testMachine\testInstance",

                // Provided that a database called LocalGovernment has been created on the testInstance and geodatabase has been enabled on the database.
                Database = "LocalGovernment",

                // Provided that a login called gdb has been created and corresponding schema has been created with the required permissions.
                User     = "******",
                Password = "******",
                Version  = "dbo.DEFAULT"
            };

            using (Geodatabase geodatabase = new Geodatabase(connectionProperties))
            {
                // Remember the qualification of DatabaseName. for the RelationshipClass.
                RelationshipClassDefinition enterpriseDefinition  = geodatabase.GetDefinition <RelationshipClassDefinition>("LocalGovernment.GDB.AddressPointHasSiteAddresses");
                IReadOnlyList <Definition>  enterpriseDefinitions = geodatabase.GetRelatedDefinitions(enterpriseDefinition, DefinitionRelationshipType.DatasetsRelatedThrough);

                // This will not be null.
                FeatureClassDefinition enterpriseAddressPointDefinition = enterpriseDefinitions.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPoint")) as FeatureClassDefinition;

                // This will not be null.
                FeatureClassDefinition enterpriseSiteAddressPointDefinition = enterpriseDefinitions.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.SiteAddressPoint")) as FeatureClassDefinition;

                FeatureDatasetDefinition   featureDatasetDefinition = geodatabase.GetDefinition <FeatureDatasetDefinition>("LocalGovernment.GDB.Address");
                IReadOnlyList <Definition> datasetsInAddressDataset = geodatabase.GetRelatedDefinitions(featureDatasetDefinition, DefinitionRelationshipType.DatasetInFeatureDataset);

                // This will not be null.
                FeatureClassDefinition addressPointInAddressDataset = datasetsInAddressDataset.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPoint")) as FeatureClassDefinition;

                // This will not be null.
                FeatureClassDefinition siteAddressPointInAddressDataset = datasetsInAddressDataset.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.SiteAddressPoint")) as FeatureClassDefinition;

                // This will not be null.
                FeatureClassDefinition addressEntryPointInAddressDataset = datasetsInAddressDataset.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.AddressEntrancePoint")) as FeatureClassDefinition;

                // This will not be null.
                RelationshipClassDefinition addressPointHasSiteAddressInAddressDataset = datasetsInAddressDataset.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.AddressPointHasSiteAddresses")) as RelationshipClassDefinition;

                // This will not be null.
                RelationshipClassDefinition siteAddressHasPostalAddressInAddressDataset = datasetsInAddressDataset.First(
                    defn => defn.GetName().Equals("LocalGovernment.GDB.SiteAddresshasPostalAddresses")) as RelationshipClassDefinition;

                FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition <FeatureClassDefinition>("LocalGovernment.GDB.AddressPoint");
                // This will be empty.
                IReadOnlyList <Definition> emptyDefinitionList = geodatabase.GetRelatedDefinitions(featureClassDefinition, DefinitionRelationshipType.DatasetInFeatureDataset);

                TableDefinition tableClassDefinition = geodatabase.GetDefinition <TableDefinition>("LocalGovernment.GDB.EmployeeInfo");
                // This will be empty.
                IReadOnlyList <Definition> anotherEmptyDefinitionList = geodatabase.GetRelatedDefinitions(tableClassDefinition, DefinitionRelationshipType.DatasetsRelatedThrough);
            }
        }
예제 #15
0
        internal static async Task CreateEvaluatePointsAsync()
        {
            await QueuedTask.Run(() =>
            {
                using (Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(GeoDataTool.DefaultProject.DefaultGeodatabasePath))))
                {
                    gdb.ApplyEdits(() =>
                    {
                        //置空原船舶领域图层
                        FeatureClass fc_targetShip                = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_TargetShip);
                        FeatureClass fc_ownShip                   = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_OwnShip);
                        FeatureClass fc_evaluatePoints            = gdb.OpenDataset <FeatureClass>(ConstDefintion.ConstFeatureClass_VoyageRiskEvaluatePoint);
                        FeatureClassDefinition fcd_evaluatePoints = gdb.GetDefinition <FeatureClassDefinition>(ConstDefintion.ConstFeatureClass_VoyageRiskEvaluatePoint);
                        fc_evaluatePoints.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]);
                            }
                        }
                        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]);
                                    double bsemi         = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_bsemi]);
                                    double aoffset       = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_aoffset]);
                                    double boffset       = Convert.ToDouble(ship[ConstDefintion.ConstFieldName_boffset]);
                                    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]);
                                    long objectID        = Convert.ToInt64(ship["OBJECTID"]);
                                    //真北转坐标北
                                    cog = CommonMethod.GIScoord2ShipCoord(cog);
                                    Coordinate2D ellipseCenter = new Coordinate2D()
                                    {
                                        X = p_ship.X,
                                        Y = p_ship.Y
                                    };
                                    if (!(objectID == 6))
                                    {
                                        continue;
                                    }
                                    if (!(CollisionRisk > 0))
                                    {
                                        continue;
                                    }
                                    if (CommonMethod.JungeLeft(own_x - ellipseCenter.X, own_y - ellipseCenter.Y, own_cog) && CollisionRisk != 1)
                                    {
                                        continue;
                                    }
                                    for (int i = 0; i < 21; i++)
                                    {
                                        //创建原始位置的椭圆 动界中心
                                        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));
                                        //换算第i个点位的瞬时位置椭圆中心
                                        moveX *= i * 0.05;
                                        moveY *= i * 0.05;
                                        Coordinate2D centerRevise = new Coordinate2D()
                                        {
                                            X = p_ship.X + moveX,
                                            Y = p_ship.Y + moveY
                                        };
                                        //起长半轴
                                        double angle1 = AngularUnit.Degrees.ConvertToRadians(cog) + Math.PI;
                                        //短半轴
                                        double angle2 = AngularUnit.Degrees.ConvertToRadians(cog) + Math.PI / 2;
                                        double angle3 = AngularUnit.Degrees.ConvertToRadians(cog) - Math.PI / 2;
                                        //基于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)));
                                        Coordinate2D centerTs = new Coordinate2D()
                                        {
                                            X = centerRevise.X + moveXs,
                                            Y = centerRevise.Y + moveYs
                                        };

                                        CreateSemiEvaluatePoint(i, angle1, asemi *i * 0.05, centerTs, fc_evaluatePoints);

                                        CreateSemiEvaluatePoint(i, angle2, bsemi *i * 0.05, centerTs, fc_evaluatePoints);
                                        CreateSemiEvaluatePoint(i, angle3, bsemi *i * 0.05, centerTs, fc_evaluatePoints);
                                        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)));
                                        Coordinate2D centerTe = new Coordinate2D()
                                        {
                                            X = centerRevise.X + moveXe,
                                            Y = centerRevise.Y + moveYe
                                        };
                                        double angle4 = AngularUnit.Degrees.ConvertToRadians(cog);
                                        CreateSemiEvaluatePoint(i, angle4, asemi *i * 0.05, centerTe, fc_evaluatePoints);
                                        //短半轴
                                        CreateSemiEvaluatePoint(i, angle2, bsemi *i * 0.05, centerTe, fc_evaluatePoints);
                                        CreateSemiEvaluatePoint(i, angle3, bsemi *i * 0.05, centerTe, fc_evaluatePoints);
                                    }
                                }
                            }
                        }
                    });
                }
            });
        }
 /// <summary>
 /// Given that the RelationshipClass is selected, this method will
 /// 1. Get the Definitions of Datasets related by the selected relationship class
 /// 2. Set the RelatedFeatureClass property to the Table/FeatureClass which is related to the FeatureClass corresponding to the selected layer
 /// </summary>
 public void UpdateRelatedFeatureClass()
 {
     QueuedTask.Run(() =>
     {
         using (Table table = (MapView.Active.Map.Layers.First(layer => layer.Name.Equals(SelectedLayer)) as FeatureLayer).GetTable())
         {
             Geodatabase geodatabase = null;
             if (table != null && table.GetDatastore() is Geodatabase)
             {
                 geodatabase = table.GetDatastore() as Geodatabase;
             }
             if (geodatabase == null)
             {
                 return;
             }
             if (SelectedRelationship == null)
             {
                 return;
             }
             IReadOnlyList <Definition> relatedDefinitions = geodatabase.GetRelatedDefinitions(geodatabase.GetDefinition <RelationshipClassDefinition>(SelectedRelationship),
                                                                                               DefinitionRelationshipType.DatasetsRelatedThrough);
             relatedFeatureClassDefinition = relatedDefinitions.First(definition => definition.GetName() != table.GetDefinition().GetName());
             RelatedFeatureClass           = relatedFeatureClassDefinition.GetName();
         }
     });
 }
        /// <summary>
        /// Because we need a type of 'index' that allows create a set of maps and
        /// corresponding mapviews.  The 'index' is then displayed in a datagrid on a dockpane.
        /// Selecting an item on the datagrid will either show or hide the associated mapview pane
        /// </summary>
        private void CreateMapviewItemsAsync()
        {
            if (Project.Current == null)
            {
                lock (_lockCollection)
                {
                    ListOfMapviews.Clear();
                }
                return;
            }
            IEnumerable <GDBProjectItem> gdbProjectItems = Project.Current.GetItems <GDBProjectItem>();

            QueuedTask.Run(() =>
            {
                lock (_lockCollection)
                {
                    ListOfMapviews.Clear();
                }
                bool bFound = false;
                if (string.IsNullOrEmpty(_temporaryPath))
                {
                    _temporaryPath = System.IO.Path.GetTempPath();
                }
                foreach (GDBProjectItem gdbProjectItem in gdbProjectItems)
                {
                    using (Datastore datastore = gdbProjectItem.GetDatastore())
                    {
                        //Unsupported datastores (non File GDB and non Enterprise GDB) will be of type UnknownDatastore
                        if (datastore is UnknownDatastore)
                        {
                            continue;
                        }

                        Geodatabase geodatabase = datastore as Geodatabase;
                        // Use the geodatabase.
                        try
                        {
                            var statesFeature = geodatabase.GetDefinition <FeatureClassDefinition>("states");
                            var shortNameIdx  = statesFeature.FindField("STATE_ABBR");
                            var fipsNumberIdx = statesFeature.FindField("STATE_FIPS");
                            var geoIdx        = statesFeature.FindField(statesFeature.GetShapeField());
                            if (shortNameIdx >= 0 && fipsNumberIdx >= 0)
                            {
                                using (FeatureClass fcStates = geodatabase.OpenDataset <FeatureClass>(statesFeature.GetName()))
                                {
                                    var fcRowCursor = fcStates.Search(new QueryFilter {
                                        SubFields = "STATE_ABBR,STATE_FIPS,Shape", WhereClause = "1 = 1", PostfixClause = "order by STATE_ABBR"
                                    });
                                    while (fcRowCursor.MoveNext())
                                    {
                                        using (Row row = fcRowCursor.Current)
                                        {
                                            var mapName   = row[shortNameIdx].ToString();
                                            var mapNumber = Convert.ToUInt16(row[fipsNumberIdx]);
                                            var geometry  = row[geoIdx] as Geometry;
                                            lock (_lockCollection)
                                            {
                                                if (!ListOfMapviews.Any((x) => x.MapName == mapName))
                                                {
                                                    ListOfMapviews.Add(new MapviewItem
                                                    {
                                                        MapName   = mapName,
                                                        MapNumber = mapNumber,
                                                        Extent    = geometry.Extent.Expand(1.1, 1.1, true)
                                                    });
                                                }
                                            }
                                            bFound = true;
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                            // no state feature class found
                        }
                    }
                }
                if (!bFound)
                {
                    lock (_lockCollection)
                    {
                        ListOfMapviews.Add(new MapviewItem {
                            MapName = "No 'States' Feature class"
                        });
                    }
                }
            });
        }
예제 #18
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();
                                     }
                                 }
                             }
                         }
                     }
                 }
             });
         }
     });
 }
예제 #19
0
        public void MainMethodCode()
        {
            // Opens a file geodatabase  This will open the geodatabase if the folder exists and contains a valid geodatabase.

            using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\LocalGovernment.gdb"))))
            {
                TableDefinition tableDefinition = fileGeodatabase.GetDefinition <TableDefinition>("CitizenContactInfo");

                // Use the fileGeodatabase and tableDefinition.
            }

            // Opening a Non-Versioned SQL Server instance.

            DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
            {
                AuthenticationMode = AuthenticationMode.DBMS,

                // Where testMachine is the machine where the instance is running and testInstance is the name of the SqlServer instance.
                Instance = @"testMachine\testInstance",

                // Provided that a database called LocalGovernment has been created on the testInstance and geodatabase has been enabled on the database.
                Database = "LocalGovernment",

                // Provided that a login called gdb has been created and corresponding schema has been created with the required permissions.
                User     = "******",
                Password = "******",
                Version  = "dbo.DEFAULT"
            };

            using (Geodatabase geodatabase = new Geodatabase((connectionProperties)))
            {
                // Remember that for Enterprise databases you have to qualify your dataset names with the DatabaseName and UserName.
                TableDefinition enterpriseTableDefinition = geodatabase.GetDefinition <TableDefinition>("LocalGovernment.GDB.CitizenContactInfo");

                // It does not matter if the dataset is within a FeatureDataset or not.
                FeatureClassDefinition featureClassDefinition = geodatabase.GetDefinition <FeatureClassDefinition>("LocalGovernment.GDB.FireStation");

                // GetDefinition For a RelationshipClass.
                RelationshipClassDefinition relationshipClassDefinition = geodatabase.GetDefinition <RelationshipClassDefinition>("LocalGovernment.GDB.AddressPointHasSiteAddresses");

                // GetDefinition For a FeatureDataset.
                FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition <FeatureDatasetDefinition>("LocalGovernment.GDB.Address")
                ;
                try
                {
                    // Note that although you can open a FeatureClass as a Table using OpenDataset, you cannot call GetDefinition on a FeatureClass with DatasetType.Table.
                    geodatabase.GetDefinition <TableDefinition>("LocalGovernment.GDB.FireStation");

                    // Attempting to open a FeatureDataset as a RelationshipClass will fail.
                    // This is an example i.e. any mismatch between DatasetType specified and Actual DatasetType will cause GetDefinition to fail.
                    geodatabase.GetDefinition <RelationshipClassDefinition>("LocalGovernment.GDB.Address");

                    // If you do not qualify your Dataset Name GetDefinition fails. Note that this worked for File Geodatabase.
                    geodatabase.GetDefinition <TableDefinition>("CitizenContactInfo");

                    // Trying to GetDefinition of a non existent dataset.
                    geodatabase.GetDefinition <TableDefinition>("SomeRandomString");
                }
                catch (GeodatabaseCatalogDatasetException catalogDatasetException)
                {
                    // All of the above scenarios will result in GeodatabaseCatalogDatasetException with a message "Item Not Found".
                    // Remember that when you get this exception, most likely the following are the reasons.
                    // 1. The Item might not exist.
                    // 2. There might be a mismatch between DatasetType specified and Actual DatasetType.
                    // 3. The qualification for the DatasetName is wrong.
                    // 4. The User does not have visibility to the dataset
                }
            }
        }
예제 #20
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);
            });
        }
        public void MainMethodCode()
        {
            // Opening a Non-Versioned SQL Server instance.

            DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
            {
                AuthenticationMode = AuthenticationMode.DBMS,

                // Where testMachine is the machine where the instance is running and testInstance is the name of the SqlServer instance.
                Instance = @"testMachine\testInstance",

                // Provided that a database called LocalGovernment has been created on the testInstance and geodatabase has been enabled on the database.
                Database = "LocalGovernment",

                // Provided that a login called gdb has been created and corresponding schema has been created with the required permissions.
                User     = "******",
                Password = "******",
                Version  = "dbo.DEFAULT"
            };

            using (Geodatabase geodatabase = new Geodatabase(connectionProperties))
                using (FeatureClass featureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.FacilitySite"))
                {
                    FeatureClassDefinition featureClassDefinition = featureClass.GetDefinition();

                    int    facilityCodeIndex = featureClassDefinition.FindField("FCODE");
                    Field  field             = featureClassDefinition.GetFields()[facilityCodeIndex];
                    Domain domain            = field.GetDomain(featureClassDefinition.GetSubtypes().FirstOrDefault(
                                                                   subtype => subtype.GetName().ToLowerInvariant().Contains("agriculture")));

                    CodedValueDomain codedValueDomain = (CodedValueDomain)domain;

                    // Will be "Agriculture Food and Livestock FCode"'.
                    string name = codedValueDomain.GetName();

                    // Will be FieldType.String'.
                    FieldType fieldType = codedValueDomain.GetFieldType();

                    // Will be "The type of agriculture, food and livestock facility"'.
                    string description = codedValueDomain.GetDescription();

                    // Will be 13 since there are 13 code value pairs in this domain'.
                    int numberOfcodedValues = codedValueDomain.GetCount();

                    // This will be a the code value pairs sorted (in this case) by the codes' increasing integer value.
                    SortedList <object, string> codedValuePairs = codedValueDomain.GetCodedValuePairs();

                    FeatureClassDefinition siteAddressPointDefinition = geodatabase.GetDefinition <FeatureClassDefinition>("LocalGovernment.GDB.SiteAddressPoint");
                    int    unitTypeIndex         = siteAddressPointDefinition.FindField("UNITTYPE");
                    Field  unitTypeField         = siteAddressPointDefinition.GetFields()[unitTypeIndex];
                    Domain addressUnitTypeDomain = unitTypeField.GetDomain();

                    CodedValueDomain valueDomain = (CodedValueDomain)addressUnitTypeDomain;

                    // Will be Apartment.
                    string aptCodeDescription = valueDomain.GetName("APT");

                    // Will be Basement.
                    string bsmtCodeDescription = valueDomain.GetName("BSMT");

                    // Will be DEPT. Make sure you know the domain's FieldType is String before cast.
                    string departmentCode = valueDomain.GetCodedValue("Department") as string;

                    // Will be FL.
                    string floorCode = valueDomain.GetCodedValue("Floor") as string;
                }
        }
        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();
                                        }
                                    }
                                }
                            }
                        }
                    });
                }
            });
        }
예제 #23
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();
                                    }
                                }
                            }
                        }
                    }
                });
            }
        }