Ejemplo n.º 1
0
        /// <summary>
        /// 创建矢量数据
        /// </summary>
        /// <param name="pWorkspace"></param>
        /// <returns></returns>
        public IFeatureClass CreateFeatureClassClass(IWorkspace pWorkspace, string strName, string strAliasName, IFields fields)
        {
            if (pWorkspace == null)
            {
                return(null);
            }
            IFeatureWorkspace featureWorkspace = pWorkspace as IFeatureWorkspace;

            if (featureWorkspace == null)
            {
                return(null);
            }

            IFeatureClass featureClass = null;

            try
            {
                featureClass = featureWorkspace.CreateFeatureClass(strName, fields, null, null, esriFeatureType.esriFTSimple, "SHAPE", null);
                if (!string.IsNullOrEmpty(strAliasName))
                {
                    IClassSchemaEdit classSchemaEdit = featureClass as IClassSchemaEdit;
                    if (null != classSchemaEdit)
                    {
                        classSchemaEdit.AlterAliasName(strAliasName);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(featureClass);
        }
Ejemplo n.º 2
0
        private void RenameClassObject(IDataset dsCurrent, int standardID)
        {
            if (dsCurrent == null)
            {
                return;
            }

            Hy.Check.Define.StandardLayer standardLayer = LayerReader.GetLayerByName(dsCurrent.Name, standardID);
            //string strAliasName = Hy.Check.Rule.Helper.LayerReader.GetAliasName(dsCurrent.Name, standardID);
            if (standardLayer != null)// dsCurrent.Name != strAliasName)
            {
                ISchemaLock schemaLock = dsCurrent as ISchemaLock;
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                IClassSchemaEdit classSchemaEdit = dsCurrent as IClassSchemaEdit;
                if (classSchemaEdit != null)
                {
                    classSchemaEdit.AlterAliasName(standardLayer.AliasName);

                    ITable tCurrent = dsCurrent as ITable;
                    if (tCurrent != null)
                    {
                        List <Hy.Check.Define.StandardField> fields = FieldReader.GetFieldsByLayer(standardLayer.ID);
                        for (int i = 0; i < fields.Count; i++)
                        {
                            if (tCurrent.Fields.FindField(fields[i].Name) > -1)
                            {
                                classSchemaEdit.AlterFieldAliasName(fields[i].Name, fields[i].AliasName);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建属性表
        /// </summary>
        /// <param name="pWorkspace"></param>
        /// <returns></returns>
        public ITable CreateTable(IWorkspace pWorkspace, string strName, string strAliasName, IFields fields)
        {
            if (pWorkspace == null)
            {
                return(null);
            }
            IFeatureWorkspace featureWorkspace = pWorkspace as IFeatureWorkspace;

            if (featureWorkspace == null)
            {
                return(null);
            }
            ITable table = null;

            try
            {
                table = featureWorkspace.CreateTable(strName, fields, null, null, null);
                if (!string.IsNullOrEmpty(strAliasName))
                {
                    IClassSchemaEdit classSchemaEdit = table as IClassSchemaEdit;
                    if (null != classSchemaEdit)
                    {
                        classSchemaEdit.RegisterAsObjectClass("OBJECTID", null);
                        classSchemaEdit.AlterAliasName(strAliasName);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(table);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Register the newly created table with the Geodatabase.
        /// </summary>
        /// <param name="pTable"></param>
        /// <param name="oidFieldName"></param>
        private static void RegisterWithGeodatabase(ITable pTable, string oidFieldName)
        {
            if (!(IsArcInfoLicense()))
            {
                return;
            }

            IObjectClass oc = (IObjectClass)pTable;

            if (oidFieldName == "")
            {
                oidFieldName = "OBJECTID";
            }
            // Attempt to acquire an exclusive schema lock for the object class.
            ISchemaLock schemaLock = (ISchemaLock)oc;

            try
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                // If this point is reached, the exclusive lock was acquired. We can cast the object
                // class to IClassSchemaEdit and call RegisterAsObjectClass.
                IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)oc;
                classSchemaEdit.RegisterAsObjectClass(oidFieldName, "");
            }
            catch (COMException comExc)
            {
                // Re-throw the exception.
                throw comExc;
            }
            finally
            {
                // Reset the lock on the object class to a shared lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        } // method RegisterWithGeodatabase
Ejemplo n.º 5
0
        } // doWork method

        protected void RegisterWithGeodatabase(
            IObjectClass objectClass,
            String oidFieldName)
        {
            if (oidFieldName == "")
            {
                oidFieldName = "OBJECTID";
            }
            // Attempt to acquire an exclusive schema lock for the object class.
            ISchemaLock schemaLock = (ISchemaLock)objectClass;

            try {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                // If this point is reached, the exclusive lock was acquired. We can cast the object
                // class to IClassSchemaEdit and call RegisterAsObjectClass.
                IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)objectClass;
                classSchemaEdit.RegisterAsObjectClass(oidFieldName, "");
            }
            catch (COMException comExc) {
                // Re-throw the exception.
                throw comExc;
            }
            finally {
                // Reset the lock on the object class to a shared lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        } // RegisterWithGeodatabase method
        /// <summary>
        /// This method attaches or detaches the "TabbedInspector" class extension to/from the specified
        /// feature class. If the featureclass already has an extension class, and it isn't the 'TabbedInspector' extension,
        /// the method does not modify the class extension.
        /// </summary>
        /// <param name="fc">The feature class to be altered.</param>
        /// <returns>Whether the operation succeeded (successful detach or attach).</returns>
        bool AlterClassExtension(IFeatureClass fc)
        {
            // Attempt to get access to schema-editing functionality on the feature class
            IClassSchemaEdit classSchemaEdit = fc as IClassSchemaEdit;

            if (classSchemaEdit == null)
            {
                m_appServices.SetStatusMessage("The selected feature class doesn't support attaching an extension class.", true);
                return(false);
            }

            // Create a UID object holding the TabbedInspector's CLSID
            UID classUID = new UIDClass();

            classUID.Value = "{" + TabbedInspector.TabbedInspectorCLSID + "}";

            // Do the schema update within a schema lock.
            bool succeeded = false;

            DoInSchemaLock(fc, delegate
            {
                // Does the feature class already have an extension class associated with it?
                if (fc.EXTCLSID != null)
                {
                    // The featureclass already has an extension attached.
                    if (fc.EXTCLSID.Value.Equals(classUID.Value))
                    {
                        // The extension is the TabbedInspector extension. Detach it.
                        classSchemaEdit.AlterClassExtensionCLSID(null, null);

                        m_appServices.SetStatusMessage(
                            string.Format("The 'custom inspector' extension class was detached from {0}.", fc.AliasName), false);
                        succeeded = true;
                    }
                    else
                    {
                        //Don't mess with featureclasses that have some other existing extension class associated with them.
                        m_appServices.SetStatusMessage(
                            string.Format("{0} already has another extension class attached to it. No change was made.", fc.AliasName), true);
                        succeeded = false;
                    }
                }
                else
                {
                    // There is no extension attached to the featureclass. Attach the TabbedInspector extension.
                    classSchemaEdit.AlterClassExtensionCLSID(classUID, null);
                    m_appServices.SetStatusMessage(
                        string.Format("The 'custom inspector' extension class was attached to {0}.", fc.AliasName), false);
                    succeeded = true;
                }
            });


            return(succeeded);
        }
Ejemplo n.º 7
0
        //更改要素类中字段模型名 函数
        public static bool AlterFieldModelName(IFeatureClass fc, string FieldName, string NewModelName)
        {
            bool             rbc    = false;
            ISchemaLock      sLock  = fc as ISchemaLock;
            IClassSchemaEdit csEdit = fc as IClassSchemaEdit;

            if (sLock != null && csEdit != null)
            {
                sLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                //改变要素类中字段模型名
                csEdit.AlterFieldModelName(FieldName, NewModelName);
                //释放锁定
                sLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                rbc = true;
            }
            return(rbc);
        }
Ejemplo n.º 8
0
        //更改要素类中字段默认值 函数
        public static bool AlterFieldDefaultValue(IFeatureClass fc, string FieldName, object defaultvalue)
        {
            bool             rbc    = false;
            ISchemaLock      sLock  = fc as ISchemaLock;
            IClassSchemaEdit csEdit = fc as IClassSchemaEdit;

            if (sLock != null && csEdit != null)
            {
                sLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                //改变要素类中字段别名
                csEdit.AlterDefaultValue(FieldName, defaultvalue);
                //释放锁定
                sLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                rbc = true;
            }
            return(rbc);
        }
Ejemplo n.º 9
0
        //更改表模型名 函数
        public static bool AlterModelName(ITable table, string NewModelName)
        {
            bool             rbc    = false;
            ISchemaLock      sLock  = table as ISchemaLock;
            IClassSchemaEdit csEdit = table as IClassSchemaEdit;

            if (sLock != null && csEdit != null)
            {
                sLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                //改变要素模型名
                csEdit.AlterModelName(NewModelName);
                //释放锁定
                sLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                rbc = true;
            }
            return(rbc);
        }
        public void IClassSchemaEdit_Example(IObjectClass objectClass)
        {
            //This function shows how you can use the IClassSchemaEdit
            //interface to alter the COM class extension for an object class.
            //cast for the IClassSchemaEdit
            IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)objectClass;
            //set and exclusive lock on the class
            ISchemaLock schemaLock = (ISchemaLock)objectClass;

            schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
            ESRI.ArcGIS.esriSystem.UID classUID = new ESRI.ArcGIS.esriSystem.UIDClass();
            //GUID for the C# project.
            classUID.Value = "{65a43962-8cc0-49c0-bfa3-015d0ff8350e}";
            classSchemaEdit.AlterClassExtensionCLSID(classUID, null);
            //release the exclusive lock
            schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 构建一个在要素集中的要素类
        /// </summary>
        /// <param name="targetWorkSpace">目标工作空间</param>
        /// <param name="DatasetName">要素集名</param>
        /// <param name="FcName">要素类名</param>
        /// <param name="FcAlias">要素类别名</param>
        /// <returns></returns>
        public bool CreateDatasetFeatureClass(IFeatureWorkspace targetWorkSpace, string DatasetName, string FcName, string FcAlias = "")
        {
            bool result = true;

            try
            {
                FieldsHelper = new FieldsHelper();
                OnAddField(FieldsHelper, FcName, FcAlias);

                IFeatureDataset targetDataset = null;
                if ((targetWorkSpace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureDataset, DatasetName) == false)
                {
                    targetDataset = targetWorkSpace.CreateFeatureDataset(DatasetName, FieldsHelper.GetSpatialRef());
                }
                else
                {
                    targetDataset = targetWorkSpace.OpenFeatureDataset(DatasetName);
                }


                if ((targetDataset as IFeatureClassContainer).get_ClassByName(FcName) != null)
                {
                    ErrorMessage = "当前要素类已经存在";
                    return(false);
                }

                UID CLSID = new UID();
                CLSID.Value = "esriGeoDatabase.Feature";

                ResultFeatureClass = targetDataset.CreateFeatureClass(FcName, FieldsHelper.Fields, CLSID, null, esriFeatureType.esriFTSimple, FieldsHelper.GetShapeFieldName(), null);

                if (string.IsNullOrEmpty(FcAlias) == false)
                {
                    IClassSchemaEdit pClassSchemaEdit = ResultFeatureClass as IClassSchemaEdit;
                    pClassSchemaEdit.AlterAliasName(FcAlias);
                }
            }
            catch (Exception ex)
            {
                result       = false;
                ErrorMessage = ex.Message;
            }
            return(result);
        }
Ejemplo n.º 12
0
        public static ITable CreateTable(IFeatureWorkspace featureWorkspace, string name, IFields fields)
        {
            if (featureWorkspace == null)
            {
                throw new ArgumentNullException("Error creating table. The reference to IFeatureWorkspace cannot be NULL.");
            }
            UID pCLSID;

            pCLSID       = new UIDClass();
            pCLSID.Value = "esriGeoDatabase.Object";
            IFieldsEdit pFieldsEdit;

            if ((fields == null) || (fields.FieldCount == 0))
            {
                fields      = new Fields();
                pFieldsEdit = fields as IFieldsEdit;

                IField     pFieldOID     = new Field();
                IFieldEdit pFieldOIDEdit = pFieldOID as IFieldEdit;
                pFieldOIDEdit.Name_2       = "OBJECTID";
                pFieldOIDEdit.Type_2       = esriFieldType.esriFieldTypeOID;
                pFieldOIDEdit.IsNullable_2 = false;

                pFieldsEdit.AddField(pFieldOID);
            }
            ITable table = null;

            try
            {
                table = featureWorkspace.CreateTable(name, fields, pCLSID, null, "");
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                throw new System.Runtime.InteropServices.COMException("An unexpected error occurred while trying to create a table in the geodatabase", ex);
            }

            // Set the alias
            IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)table;

            classSchemaEdit.AlterAliasName(GetUnQualifiedName(name));

            // Return the table
            return(table);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 创建一个独立要素类
        /// </summary>
        /// <param name="targetWorkSpace">目标工作空间</param>
        /// <param name="FcName">要素类名</param>
        /// <param name="FcAlias">要素类别名</param>
        /// <returns>若创建成功则返回true</returns>
        public bool CreateFeatureClass(IFeatureWorkspace targetWorkSpace, string FcName, string FcAlias = "")
        {
            if ((targetWorkSpace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, FcName))
            {
                ErrorMessage = "当前要素类已经存在";
                return(false);
            }

            bool result = true;

            try
            {
                UID CLSID = new UID();
                CLSID.Value = "esriGeoDatabase.Feature";

                FieldsHelper = new FieldsHelper();
                if (OnAddField(FieldsHelper, FcName, FcAlias) == false)
                {
                    ErrorMessage = "添加字段失败 : " + ErrorMessage;
                    return(false);
                }

                ResultFeatureClass = targetWorkSpace.CreateFeatureClass(FcName, FieldsHelper.Fields, CLSID, null, esriFeatureType.esriFTSimple, FieldsHelper.GetShapeFieldName(), null);

                if (string.IsNullOrEmpty(FcAlias) == false)
                {
                    IClassSchemaEdit pClassSchemaEdit = ResultFeatureClass as IClassSchemaEdit;
                    pClassSchemaEdit.AlterAliasName(FcAlias);
                }
            }
            catch (Exception ex)
            {
                result       = false;
                ErrorMessage = ex.Message;
            }
            return(result);
        }
Ejemplo n.º 14
0
        public static IFeatureClass CreateFeatureClass(object objectWorkspace, string name, ISpatialReference spatialReference, esriFeatureType featureType, esriGeometryType geometryType, IFields fields, UID uidCLSID, UID uidCLSEXT, string configWord)
        {
            // Check for invalid parameters.
            if (objectWorkspace == null)
            {
                throw new ArgumentNullException("[objectWorkspace] cannot be null");
            }

            if (!((objectWorkspace is IFeatureWorkspace) || (objectWorkspace is IFeatureDataset)))
            {
                throw (new ArgumentNullException("[objectWorkspace] must be IFeatureWorkspace or IFeatureDataset"));
            }

            if (string.IsNullOrEmpty(name))
            {
                throw (new ArgumentNullException("[name] cannot be empty"));
            }

            if ((objectWorkspace is IWorkspace) && (spatialReference == null))
            {
                throw (new ArgumentNullException("[spatialReference] cannot be null for StandAlong FeatureClasses"));
            }


            // Set ClassID (if Null)
            if (uidCLSID == null)
            {
                uidCLSID = new UIDClass();
                switch (featureType)
                {
                case (esriFeatureType.esriFTSimple):
                    uidCLSID.Value = "{52353152-891A-11D0-BEC6-00805F7C4268}";
                    break;

                case (esriFeatureType.esriFTSimpleJunction):
                    geometryType   = esriGeometryType.esriGeometryPoint;
                    uidCLSID.Value = "{CEE8D6B8-55FE-11D1-AE55-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTComplexJunction):
                    uidCLSID.Value = "{DF9D71F4-DA32-11D1-AEBA-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTSimpleEdge):
                    geometryType   = esriGeometryType.esriGeometryPolyline;
                    uidCLSID.Value = "{E7031C90-55FE-11D1-AE55-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTComplexEdge):
                    geometryType   = esriGeometryType.esriGeometryPolyline;
                    uidCLSID.Value = "{A30E8A2A-C50B-11D1-AEA9-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTAnnotation):
                    geometryType   = esriGeometryType.esriGeometryPolygon;
                    uidCLSID.Value = "{E3676993-C682-11D2-8A2A-006097AFF44E}";
                    break;

                case (esriFeatureType.esriFTDimension):
                    geometryType   = esriGeometryType.esriGeometryPolygon;
                    uidCLSID.Value = "{496764FC-E0C9-11D3-80CE-00C04F601565}";
                    break;
                }
            }

            // Set uidCLSEXT (if Null)
            if (uidCLSEXT == null)
            {
                switch (featureType)
                {
                case (esriFeatureType.esriFTAnnotation):
                    uidCLSEXT       = new UIDClass();
                    uidCLSEXT.Value = "{24429589-D711-11D2-9F41-00C04F6BC6A5}";
                    break;

                case (esriFeatureType.esriFTDimension):
                    uidCLSEXT       = new UIDClass();
                    uidCLSEXT.Value = "{48F935E2-DA66-11D3-80CE-00C04F601565}";
                    break;
                }
            }

            // Add Fields
            if (fields == null)
            {
                // Create fields collection
                fields = new FieldsClass();
                IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

                // Create the geometry field
                IGeometryDef     geometryDef     = new GeometryDefClass();
                IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

                // Assign Geometry Definition
                geometryDefEdit.GeometryType_2 = geometryType;
                geometryDefEdit.GridCount_2    = 1;
                geometryDefEdit.set_GridSize(0, 0.5);
                geometryDefEdit.AvgNumPoints_2 = 2;
                geometryDefEdit.HasM_2         = false;
                geometryDefEdit.HasZ_2         = false;
                if (objectWorkspace is IWorkspace)
                {
                    // If this is a STANDALONE FeatureClass then add spatial reference.
                    geometryDefEdit.SpatialReference_2 = spatialReference;
                }

                // Create OID Field
                IField     fieldOID     = new FieldClass();
                IFieldEdit fieldEditOID = (IFieldEdit)fieldOID;
                fieldEditOID.Name_2      = "OBJECTID";
                fieldEditOID.AliasName_2 = "OBJECTID";
                fieldEditOID.Type_2      = esriFieldType.esriFieldTypeOID;
                fieldsEdit.AddField(fieldOID);

                // Create Geometry Field
                IField     fieldShape     = new FieldClass();
                IFieldEdit fieldEditShape = (IFieldEdit)fieldShape;
                fieldEditShape.Name_2        = "SHAPE";
                fieldEditShape.AliasName_2   = "SHAPE";
                fieldEditShape.Type_2        = esriFieldType.esriFieldTypeGeometry;
                fieldEditShape.GeometryDef_2 = geometryDef;
                fieldsEdit.AddField(fieldShape);
            }

            // Locate Shape Field
            string stringShapeFieldName = null;
            int    i = 0;

            while (i <= fields.FieldCount - 1)
            {
                if (fields.get_Field(i).Type == esriFieldType.esriFieldTypeGeometry)
                {
                    stringShapeFieldName = fields.get_Field(i).Name;
                    break;
                }
                i = i + 1;
            }
            if (stringShapeFieldName == null)
            {
                throw (new System.Data.ConstraintException("Cannot locate geometry field in FIELDS"));
            }

            IFeatureClass featureClass = null;

            if (objectWorkspace is IFeatureWorkspace)
            {
                // Create a STANDALONE FeatureClass
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)objectWorkspace;

                featureClass = featureWorkspace.CreateFeatureClass(name, fields, uidCLSID, uidCLSEXT, featureType, stringShapeFieldName, configWord);
            }
            else if (objectWorkspace is IFeatureDataset)
            {
                IFeatureDataset featureDataset = (IFeatureDataset)objectWorkspace;
                featureClass = featureDataset.CreateFeatureClass(name, fields, uidCLSID, uidCLSEXT, featureType, stringShapeFieldName, configWord);
            }

            // Set the alias
            IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)featureClass;

            classSchemaEdit.AlterAliasName(GeodatabaseUtil.GetUnQualifiedName(name));

            // Return FeatureClass
            return(featureClass);
        }
Ejemplo n.º 15
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");
            }
        }
Ejemplo n.º 16
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");
            }
        }
Ejemplo n.º 17
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");
            }
        }
Ejemplo n.º 18
0
        protected override void OnClick()
        {
            m_pApp = (IApplication)ArcMap.Application;
            if (m_pApp == null)
            {
                //if the app is null then could be running from ArcCatalog
                m_pApp = (IApplication)ArcCatalog.Application;
            }

            if (m_pApp == null)
            {
                MessageBox.Show("Could not access the application.", "No Application found");
                return;
            }
            IGxApplication pGXApp = (IGxApplication)m_pApp;

            stdole.IUnknown pUnk = null;
            try
            {
                pUnk = (stdole.IUnknown)pGXApp.SelectedObject.InternalObjectName.Open();
            }
            catch (COMException ex)
            {
                if (ex.ErrorCode == (int)fdoError.FDO_E_DATASET_TYPE_NOT_SUPPORTED_IN_RELEASE ||
                    ex.ErrorCode == -2147220944)
                {
                    MessageBox.Show("The dataset is not supported in this release.", "Could not open the dataset");
                }
                else
                {
                    MessageBox.Show(ex.ErrorCode.ToString(), "Could not open the dataset");
                }
                return;
            }

            if (pUnk is ICadastralFabric)
            {
                m_pCadaFab = (ICadastralFabric)pUnk;
            }
            else
            {
                MessageBox.Show("Please select a parcel fabric and try again.", "Not a parcel fabric");
                return;
            }


            Utils FabricUTILS = new Utils();

            ITable     pTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTPlans);
            IDataset   pDS    = (IDataset)pTable;
            IWorkspace pWS    = pDS.Workspace;

            //Do a Start and Stop editing to make sure we're not running in an edit session
            if (!FabricUTILS.StartEditing(pWS, true))
            {//if start editing fails then bail
                if (pUnk != null)
                {
                    Marshal.ReleaseComObject(pUnk);
                }
                Cleanup(pTable, pWS);
                FabricUTILS = null;
                return;
            }
            FabricUTILS.StopEditing(pWS);

            bool bAddedField = false;

            if (FabricUTILS.GetFabricVersion((ICadastralFabric2)m_pCadaFab) < 2)
            {
                bAddedField = FabricUTILS.CadastralTableAddFieldV1(m_pCadaFab, esriCadastralFabricTable.esriCFTPlans, esriFieldType.esriFieldTypeInteger,
                                                                   "KeepOnMerge", "KeepOnMerge", 1);
            }
            else
            {
                bAddedField = FabricUTILS.CadastralTableAddField(m_pCadaFab, esriCadastralFabricTable.esriCFTPlans, esriFieldType.esriFieldTypeInteger,
                                                                 "KeepOnMerge", "KeepOnMerge", 1);
            }

            if (bAddedField)
            {
                MessageBox.Show("Plan-merge helper field 'KeepOnMerge' added.", "Add Field");
            }
            else
            {
                MessageBox.Show("Field 'KeepOnMerge' could not be added." + Environment.NewLine + "The field may already exist.",
                                "Add Field");
            }

            if (bAddedField)
            {
                //if the field was added succesfully, add the Yes/No domain
                IDomain pDom = new CodedValueDomainClass();
                try
                {
                    IWorkspaceDomains2 pWSDoms = (IWorkspaceDomains2)pWS;
                    pDom.FieldType   = esriFieldType.esriFieldTypeInteger;
                    pDom.Name        = "Flag for Keep on Plan Merge";
                    pDom.Description = "Flag for Keep on Plan Merge";
                    ICodedValueDomain pCVDom = (ICodedValueDomain)pDom;
                    //pCVDom.AddCode(0, "No");
                    pCVDom.AddCode(1, "Keep On Merge");
                    pWSDoms.AddDomain(pDom);
                }
                catch (COMException ex)
                {
                    MessageBox.Show(ex.ErrorCode.ToString());
                }

                //Get the field
                int iFld = pTable.FindField("KeepOnMerge");
                if (iFld >= 0)
                {
                    IField pFld = pTable.Fields.get_Field(iFld);
                    // Check that the field and domain have the same field type.
                    if (pFld.Type == pDom.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("KeepOnMerge", pDom);
                            Console.WriteLine("The domain was successfully assigned.");
                        }
                        catch (COMException exc)
                        {
                            // Handle the exception in a way appropriate for the application.
                            Console.WriteLine(exc.Message);
                        }
                        finally
                        {
                            // Set the schema lock to be a shared lock.
                            schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                        }
                    }
                }

                if (pDom != null)
                {
                    Marshal.ReleaseComObject(pDom);
                }
            }
            Cleanup(pTable, pWS);
            FabricUTILS = null;
        }
Ejemplo n.º 19
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();
        }
Ejemplo n.º 20
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());
            }
        }
Ejemplo n.º 21
0
        public bool Apply()
        {
            int num;

            if (this.itable_0 != null)
            {
                Exception exception;
                try
                {
                    try
                    {
                        IField field;
                        for (num = 0; num < this.ifieldsEdit_1.FieldCount; num++)
                        {
                            IFields fields = this.itable_0.Fields;
                            field = this.ifieldsEdit_1.get_Field(num);
                            int index = this.itable_0.FindField(field.Name);
                            if (index != -1)
                            {
                                this.itable_0.DeleteField(fields.get_Field(index));
                            }
                        }
                        for (num = 0; num < this.ifieldsEdit_0.FieldCount; num++)
                        {
                            this.itable_0.AddField(this.ifieldsEdit_0.get_Field(num));
                        }
                        if (!ObjectClassShareData.m_IsShapeFile)
                        {
                            IClassSchemaEdit edit = this.itable_0 as IClassSchemaEdit;
                            num = 0;
                            while (num < this.ifields_0.FieldCount)
                            {
                                field = this.ifields_0.get_Field(num);
                                edit.AlterFieldAliasName(field.Name, field.AliasName);
                                if (((field.Name != "SHAPE.area") && !(field.Name == "SHAPE.len")) &&
                                    (((((field.Type == esriFieldType.esriFieldTypeDouble) ||
                                        (field.Type == esriFieldType.esriFieldTypeInteger)) ||
                                       ((field.Type == esriFieldType.esriFieldTypeSingle) ||
                                        (field.Type == esriFieldType.esriFieldTypeSmallInteger))) ||
                                      (field.Type == esriFieldType.esriFieldTypeDate)) ||
                                     (field.Type == esriFieldType.esriFieldTypeString)))
                                {
                                    edit.AlterDomain(field.Name, field.Domain);
                                }
                                num++;
                            }
                        }
                    }
                    catch (Exception exception1)
                    {
                        exception = exception1;
                        Logger.Current.Error("", exception, "");
                    }
                    this.ifieldsEdit_1.DeleteAllFields();
                    this.ifieldsEdit_0.DeleteAllFields();
                    this.ifields_0 = (this.itable_0.Fields as IClone).Clone() as IFields;
                    this.method_0(this.listView2, this.ifields_0);
                    this.listView2.LockRowCount = this.ifields_0.FieldCount;
                    goto Label_023C;
                }
                catch (Exception exception2)
                {
                    exception = exception2;
                    Logger.Current.Error("", exception, "");
                    MessageBox.Show(exception.Message);
                    return(false);
                }
            }
            if (this.ifields_0 != null)
            {
                for (num = 0; num < this.ifieldsEdit_0.FieldCount; num++)
                {
                    (this.ifields_0 as IFieldsEdit).AddField(this.ifieldsEdit_0.get_Field(num));
                }
            }
Label_023C:
            return(true);
        }
Ejemplo n.º 22
0
        private void createMatadataMap(IWorkspace inF)
        {
            g_conn = "Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + Plugin.Mod.Server + ") (PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)));Persist Security Info=True;User Id=" + Plugin.Mod.User + "; Password="******"";
            //g_conn = "Provider=OraOLEDB.Oracle;Data Source=orc;Persist Security Info=True;User Id=" + Plugin.Mod.User + "; Password="******"";
            OleDbConnection oeCon = new OleDbConnection(g_conn);

            oeCon.Open();
            string pTname = "metadata_map_tmp";

            ModTableFun.DropTable(oeCon, pTname);
            if (!ModTableFun.isExist(oeCon, "metadata_xml") || !ModTableFun.isExist(oeCon, "JHTB"))
            {
                return;
            }
            string sql = "create table metadata_map_tmp as select * from metadata_xml";

            ModTableFun.ExecuteDDL(oeCon, sql);                         //根据元数据表创建中间表
            ModTableFun.DropColumn(oeCon, pTname, "XMLID,METADATAXML"); //删掉不支持的类型的列
            if (!ModTableFun.isExist(oeCon, pTname))                    //中间表未创建  返回
            {
                return;
            }

            IFeatureWorkspace pFW      = inF as IFeatureWorkspace;
            IFeatureClass     pFC_jhtb = pFW.OpenFeatureClass("JHTB");
            IFeatureClass     pFC      = null;                                                            //元数据地图图层

            if (!(inF as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, "METADATA_MAP")) //若不存在就创建
            {
                IGeoDataset pGD_jhtb = pFC_jhtb as IGeoDataset;
                pFC = CreateFeatureClass("METADATA_MAP", pFW, pGD_jhtb.SpatialReference);
                IClassSchemaEdit pCSE = pFC as IClassSchemaEdit;
                pCSE.AlterAliasName("元数据地图");
                ITable pT = pFW.OpenTable(pTname);
                for (int i = 0; i < pT.Fields.FieldCount; i++)
                {
                    IField pField = pT.Fields.get_Field(i);
                    pFC.AddField(pField);
                }
            }
            else//否则直接打开
            {
                //打开前删除全部的记录
                sql = "truncate table METADATA_MAP";
                ModTableFun.ExecuteDDL(oeCon, sql);
                pFC = pFW.OpenFeatureClass("METADATA_MAP");
            }
            if (pFC.FeatureCount(null) != 0)//确认元数据地图层记录为空
            {
                return;
            }
            IFields pFds = pFC.Fields;

            IFeatureCursor insertCsr = pFC.Insert(true);//插入要素的游标


            sql = "select * from " + pTname;
            OleDbDataReader oeDR = ModTableFun.GetReader(oeCon, sql);

            if (oeDR == null)//元数据为空,返回
            {
                return;
            }
            DataTable pDT = oeDR.GetSchemaTable();

            while (oeDR.Read())//遍历记录
            {
                IFeatureBuffer pFB = pFC.CreateFeatureBuffer();
                IFeature       pF  = pFB as IFeature;
                string         tfh = oeDR["图幅号"].ToString();
                IQueryFilter   pQF = new QueryFilterClass();
                pQF.WhereClause = "MAPNO = '" + tfh + "'";
                IFeatureCursor fCursor_jhtb = pFC_jhtb.Search(pQF, false);
                IFeature       f_jhtb       = fCursor_jhtb.NextFeature();
                if (f_jhtb == null)//若元数据表中的图幅号未在结合图表找到,则不加入元数据地图图层
                {
                    continue;
                }
                pF.Shape = f_jhtb.ShapeCopy;     //写结合图表的图形
                foreach (DataRow dr in pDT.Rows) //遍历写入列值
                {
                    int    fdix = pFds.FindField(dr["ColumnName"].ToString());
                    IField pFld = pFds.get_Field(fdix);
                    if ((fdix > -1) && (pFld.Editable == true) && pFld.Type != esriFieldType.esriFieldTypeGeometry && pFld.Type != esriFieldType.esriFieldTypeOID)
                    {
                        pF.set_Value(fdix, oeDR[dr["ColumnName"].ToString()]);
                    }
                }//foreach

                insertCsr.InsertFeature(pFB);//将缓存要素插入游标
            }//while
            insertCsr.Flush();
        }
Ejemplo n.º 23
0
        public bool Apply()
        {
            int num;

            if (!(!this.bool_2 || this.bool_3))
            {
                return(true);
            }
            this.bool_3 = false;
            if (NewObjectClassHelper.m_pObjectClassHelper.ObjectClass != null)
            {
                COMException exception;
                Exception    exception2;
                this.itable_0 = NewObjectClassHelper.m_pObjectClassHelper.ObjectClass as ITable;
                string name = (this.itable_0 as IDataset).Name;
                try
                {
                    IField       field;
                    CodeDomainEx ex;
                    try
                    {
                        for (num = 0; num < this.ifieldsEdit_1.FieldCount; num++)
                        {
                            IFields fields = this.itable_0.Fields;
                            field = this.ifieldsEdit_1.get_Field(num);
                            int index = this.itable_0.FindField(field.Name);
                            if (index != -1)
                            {
                                this.itable_0.DeleteField(fields.get_Field(index));
                                if ((NewObjectClassHelper.m_pObjectClassHelper != null) &&
                                    NewObjectClassHelper.m_pObjectClassHelper.FieldDomains.ContainsKey(field))
                                {
                                    ex = NewObjectClassHelper.m_pObjectClassHelper.FieldDomains[field];
                                    if (ex != null)
                                    {
                                        CodeDomainManage.DeleteCodeDoaminMap(name, field.Name);
                                    }
                                }
                            }
                        }
                    }
                    catch (COMException exception1)
                    {
                        exception = exception1;
                        Logger.Current.Error("", exception, "");
                        MessageBox.Show(exception.Message);
                        return(false);
                    }
                    catch (Exception exception3)
                    {
                        exception2 = exception3;
                        Logger.Current.Error("", exception2, "");
                    }
                    try
                    {
                        for (num = 0; num < this.ifieldsEdit_0.FieldCount; num++)
                        {
                            IField key = this.ifieldsEdit_0.get_Field(num);
                            this.itable_0.AddField(this.ifieldsEdit_0.get_Field(num));
                            if ((NewObjectClassHelper.m_pObjectClassHelper != null) &&
                                NewObjectClassHelper.m_pObjectClassHelper.FieldDomains.ContainsKey(key))
                            {
                                ex = NewObjectClassHelper.m_pObjectClassHelper.FieldDomains[key];
                                if (ex != null)
                                {
                                    CodeDomainManage.AddFieldCodeDoaminMap(name, key.Name, ex.DomainID);
                                }
                            }
                        }
                    }
                    catch (COMException exception4)
                    {
                        exception = exception4;
                        if (exception.ErrorCode == -2147220969)
                        {
                            MessageBox.Show("不是对象的所有者,无法修改对象!");
                        }
                        else if (exception.ErrorCode == -2147219887)
                        {
                            MessageBox.Show("无法添加字段!");
                        }
                        else
                        {
                            Logger.Current.Error("", exception, "");
                            MessageBox.Show(exception.Message);
                        }
                    }
                    catch (Exception exception5)
                    {
                        exception2 = exception5;
                        Logger.Current.Error("", exception2, "");
                    }
                    if (!ObjectClassShareData.m_IsShapeFile)
                    {
                        IClassSchemaEdit edit = this.itable_0 as IClassSchemaEdit;
                        num = 0;
                        while (num < this.ilist_0.Count)
                        {
                            field = this.ilist_0[num];
                            try
                            {
                                if (((FieldChangeType)this.ilist_1[num]) == FieldChangeType.FCTAlias)
                                {
                                    edit.AlterFieldAliasName(field.Name, field.AliasName);
                                }
                                else if (((FieldChangeType)this.ilist_1[num]) == FieldChangeType.FCTDomain)
                                {
                                    edit.AlterDomain(field.Name, field.Domain);
                                    if ((NewObjectClassHelper.m_pObjectClassHelper != null) &&
                                        NewObjectClassHelper.m_pObjectClassHelper.FieldDomains.ContainsKey(field))
                                    {
                                        ex = NewObjectClassHelper.m_pObjectClassHelper.FieldDomains[field];
                                        if (ex != null)
                                        {
                                            CodeDomainManage.AddFieldCodeDoaminMap(name, field.Name, ex.DomainID);
                                        }
                                        else
                                        {
                                            CodeDomainManage.DeleteCodeDoaminMap(name, field.Name);
                                        }
                                    }
                                }
                            }
                            catch (COMException exception6)
                            {
                                exception = exception6;
                                (field as IFieldEdit).AliasName_2 = field.Name;
                                if (exception.ErrorCode == -2147220969)
                                {
                                    MessageBox.Show("不是对象的所有者,无法修改字段[" + field.Name + "]!");
                                }
                                else if (exception.ErrorCode == -2147219887)
                                {
                                    MessageBox.Show("无法修改字段[" + field.Name + "]!");
                                }
                                else
                                {
                                    Logger.Current.Error("", exception, "");
                                    MessageBox.Show(exception.Message);
                                }
                                return(false);
                            }
                            catch (Exception exception7)
                            {
                                exception2 = exception7;
                                Logger.Current.Error("", exception2, "");
                            }
                            num++;
                        }
                    }
                    if (!ObjectClassShareData.m_IsShapeFile)
                    {
                        (this.itable_0 as ISchemaLock).ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                    this.ifieldsEdit_1.DeleteAllFields();
                    this.ifieldsEdit_0.DeleteAllFields();
                    this.ilist_0.Clear();
                    this.ilist_1.Clear();
                    this.ifields_0 = (this.itable_0.Fields as IClone).Clone() as IFields;
                    this.method_2(this.listView2, this.ifields_0);
                    this.listView2.LockRowCount = this.ifields_0.FieldCount;
                    goto Label_0512;
                }
                catch (COMException exception8)
                {
                    exception = exception8;
                    if (exception.ErrorCode == -2147220969)
                    {
                        MessageBox.Show("不是对象的所有者,无法修改对象!");
                    }
                    else
                    {
                        Logger.Current.Error("", exception, "");
                        MessageBox.Show(exception.Message);
                    }
                    return(false);
                }
                catch (Exception exception9)
                {
                    exception2 = exception9;
                    Logger.Current.Error("", exception2, "");
                    MessageBox.Show(exception2.Message);
                    return(false);
                }
            }
            if (this.ifields_0 != null)
            {
                for (num = 0; num < this.ifieldsEdit_0.FieldCount; num++)
                {
                    (this.ifields_0 as IFieldsEdit).AddField(this.ifieldsEdit_0.get_Field(num));
                }
            }
Label_0512:
            return(true);
        }