Пример #1
0
        private async Task <string> GetDomainValueAsync(string fieldName, string key)
        {
            try
            {
                IEnumerable <GDBProjectItem> gdbProjectItems = Project.Current.GetItems <GDBProjectItem>();
                return(await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
                {
                    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;

                            string geodatabasePath = geodatabase.GetPath();
                            if (geodatabasePath.Contains(ProSymbolEditorModule.WorkspaceString))
                            {
                                //Correct GDB, open the current selected feature class
                                _currentFeatureClass = geodatabase.OpenDataset <FeatureClass>(_currentFeatureClassName);
                                using (_currentFeatureClass)
                                {
                                    ArcGIS.Core.Data.FeatureClassDefinition facilitySiteDefinition = _currentFeatureClass.GetDefinition();
                                    IReadOnlyList <ArcGIS.Core.Data.Field> fields = facilitySiteDefinition.GetFields();

                                    ArcGIS.Core.Data.Field foundField = fields.FirstOrDefault(field => field.Name == fieldName);

                                    if (foundField != null)
                                    {
                                        CodedValueDomain domain = foundField.GetDomain() as CodedValueDomain;
                                        return domain.GetCodedValue(key).ToString();
                                    }
                                }

                                break;
                            }
                        }
                    }

                    return "";
                }));
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.ToString());
            }

            return(null);
        }
        private async Task <bool> ShouldAddInBeEnabledAsync()
        {
            //If we can get the database, then enable the add-in
            if (Project.Current == null)
            {
                //No open project
                return(false);
            }

            //Get database
            try
            {
                IEnumerable <GDBProjectItem> gdbProjectItems = Project.Current.GetItems <GDBProjectItem>();
                Geodatabase militaryGeodatabase = await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
                {
                    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;

                            string geodatabasePath = geodatabase.GetPath();
                            if (geodatabasePath.Contains(WorkspaceString))
                            {
                                return(geodatabase);
                            }
                        }
                    }

                    return(null);
                });


                if (militaryGeodatabase == null)
                {
                    return(false);
                }
            }
            catch (Exception exception)
            {
                System.Console.WriteLine(exception.Message);
                return(false);
            }

            return(true);
        }
Пример #3
0
        private async void GetMilitaryDomainsAsync()
        {
            try
            {
                IEnumerable <GDBProjectItem> gdbProjectItems = Project.Current.GetItems <GDBProjectItem>();
                await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
                {
                    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;

                            string geodatabasePath = geodatabase.GetPath();
                            if (geodatabasePath.Contains(ProSymbolEditorModule.WorkspaceString))
                            {
                                //Correct GDB, open the current selected feature class
                                _currentFeatureClass = geodatabase.OpenDataset <FeatureClass>(_currentFeatureClassName);
                                using (_currentFeatureClass)
                                {
                                    ArcGIS.Core.Data.FeatureClassDefinition facilitySiteDefinition = _currentFeatureClass.GetDefinition();
                                    IReadOnlyList <ArcGIS.Core.Data.Field> fields = facilitySiteDefinition.GetFields();

                                    MilitaryFieldsInspectorModel.PopulateDomains(fields);
                                    MilitaryFieldsInspectorModel.CheckLabelFieldsExistence(fields);
                                }

                                break;
                            }
                        }
                    }
                });

                //Check for affiliation tag
                string identityCode = "";
                if (_selectedStyleItem.Tags.ToUpper().Contains("FRIEND"))
                {
                    identityCode = await GetDomainValueAsync("identity", "Friend");
                }
                else if (_selectedStyleItem.Tags.ToUpper().Contains("HOSTILE"))
                {
                    identityCode = await GetDomainValueAsync("identity", "Hostile/Faker");
                }
                else if (_selectedStyleItem.Tags.ToUpper().Contains("NEUTRAL"))
                {
                    identityCode = await GetDomainValueAsync("identity", "Neutral");
                }
                else if (_selectedStyleItem.Tags.ToUpper().Contains("UNKNOWN"))
                {
                    identityCode = await GetDomainValueAsync("identity", "Unknown");
                }

                if (identityCode != "")
                {
                    foreach (DomainCodedValuePair dcvp in MilitaryFieldsInspectorModel.IdentityDomainValues)
                    {
                        if (dcvp.Code.ToString() == identityCode)
                        {
                            SymbolAttributeSet.SelectedIdentityDomainPair = dcvp;
                            break;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.ToString());
            }
        }
Пример #4
0
        public async void CreateNewFeatureAsync(object parameter)
        {
            string message        = String.Empty;
            bool   creationResult = false;

            //Generate geometry if polygon or polyline, if adding new feature is from using coordinates and not the map tool
            if (Convert.ToBoolean(parameter) == true)
            {
                if (GeometryType == GeometryType.Polyline || GeometryType == GeometryType.Polygon)
                {
                    GeneratePolyGeometry();
                }
            }

            IEnumerable <GDBProjectItem> gdbProjectItems = Project.Current.GetItems <GDBProjectItem>();
            await QueuedTask.Run(() =>
            {
                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.

                        string geodatabasePath = geodatabase.GetPath();
                        if (geodatabasePath.Contains(ProSymbolEditorModule.WorkspaceString))
                        {
                            //Correct GDB, open the current selected feature class
                            FeatureClass featureClass = geodatabase.OpenDataset <FeatureClass>(_currentFeatureClassName);
                            using (featureClass)
                                using (FeatureClassDefinition facilitySiteDefinition = featureClass.GetDefinition())
                                {
                                    EditOperation editOperation = new EditOperation();
                                    editOperation.Name          = "Military Symbol Insert";
                                    editOperation.Callback(context =>
                                    {
                                        try
                                        {
                                            RowBuffer rowBuffer = featureClass.CreateRowBuffer();
                                            _symbolAttributeSet.PopulateRowBufferWithAttributes(ref rowBuffer);
                                            rowBuffer["Shape"] = GeometryEngine.Project(MapGeometry, facilitySiteDefinition.GetSpatialReference());

                                            Feature feature = featureClass.CreateRow(rowBuffer);
                                            feature.Store();

                                            //To Indicate that the attribute table has to be updated
                                            context.Invalidate(feature);
                                        }
                                        catch (GeodatabaseException geodatabaseException)
                                        {
                                            message = geodatabaseException.Message;
                                        }
                                    }, featureClass);

                                    var task       = editOperation.ExecuteAsync();
                                    creationResult = task.Result;
                                    if (!creationResult)
                                    {
                                        message = editOperation.ErrorMessage;
                                    }

                                    break;
                                }
                        }
                    }
                }
            });

            if (!creationResult)
            {
                MessageBox.Show(message);
            }
        }