Example #1
0
        ///// <summary>
        ///// 批量专题导出Excel
        ///// </summary>
        ///// <param name="pFeatureClass"></param>
        ///// <param name="listFileName"></param>
        ///// <param name="TypeName"></param>
        //public void BatchSubjectExport(IFeatureClass pFeatureClass, IList<string> listFileName, string TypeName, string fieldName)
        //{
        //    flag = 1;
        //    result = folderBrowerDialog.ShowDialog();
        //    for (int i = 0; i < listFileName.Count; i++)
        //    {
        //        Export(pFeatureClass, listFileName[i], TypeName, fieldName);
        //    }
        //    flag = 0;
        //}
        ///// <summary>
        ///// 批量导出该行政去内各种类型Excel
        ///// </summary>
        ///// <param name="ListFeatureClass"></param>
        ///// <param name="VillageName">行政区名称</param>
        ///// <param name="fieldName">统计字段名称</param>
        //public void BatchStatisticalChart(IList<IFeatureClass> ListFeatureClass, string VillageName, string fieldName)
        //{

        //    flag = 1;
        //    result = folderBrowerDialog.ShowDialog();
        //    for (int i = 0; i < ListFeatureClass.Count; i++)
        //    {
        //        ExportByFeartureClassName(ListFeatureClass[i], VillageName, fieldName);
        //    }
        //    flag = 0;
        //}
        ///// <summary>
        ///// 根据FeatureClass别名进行统计导出Excel表
        ///// </summary>
        ///// <param name="pFeatureClass"></param>
        ///// <param name="VillageName"></param>
        ///// <param name="fieldName"></param>
        //private void ExportByFeartureClassName(IFeatureClass pFeatureClass, string VillageName, string fieldName)
        //{
        //    switch (pFeatureClass.AliasName)
        //    {
        //        case "DATASYS.DATONG_LDGH":
        //            string fileName = VillageName + "镇(乡)林地规划统计表";
        //            Export(pFeatureClass, fileName, "林地类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_LYYDFB":
        //            fileName = VillageName + "镇(乡)林业用地分布统计表";
        //            Export(pFeatureClass, fileName, "类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_BAOHU_DJ":
        //            fileName = VillageName + "镇(乡)林地保护等级分布统计表";
        //            Export(pFeatureClass, fileName, "林地保护等级级别", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_ZDGNQ":
        //            fileName = VillageName + "镇(乡)林地主导功能区分布统计表";
        //            Export(pFeatureClass, fileName, "主导功能区类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_LDLY":
        //            fileName = VillageName + "镇(乡)林地利用现状统计表";
        //            Export(pFeatureClass, fileName, "林地利用现状类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_LDJG":
        //            fileName = VillageName + "镇(乡)林地结构现状统计表";
        //            Export(pFeatureClass, fileName, "林地结构类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_ZHILIANG_DJ":
        //            fileName = VillageName + "镇(乡)林地质量等级现状统计表";
        //            Export(pFeatureClass, fileName, "林地质量等级类型", fieldName);
        //            fileName = "";
        //            break;
        //        case "DATASYS.DATONG_LC":
        //            fileName = VillageName + "镇(乡)林场统计表";
        //            Export(pFeatureClass, fileName, "林场名称", fieldName);
        //            fileName = "";
        //            break;
        //    }
        //}
        /// <summary>
        /// 得到属性域的值
        /// </summary>
        /// <param name="TypeName">表字段名称</param>
        /// <param name="pFeatureClass">特征类</param>
        /// <returns>属性域字段</returns>
        private IList <string> GetDomainsName(string fieldName, IFeatureClass pFeatureClass)
        {
            IList <string> newList = new List <string>();

            newList = listString;
            IDataset          dataset          = pFeatureClass as IDataset;
            IWorkspace        workspace        = dataset.Workspace;
            IWorkspaceDomains workspaceDomains = (IWorkspaceDomains)workspace;
            int               indexField       = pFeatureClass.Fields.FindField(fieldName);
            IField            pField           = pFeatureClass.Fields.get_Field(indexField);
            IDomain           domain           = pField.Domain;
            ICodedValueDomain codeDomain       = (ICodedValueDomain)domain;

            for (int i = 0; i < codeDomain.CodeCount; i++)
            {
                for (int j = 0; j < listString.Count; j++)
                {
                    if (listString[j] == codeDomain.get_Value(i).ToString())
                    {
                        newList[j] = codeDomain.get_Name(i).ToString();
                    }
                }
            }
            return(newList);
        }
Example #2
0
        private void frmExtendDomain_Load(object sender, EventArgs e)
        {
            IWorkspaceDomains domains = this.iworkspace_0 as IWorkspaceDomains;

            if (this.iworkspace_0 != null)
            {
                IEnumDomain domain = domains.Domains;
                string[]    items  = new string[2];
                if (domain != null)
                {
                    domain.Reset();
                    for (IDomain domain2 = domain.Next(); domain2 != null; domain2 = domain.Next())
                    {
                        if (domain2 is IJLKCodeValueDomain)
                        {
                            items[0] = domain2.Name;
                            items[1] = domain2.Description;
                            ListViewItem item = new ListViewItem(items)
                            {
                                Tag = new Class3(domain2)
                            };
                            this.ilist_0.Add(item.Tag);
                            this.DomainListView.Items.Add(item);
                        }
                    }
                }
            }
        }
Example #3
0
            public DomainConstraints([NotNull] IWorkspaceDomains domains,
                                     bool allowNullForCodedValueDomains,
                                     bool allowNullForRangeDomains)
            {
                Assert.ArgumentNotNull(domains, nameof(domains));

                _domains = domains;
                _allowNullForCodedValueDomains = allowNullForCodedValueDomains;
                _allowNullForRangeDomains      = allowNullForRangeDomains;
            }
Example #4
0
        private static void UpdateCodedValueDomain(IWorkspace theWorkspace, string DomainName, string SourceClassName, string CodeFieldName, string ValueFieldName)
        {
            // Get reference to the table to read codes and values from
            ITable theTable = commonFunctions.OpenTable(theWorkspace, SourceClassName);

            // Get reference to the domain itself
            IWorkspaceDomains wsDomains = (IWorkspaceDomains)theWorkspace;
            ICodedValueDomain theDomain = (ICodedValueDomain)wsDomains.get_DomainByName(DomainName);

            // Requires exclusive schema lock
            ISchemaLock schemaLock = (ISchemaLock)theDomain;

            try
            {
                // Get an exclusive lock
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Clear everything out of the domain first
                int codedValues = theDomain.CodeCount;
                for (int i = 0; i <= codedValues - 1; i++)
                {
                    theDomain.DeleteCode(theDomain.Value[0]);
                }

                // Sort the table
                ITableSort tableSorter = new TableSortClass();
                tableSorter.Fields = ValueFieldName;
                tableSorter.set_Ascending(ValueFieldName, true);
                tableSorter.Table = theTable;
                tableSorter.Sort(null);

                // Loop through the sorted rows, add to the domain
                int codeFld  = theTable.FindField(CodeFieldName);
                int valueFld = theTable.FindField(ValueFieldName);

                ICursor theCursor = tableSorter.Rows;
                IRow    theRow    = theCursor.NextRow();

                while (theRow != null)
                {
                    theDomain.AddCode(theRow.get_Value(codeFld), theRow.get_Value(valueFld).ToString());
                    theRow = theCursor.NextRow();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(DomainName + " was not updated. This is likely because an exclusive schema lock could not be obtained.", "NCGMP Tools");
            }
            finally
            {
                // Release the exclusive lock, if it was acquired.
                //  This block of code (finally) is called whether or not there is a problem
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }
Example #5
0
        public static bool ExistDomain(IWorkspace workspace, string name)
        {
            IWorkspaceDomains pWorkspaceDomains = workspace as IWorkspaceDomains;

            if (pWorkspaceDomains == null)
            {
                return(false);
            }
            IDomain pDomain = pWorkspaceDomains.DomainByName[name];

            return(pDomain != null);
        }
Example #6
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            IWorkspaceDomains domains = this.iworkspace_0 as IWorkspaceDomains;

            if (domains != null)
            {
                for (int i = 0; i < this.ilist_0.Count; i++)
                {
                    (this.ilist_0[i] as Class3).Apply(domains);
                }
            }
        }
        protected override void OnClick()
        {
            IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactory();

            IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(@"D:\Applications\ArcObjects\TestButton\GeoDP\GeoDB.gdb", ArcMap.Application.hWnd);

            IWorkspaceDomains pWorkspaceDomains = pWorkspace as IWorkspaceDomains;
            ICodedValueDomain pDomain           = pWorkspaceDomains.DomainByName["Resturants"] as ICodedValueDomain;

            for (int i = 0; i < pDomain.CodeCount; i++)
            {
                MessageBox.Show("Code: " + pDomain.Value[i] + Environment.NewLine + "Description: " + pDomain.Name[i]);
            }
        }
Example #8
0
 //复制工作空间坐标空间域
 private void CreateWorkspaceDomains(IWorkspace pWs1, IWorkspace pWs2)
 {
     try
     {
         WaitForm.SetCaption("正在复制工作空间域,请稍后...");
         IWorkspaceDomains pWsD1       = pWs1 as IWorkspaceDomains;
         IWorkspaceDomains pWsD2       = pWs2 as IWorkspaceDomains;
         IEnumDomain       pEnumDomain = pWsD1.Domains;
         IDomain           pDomain1    = null;
         IDomain           pDomain2    = null;
         if (pEnumDomain == null)
         {
             return;
         }
         while ((pDomain1 = pEnumDomain.Next()) != null)
         {
             if (pDomain1.Type == esriDomainType.esriDTCodedValue)//编码域
             {
                 ICodedValueDomain tempDomain1 = pDomain1 as ICodedValueDomain;
                 ICodedValueDomain tempDomain2 = new CodedValueDomainClass();
                 for (int i = 0; i < tempDomain1.CodeCount; i++)
                 {
                     tempDomain2.AddCode(tempDomain1.get_Value(i), tempDomain1.get_Name(i));
                 }
                 pDomain2             = tempDomain2 as IDomain;
                 pDomain2.Description = pDomain1.Description;
                 pDomain2.FieldType   = pDomain1.FieldType;
                 pDomain2.DomainID    = pDomain1.DomainID;
                 pDomain2.MergePolicy = pDomain1.MergePolicy;
                 pDomain2.Name        = pDomain1.Name;
                 pDomain2.Owner       = pDomain1.Owner;
                 pDomain2.SplitPolicy = pDomain1.SplitPolicy;
                 pWsD2.AddDomain(pDomain2);
             }
             else//范围域
             {
                 IRangeDomain tempDomain1 = pDomain1 as IRangeDomain;
                 IRangeDomain tempDomain2 = new RangeDomainClass();
                 tempDomain2.MaxValue = tempDomain1.MaxValue;
                 tempDomain2.MinValue = tempDomain1.MinValue;
                 pDomain2             = tempDomain2 as IDomain;
                 pWsD2.AddDomain(pDomain2);
             }
         }
     }
     catch (System.Exception ex)
     {
         return;
     }
 }
Example #9
0
 public void Apply(IWorkspaceDomains iworkspaceDomains_0)
 {
     try
     {
         if (this.bool_1)
         {
             if (!this.bool_0)
             {
                 iworkspaceDomains_0.DeleteDomain(this.string_0);
             }
         }
         else if (this.bool_0)
         {
             iworkspaceDomains_0.AddDomain(this.idomain_1);
         }
         else if (this.bool_2)
         {
             if (this.idomain_0 != null)
             {
                 iworkspaceDomains_0.DeleteDomain(this.idomain_0.Name);
                 (iworkspaceDomains_0 as IWorkspaceDomains2).AddDomain(this.idomain_1);
             }
             else
             {
                 (iworkspaceDomains_0 as IWorkspaceDomains2).AlterDomain(this.idomain_1);
             }
         }
     }
     catch (COMException exception)
     {
         if (exception.ErrorCode == -2147220969)
         {
             MessageBox.Show("非数据库所有者,无法修改域值!");
         }
         else
         {
             Logger.Current.Error("", exception, "");
         }
     }
     catch (Exception exception2)
     {
         Logger.Current.Error("", exception2, "");
     }
     this.bool_0 = false;
     this.bool_1 = false;
     this.bool_2 = false;
 }
Example #10
0
        protected override void OnClick()
        {
            //
            //  TODO: Sample code showing how to access button host
            //
            IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactory();
            IWorkspace        pWorkspace        = pWorkspaceFactory.OpenFromFile(@"C:\IGeometry\IGeometryGDB\IGeometry.gdb", ArcMap.Application.hWnd);

            IWorkspaceDomains pWorkspaceDomains = pWorkspace as IWorkspaceDomains;
            ICodedValueDomain pDomain           = pWorkspaceDomains.DomainByName["RestaurantTypes"] as ICodedValueDomain;

            for (int i = 0; i < pDomain.CodeCount; i++)
            {
                MessageBox.Show("Code: " + pDomain.Value[i] + Environment.NewLine + "Description: " + pDomain.Name[i]);
            }

            ArcMap.Application.CurrentTool = null;
        }
Example #11
0
        public static IDomain AddDomain(IWorkspace workspace, IDomain domain)
        {
            if (domain == null)
            {
                return(null);
            }
            IWorkspaceDomains pWorkspaceDomains = workspace as IWorkspaceDomains;

            if (pWorkspaceDomains == null)
            {
                return(null);
            }
            IDomain pDomain = pWorkspaceDomains.DomainByName[domain.Name];

            if (pDomain != null)
            {
                return(pDomain);
            }
            if (domain.Type == esriDomainType.esriDTCodedValue)
            {
                ICodedValueDomain pCodedValueDomain       = new CodedValueDomainClass();
                ICodedValueDomain pOriginCodedValueDomain = domain as ICodedValueDomain;
                for (int i = 0; i < pOriginCodedValueDomain.CodeCount; i++)
                {
                    pCodedValueDomain.AddCode(pOriginCodedValueDomain.Value[i], pOriginCodedValueDomain.Name[i]);
                }
                pDomain = pCodedValueDomain as IDomain;
            }
            else
            {
                IRangeDomain pRangeDomain       = new RangeDomainClass();
                IRangeDomain pOriginRangeDomain = domain as IRangeDomain;
                pRangeDomain.MinValue = pOriginRangeDomain.MinValue;
                pRangeDomain.MaxValue = pOriginRangeDomain.MaxValue;
                pDomain = pRangeDomain as IDomain;
            }
            pDomain.Name        = domain.Name;
            pDomain.FieldType   = domain.FieldType;
            pDomain.Description = domain.Description;
            pDomain.SplitPolicy = esriSplitPolicyType.esriSPTDuplicate;
            pDomain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;
            pWorkspaceDomains.AddDomain(pDomain);
            return(pDomain);
        }
Example #12
0
        /// <summary>
        /// 创建属性域
        /// </summary>
        /// <param name="workspace">工作空间</param>
        /// <param name="strDomainName">属性域名称</param>
        /// <param name="dicDomainItems">属性域的项</param>
        public static void CreateDomain(this IWorkspace workspace, string strDomainName, Dictionary <string, string> dicDomainItems)
        {
            IWorkspaceDomains wsDomains       = (IWorkspaceDomains)workspace;
            ICodedValueDomain codeValueDomain = new CodedValueDomainClass();

            foreach (KeyValuePair <string, string> domainItem in dicDomainItems)
            {
                codeValueDomain.AddCode(domainItem.Key, domainItem.Value);
            }

            IDomain domain = (IDomain)codeValueDomain;

            domain.Name        = strDomainName;
            domain.FieldType   = esriFieldType.esriFieldTypeString;
            domain.SplitPolicy = esriSplitPolicyType.esriSPTDuplicate;
            domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;

            wsDomains.AddDomain(domain);
        }
Example #13
0
        private static IDomain GetOrCreateDomain(IWorkspace ws)
        {
            IWorkspaceDomains wsd    = ws as IWorkspaceDomains;
            IDomain           domain = wsd.get_DomainByName(DOMAIN_NAME);

            if (domain == null)
            {
                ICodedValueDomain2 cvd = new CodedValueDomain() as ICodedValueDomain2;
                cvd.AddCode(1, "New Feature");
                cvd.AddCode(2, "Modified Feature");
                cvd.AddCode(3, "Modified Feature (After)");
                cvd.AddCode(6, "Modified Feature (Before)");
                cvd.AddCode(4, "Deleted Feature");
                domain             = cvd as IDomain;
                domain.FieldType   = esriFieldType.esriFieldTypeInteger;
                domain.Name        = DOMAIN_NAME;
                domain.SplitPolicy = esriSplitPolicyType.esriSPTDuplicate;
                domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;
                int i = wsd.AddDomain(domain);
            }
            return(domain);
        }
Example #14
0
        /// <summary>
        /// Creates vessel type coded domain.
        /// </summary>
        /// <param name="pWorkspace">FileGeodatabase workspace.</param>
        private void CreateTypeDomain(IWorkspace pWorkspace)
        {
            try
            {
                if (!(IsArcInfoLicense()))
                {
                    return;
                }

                IFeatureWorkspace pFWS   = (IFeatureWorkspace)pWorkspace;
                ITable            pTable = pFWS.OpenTable("Vessel");

                IWorkspaceDomains pWSD             = (IWorkspaceDomains)pWorkspace;
                ICodedValueDomain codedValueDomain = new CodedValueDomainClass();
                int i;

                //VESSEL TYPE DOMAIN
                // Value and name pairs.
                for (i = 0; i <= 9; i++)
                {
                    codedValueDomain.AddCode(i, "Not Available");
                }
                for (i = 10; i <= 19; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }
                for (i = 20; i <= 29; i++)
                {
                    codedValueDomain.AddCode(i, "WIG");
                }
                codedValueDomain.AddCode(30, "Fishing");
                codedValueDomain.AddCode(31, "Towing");
                codedValueDomain.AddCode(32, "Towing and length of the tow exceeds 200 m or breadth exceeds 25 m");
                codedValueDomain.AddCode(33, "Engaged in dredging or underwater operations");
                codedValueDomain.AddCode(34, "Engaged in diving operations");
                codedValueDomain.AddCode(35, "Engaged in military operations");
                codedValueDomain.AddCode(36, "Sailing");
                codedValueDomain.AddCode(37, "Pleasure craft");
                codedValueDomain.AddCode(38, "Reserved for future use");
                codedValueDomain.AddCode(39, "Reserved for future use");
                for (i = 40; i <= 49; i++)
                {
                    codedValueDomain.AddCode(i, "HSC");
                }
                codedValueDomain.AddCode(50, "Pilot vessel");
                codedValueDomain.AddCode(51, "Search and rescue vessels");
                codedValueDomain.AddCode(52, "Tugs");
                codedValueDomain.AddCode(53, "Port tenders");
                codedValueDomain.AddCode(54, "Vessels with anti-pollution facilities or equipment");
                codedValueDomain.AddCode(55, "Law enforcement vessels");
                codedValueDomain.AddCode(56, "Spare - for assignments to local vessels");
                codedValueDomain.AddCode(57, "Spare - for assignments to local vessels");
                codedValueDomain.AddCode(58, "Medical transports (as defined in the 1949 Geneva Conventions and Additional Protocols)");
                codedValueDomain.AddCode(59, "Ships according to RR Resolution No. 18 (Mob-83)");
                for (i = 60; i <= 69; i++)
                {
                    codedValueDomain.AddCode(i, "Passenger ships");
                }
                for (i = 70; i <= 79; i++)
                {
                    codedValueDomain.AddCode(i, "Cargo ships");
                }
                for (i = 80; i <= 89; i++)
                {
                    codedValueDomain.AddCode(i, "Tanker(s)");
                }
                for (i = 90; i <= 99; i++)
                {
                    codedValueDomain.AddCode(i, "Other types of ship");
                }
                for (i = 100; i <= 199; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved, for regional use");
                }
                for (i = 200; i <= 255; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved, for future use");
                }

                // The code to set the common properties for the new coded value domain.
                IDomain domain = (IDomain)codedValueDomain;
                domain.Name        = "VesselType";
                domain.FieldType   = esriFieldType.esriFieldTypeInteger;
                domain.SplitPolicy = esriSplitPolicyType.esriSPTDefaultValue;
                domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;

                // Add the new domain to the workspace.
                pWSD.AddDomain(domain);

                //assign the domain to the vessel table VesselType field
                IFields pFields     = pTable.Fields;
                int     iFieldIndex = pTable.FindField("VesselType");
                IField  pField      = pFields.get_Field(iFieldIndex);

                // Check that the field and domain have the same field type.
                if (pField.Type == domain.FieldType)
                {
                    // Cast the feature class to the ISchemaLock and IClassSchemaEdit interfaces.
                    ISchemaLock      schemaLock      = (ISchemaLock)pTable;
                    IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pTable;

                    // Attempt to get an exclusive schema lock.
                    try
                    {
                        // Lock the class and alter the domain.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                        classSchemaEdit.AlterDomain("VesselType", domain);
                    }
                    catch (Exception exc)
                    {
                        // Handle the exception in a way appropriate for the application.
                        MessageBox.Show(exc.Message);
                    }
                    finally
                    {
                        // Set the schema lock to be a shared lock.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "AIS_DataModel:CodedDomain:CreateTypeDomain");
            }
        }
Example #15
0
        /// <summary>
        /// Creates Broadcast feature class Status coded domain.
        /// </summary>
        /// <param name="pWorkspace">FileGeodatabase workspace.</param>
        private void CreateStatusDomain(IWorkspace pWorkspace)
        {
            try
            {
                if (!(IsArcInfoLicense()))
                {
                    return;
                }

                IFeatureWorkspace pFWS = (IFeatureWorkspace)pWorkspace;
                IFeatureClass     pFC  = pFWS.OpenFeatureClass("Broadcast");

                IWorkspaceDomains pWSD             = (IWorkspaceDomains)pWorkspace;
                ICodedValueDomain codedValueDomain = new CodedValueDomainClass();

                //VESSEL STATUS DOMAIN
                // Value and name pairs.
                codedValueDomain.AddCode(0, "Under way using engine");
                codedValueDomain.AddCode(1, "At anchor");
                codedValueDomain.AddCode(2, "Not under command");
                codedValueDomain.AddCode(3, "Restricted maneuverability");
                codedValueDomain.AddCode(4, "Constrained by her draught");
                codedValueDomain.AddCode(5, "Moored");
                codedValueDomain.AddCode(6, "Aground");
                codedValueDomain.AddCode(7, "Fishing");
                codedValueDomain.AddCode(8, "Under way sailing");
                codedValueDomain.AddCode(9, "Reserved for future amendment of navigational status for ships carrying DG, HS, or MP, or IMO hazard or pollutant category C, high speed craft (HSC)");
                codedValueDomain.AddCode(10, "Reserved for future amendment of navigational status for ships carrying dangerous goods (DG), harmful substances (HS) or marine pollutants (MP), or IMO hazard or pollutant category A, wing in grand (WIG)");
                codedValueDomain.AddCode(11, "Reserved for future use");
                codedValueDomain.AddCode(12, "Reserved for future use");
                codedValueDomain.AddCode(13, "Reserved for future use");
                codedValueDomain.AddCode(14, "AIS-START (active)");
                codedValueDomain.AddCode(15, "Not-Defined");


                // The code to set the common properties for the new coded value domain.
                IDomain domain = (IDomain)codedValueDomain;
                domain.Name        = "Status";
                domain.FieldType   = esriFieldType.esriFieldTypeInteger;
                domain.SplitPolicy = esriSplitPolicyType.esriSPTDefaultValue;
                domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;

                // Add the new domain to the workspace.
                pWSD.AddDomain(domain);

                //assign the domain to the broadcast feature class status field
                IFields pFields     = pFC.Fields;
                int     iFieldIndex = pFC.FindField("Status");
                IField  pField      = pFields.get_Field(iFieldIndex);

                // Check that the field and domain have the same field type.
                if (pField.Type == domain.FieldType)
                {
                    // Cast the feature class to the ISchemaLock and IClassSchemaEdit interfaces.
                    ISchemaLock      schemaLock      = (ISchemaLock)pFC;
                    IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pFC;

                    // Attempt to get an exclusive schema lock.
                    try
                    {
                        // Lock the class and alter the domain.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                        classSchemaEdit.AlterDomain("Status", domain);
                    }
                    catch (Exception exc)
                    {
                        // Handle the exception in a way appropriate for the application.
                        MessageBox.Show(exc.Message);
                    }
                    finally
                    {
                        // Set the schema lock to be a shared lock.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "AIS_DataModel:CodedDomain:CreateStatusDomain");
            }
        }
Example #16
0
        /// <summary>
        /// Creates Cargo type Voyage workspace.
        /// </summary>
        /// <param name="pWorkspace">FileGeodatabase workspace.</param>
        private void CreateCargoDomain(IWorkspace pWorkspace)
        {
            try
            {
                if (!(IsArcInfoLicense()))
                {
                    return;
                }

                IFeatureWorkspace pFWS   = (IFeatureWorkspace)pWorkspace;
                ITable            pTable = pFWS.OpenTable("Voyage");

                IWorkspaceDomains pWSD             = (IWorkspaceDomains)pWorkspace;
                ICodedValueDomain codedValueDomain = new CodedValueDomainClass();
                int i;

                //VESSEL CARGO DOMAIN
                // Value and name pairs.

                for (i = 0; i <= 9; i++)
                {
                    codedValueDomain.AddCode(i, "Not Available");
                }
                for (i = 10; i <= 19; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 20; i <= 90; i += 10)
                {
                    codedValueDomain.AddCode(i, "Not Available");
                }

                for (i = 21; i <= 81; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category A");
                }
                for (i = 22; i <= 82; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category B");
                }
                for (i = 23; i <= 83; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category C");
                }
                for (i = 24; i <= 84; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category D");
                }
                for (i = 29; i <= 89; i += 20)
                {
                    codedValueDomain.AddCode(i, "No additional information");
                }

                for (i = 25; i <= 28; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 31; i <= 39; i++)
                {
                    codedValueDomain.AddCode(i, "Not Available");
                }

                for (i = 45; i <= 48; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 51; i <= 59; i++)
                {
                    codedValueDomain.AddCode(i, "Not Available");
                }

                for (i = 65; i <= 68; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 71; i <= 91; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category A");
                }
                for (i = 72; i <= 92; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category B");
                }
                for (i = 73; i <= 93; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category C");
                }
                for (i = 74; i <= 94; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category D");
                }
                for (i = 79; i <= 99; i += 20)
                {
                    codedValueDomain.AddCode(i, "No additional information");
                }

                for (i = 75; i <= 78; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 85; i <= 88; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 95; i <= 98; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 100; i <= 199; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved, for regional use");
                }
                for (i = 200; i <= 255; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved, for future use");
                }

                // The code to set the common properties for the new coded value domain.
                IDomain domain = (IDomain)codedValueDomain;
                domain.Name        = "Cargo";
                domain.FieldType   = esriFieldType.esriFieldTypeInteger;
                domain.SplitPolicy = esriSplitPolicyType.esriSPTDefaultValue;
                domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;

                // Add the new domain to the workspace.
                pWSD.AddDomain(domain);

                //assign the domain to the voyage table cargo field
                IFields pFields     = pTable.Fields;
                int     iFieldIndex = pTable.FindField("Cargo");
                IField  pField      = pFields.get_Field(iFieldIndex);

                // Check that the field and domain have the same field type.
                if (pField.Type == domain.FieldType)
                {
                    // Cast the feature class to the ISchemaLock and IClassSchemaEdit interfaces.
                    ISchemaLock      schemaLock      = (ISchemaLock)pTable;
                    IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pTable;

                    // Attempt to get an exclusive schema lock.
                    try
                    {
                        // Lock the class and alter the domain.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                        classSchemaEdit.AlterDomain("Cargo", domain);
                    }
                    catch (Exception exc)
                    {
                        // Handle the exception in a way appropriate for the application.
                        MessageBox.Show(exc.Message);
                    }
                    finally
                    {
                        // Set the schema lock to be a shared lock.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "AIS_DataModel:CodedDomain:CreateCargoDomain");
            }
        }
Example #17
0
        /// <summary>
        /// Adds coded domain values to the Voyage Tracks feature class.
        /// </summary>
        /// <param name="sWorkspace"></param>
        /// <param name="sLayerName"></param>
        private void AddCodedDomain(string sWorkspace, string sLayerName)
        {
            try
            {
                IWorkspace    pWorkspace = clsStatic.OpenWorkspace(sWorkspace);
                IFeatureLayer pFL        = clsStatic.GetFeatureLayer(pWorkspace, sLayerName); // pFWS.OpenTable("Voyage");
                ITable        pTable     = (ITable)pFL.FeatureClass;

                IWorkspaceDomains pWSD             = (IWorkspaceDomains)pWorkspace;
                ICodedValueDomain codedValueDomain = new CodedValueDomainClass();
                IEnumDomain       pDomains         = pWSD.Domains;
                pDomains.Reset();
                IDomain pDomain = pDomains.Next();
                while (pDomain != null)
                {
                    if (pDomain.Name == "Cargo")
                    {
                        break;
                    }
                }
                if (pDomain == null)
                {
                    if (clsStatic.GetArcLicense())
                    {
                        //VESSEL CARGO DOMAIN
                        // Value and name pairs.
                        for (int i = 0; i <= 9; i++)
                        {
                            codedValueDomain.AddCode(i, "Not Available");
                        }
                        for (int i = 10; i <= 19; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 20; i <= 90; i += 10)
                        {
                            codedValueDomain.AddCode(i, "Not Available");
                        }

                        for (int i = 21; i <= 81; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category A");
                        }
                        for (int i = 22; i <= 82; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category B");
                        }
                        for (int i = 23; i <= 83; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category C");
                        }
                        for (int i = 24; i <= 84; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category D");
                        }
                        for (int i = 29; i <= 89; i += 20)
                        {
                            codedValueDomain.AddCode(i, "No additional information");
                        }

                        for (int i = 25; i <= 28; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 31; i <= 39; i++)
                        {
                            codedValueDomain.AddCode(i, "Not Available");
                        }

                        for (int i = 45; i <= 48; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 51; i <= 59; i++)
                        {
                            codedValueDomain.AddCode(i, "Not Available");
                        }

                        for (int i = 65; i <= 68; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 71; i <= 91; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category A");
                        }
                        for (int i = 72; i <= 92; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category B");
                        }
                        for (int i = 73; i <= 93; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category C");
                        }
                        for (int i = 74; i <= 94; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category D");
                        }
                        for (int i = 79; i <= 99; i += 20)
                        {
                            codedValueDomain.AddCode(i, "No additional information");
                        }

                        for (int i = 75; i <= 78; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 85; i <= 88; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 95; i <= 98; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 100; i <= 199; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved, for regional use");
                        }
                        for (int i = 200; i <= 255; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved, for future use");
                        }

                        // The code to set the common properties for the new coded value domain.
                        pDomain             = (IDomain)codedValueDomain;
                        pDomain.Name        = "Cargo";
                        pDomain.FieldType   = esriFieldType.esriFieldTypeInteger;
                        pDomain.SplitPolicy = esriSplitPolicyType.esriSPTDefaultValue;
                        pDomain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;
                        // Add the new domain to the workspace.
                        pWSD.AddDomain(pDomain);
                    }
                }
                //assign the domain to the voyage table cargo field
                IFields pFields     = pTable.Fields;
                int     iFieldIndex = pTable.FindField("Cargo");
                IField  pField      = pFields.get_Field(iFieldIndex);

                // Check that the field and domain have the same field type.
                if (pField.Type == pDomain.FieldType)
                {
                    // Cast the feature class to the ISchemaLock and IClassSchemaEdit interfaces.
                    ISchemaLock      schemaLock      = (ISchemaLock)pTable;
                    IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pTable;

                    // Attempt to get an exclusive schema lock.
                    try
                    {
                        // Lock the class and alter the domain.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                        classSchemaEdit.AlterDomain("Cargo", pDomain);
                    }
                    catch (Exception ex)
                    {
                        // Handle the exception in a way appropriate for the application.
                        clsStatic.ShowErrorMessage(ex.ToString());
                    }
                    finally
                    {
                        // Set the schema lock to be a shared lock.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                }
            }
            catch (Exception ex)
            {
                clsStatic.ShowErrorMessage(ex.ToString());
            }
        }
Example #18
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            if (txtBoxExcelPath.Text == "")
            {
                MessageBox.Show("请选择导入的外业调查表!");
                return;
            }
            string strExcelPath = this.txtBoxExcelPath.Text;

            ExcelHelper elh = new ExcelHelper(strExcelPath);

            Microsoft.Office.Interop.Excel.Worksheet sheet = elh.excelApp.Worksheets[1] as Microsoft.Office.Interop.Excel.Worksheet;
            sheet.Columns.EntireColumn.AutoFit();   //自动调整列宽  added by chulili 2012-11-29


            IFeatureClass pFeatureClass = m_pCurFeaCls;
            IWorkspace    pws           = (pFeatureClass as IDataset).Workspace;

            string strKeyChineseName = cmbKeyField.Text;
            string strKeyFieldName   = "";
            int    indexKeyField     = -1;

            if (_DicFieds.ContainsKey(strKeyChineseName))
            {
                indexKeyField   = _DicFieds[strKeyChineseName];
                strKeyFieldName = m_pCurFeaCls.Fields.get_Field(indexKeyField).Name;
            }

            IField pKeyField = pFeatureClass.Fields.get_Field(indexKeyField);

            IWorkspaceDomains pWorkSpaceDomains = pws as IWorkspaceDomains;
            ICodedValueDomain pCodedDomain      = new CodedValueDomainClass();
            int iNullRowCnt = 0;
            int iNullCnt    = 0;

            for (int i = 2; i <= sheet.UsedRange.Rows.Count; i++)
            {
                Exception er = null;

                string sql = "";
                iNullCnt = 0;

                object objcode  = ((Microsoft.Office.Interop.Excel.Range)sheet.UsedRange.Cells[i, 1]).Text; //对应行的该列的值
                string strcode  = objcode.ToString();
                object objvalue = ((Microsoft.Office.Interop.Excel.Range)sheet.UsedRange.Cells[i, 2]).Text; //对应行的该列的值
                string strvalue = objvalue.ToString();
                if (strcode == "")
                {
                    iNullRowCnt++;
                    if (iNullRowCnt > 10)
                    {
                        break;
                    }
                }
                else
                {
                    iNullRowCnt = 0;
                }
                pCodedDomain.AddCode(strcode, strvalue);
            }
            //pCodedDomain.AddCode("111", "纯林");
            //pCodedDomain.AddCode("112", "混交林");
            IDomain pDomain = pCodedDomain as IDomain;

            pDomain.Name        = pKeyField.Name + "domain2";
            pDomain.FieldType   = pKeyField.Type;
            pDomain.SplitPolicy = esriSplitPolicyType.esriSPTDuplicate;
            pDomain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;


            pWorkSpaceDomains.AddDomain(pDomain);

            ISchemaLock      schemaLock      = (ISchemaLock)pFeatureClass;
            IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pFeatureClass;

            try
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                classSchemaEdit.AlterDomain(pKeyField.Name, pDomain);
            }
            catch (Exception exc)
            {
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }

            sheet = null;
            elh.Close();
        }