Пример #1
0
        // ArcGIS Snippet Title:
        // Create Table
        //
        // Long Description:
        // Creates a dataset in a workspace.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Geodatabase
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Uitvoeren.
        //

        ///<summary>Creates a table with some default fields.</summary>
        ///
        ///<param name="workspace">An IWorkspace2 interface</param>
        ///<param name="tableName">A System.String of the table name in the workspace. Example: "owners"</param>
        ///<param name="fields">An IFields interface or Nothing</param>
        ///
        ///<returns>An ITable interface or Nothing</returns>
        ///
        ///<remarks>
        ///Notes:
        ///(1) If an IFields interface is supplied for the 'fields' collection it will be used to create the
        ///    table. If a Nothing value is supplied for the 'fields' collection, a table will be created using
        ///    default values in the method.
        ///(2) If a table with the supplied 'tableName' exists in the workspace an ITable will be returned.
        ///    if table does not exit a new one will be created.
        ///</remarks>
        public ESRI.ArcGIS.Geodatabase.ITable CreateOrOpenTableLog(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields)
        {
            // create the behavior clasid for the featureclass
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();

            if (workspace == null)
            {
                return(null);                                                                                                  // valid feature workspace not passed in as an argument to the method
            }
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast
            ESRI.ArcGIS.Geodatabase.ITable            table;

            if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName))
            {
                // table with that name already exists return that table
                table = featureWorkspace.OpenTable(tableName);
                return(table);
            }

            uid.Value = "esriGeoDatabase.Object";

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

            // if a fields collection is not passed in then supply our own
            if (fields == null)
            {
                // create the fields using the required fields method
                fields = objectClassDescription.RequiredFields;
                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                fieldsEdit.AddField(this.CreateFieldInt("ID"));
                fieldsEdit.AddField(this.CreateFieldInt("index"));
                fieldsEdit.AddField(this.CreateFieldDouble("X_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("Y_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("M_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("X_To", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("Y_To", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("M_To", 8, 2));


                // add field to field collection
                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
            }

            // Use IFieldChecker to create a validated fields collection.
            ESRI.ArcGIS.Geodatabase.IFieldChecker   fieldChecker    = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError  = null;
            ESRI.ArcGIS.Geodatabase.IFields         validatedFields = null;
            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.


            // create and return the table
            table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, "");

            return(table);
        }
Пример #2
0
        /// <summary>
        /// 创建数据表
        /// </summary>
        /// <param name="_TablePath"></param>
        /// <param name="_TableName"></param>
        /// <returns></returns>
        public ITable CreateTable(string _TablePath, string _TableName)
        {
            IWorkspaceFactory pWks = new FileGDBWorkspaceFactoryClass();
            IFeatureWorkspace pFwk = pWks.OpenFromFile(_TablePath, 0) as IFeatureWorkspace;

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();
            IFields     pTableFields     = objectClassDescription.RequiredFields;
            IFieldsEdit pTableFieldsEdit = pTableFields as IFieldsEdit;
            IField      pField           = null;
            IFieldEdit  pFieldEdit       = null;

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                DataColumn dc = dt.Columns[i];
                pField            = new FieldClass();
                pFieldEdit        = pField as IFieldEdit;
                pFieldEdit.Name_2 = dc.ColumnName;
                switch (dc.DataType.ToString())
                {
                case "System.Double":
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                    break;

                case "System.String":
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    break;
                }
                pTableFieldsEdit.AddField(pField);
            }

            ITable pTable = pFwk.CreateTable(_TableName, pTableFields, null, null, "");

            return(pTable);
        }
Пример #3
0
        /// <summary>
        /// 输出结果为一个张表,这张表有3个字段,其中面ID为面要素数据的FID
        /// 个数用于记录这个面包含的点的个数
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="TableName"></param>
        /// <returns></returns>

        public ITable CreateTable(string _TablePath, string _TableName)
        {
            IWorkspaceFactory pWks = new ShapefileWorkspaceFactoryClass();

            IFeatureWorkspace pFwk = pWks.OpenFromFile(_TablePath, 0) as IFeatureWorkspace;

            //用于记录面中的ID;

            IField pFieldID = new FieldClass();

            IFieldEdit pFieldIID = pFieldID as IFieldEdit;

            pFieldIID.Type_2 = esriFieldType.esriFieldTypeInteger;

            pFieldIID.Name_2 = "面ID";

            //用于记录个数的;
            IField pFieldCount = new FieldClass();

            IFieldEdit pFieldICount = pFieldCount as IFieldEdit;

            pFieldICount.Type_2 = esriFieldType.esriFieldTypeInteger;
            pFieldICount.Name_2 = "个数";

            //用于添加表中的必要字段
            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

            IFields pTableFields = objectClassDescription.RequiredFields;

            IFieldsEdit pTableFieldsEdit = pTableFields as IFieldsEdit;

            pTableFieldsEdit.AddField(pFieldID);

            pTableFieldsEdit.AddField(pFieldCount);

            ITable pTable = pFwk.CreateTable(_TableName, pTableFields, null, null, "");

            return(pTable);
        }
Пример #4
0
        /// <summary>
        /// 创建数据表
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
//        static public ITable CreateTable(string path)
//         {
//
//
//            string _TablePath=Path.GetDirectoryName(path);
//            string _TableName=Path.GetFileName(path);
//            IWorkspaceFactory pWks = new ShapefileWorkspaceFactoryClass();
//              IFeatureWorkspace pFwk = pWks.OpenFromFile(_TablePath,0) as IFeatureWorkspace;
//             //用于分区的ID;
//             IField pFieldID = new FieldClass();
//             IFieldEdit pFieldIID = pFieldID as IFieldEdit;
//             pFieldIID.Type_2 = esriFieldType.esriFieldTypeInteger;
//             pFieldIID.Name_2 = "ZID";
//            //用于记录比值的;
//             IField pFieldValue = new FieldClass();
//             IFieldEdit pFieldICount = pFieldValue as IFieldEdit;
//             pFieldICount.Type_2 = esriFieldType.esriFieldTypeDouble;
//             pFieldICount.Name_2 = "Value";
//             //用于添加表中的必要字段
//             ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription =
//             new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();
//
//             IFields pTableFields = objectClassDescription.RequiredFields;
//             IFieldsEdit pTableFieldsEdit = pTableFields as IFieldsEdit;
//
//             pTableFieldsEdit.AddField(pFieldID);
//             pTableFieldsEdit.AddField(pFieldValue);
//
//             ITable pTable = pFwk.CreateTable(_TableName,pTableFields, null,null, "");
//             return pTable;
//
//         }
        /// <summary>
        /// 创建包含指定字段的数据表
        /// </summary>
        /// <param name="path"></param>
        /// <param name="pFields"></param>
        /// <returns></returns>
        static public ITable CreateTable(string path, IFields pFields)
        {
            string            _TablePath = System.IO.Path.GetDirectoryName(path);
            string            _TableName = System.IO.Path.GetFileName(path);
            IWorkspaceFactory pWks       = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFwk       = pWks.OpenFromFile(_TablePath, 0) as IFeatureWorkspace;

            //用于添加表中的必要字段
            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription =
                new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

            IFields     pTableFields     = objectClassDescription.RequiredFields;
            IFieldsEdit pTableFieldsEdit = pTableFields as IFieldsEdit;

            for (int i = 0; i < pFields.FieldCount; i++)
            {
                IField pField = pFields.Field[i];
                pTableFieldsEdit.AddField(pField);
            }
            ITable pTable = pFwk.CreateTable(_TableName, pTableFields, null, null, "");

            return(pTable);
        }
Пример #5
0
        /// <summary>
        /// 创建一个只有ZID的数据表
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        static public ITable CreateTable(string path)
        {
            string            _TablePath = System.IO.Path.GetDirectoryName(path);
            string            _TableName = System.IO.Path.GetFileName(path);
            IWorkspaceFactory pWks       = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFwk       = pWks.OpenFromFile(_TablePath, 0) as IFeatureWorkspace;

            IField     pField     = new FieldClass();
            IFieldEdit pFieldEdit = pField as IFieldEdit;

            pFieldEdit.Name_2 = "ZID";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
            //用于添加表中的必要字段
            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription =
                new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

            IFields     pTableFields = objectClassDescription.RequiredFields;
            IFieldsEdit pFieldsEdit  = pTableFields as IFieldsEdit;

            pFieldsEdit.AddField(pField);
            ITable pTable = pFwk.CreateTable(_TableName, pTableFields, null, null, "");

            return(pTable);
        }
Пример #6
0
        // ArcGIS Snippet Title:
        // Create Table
        //
        // Long Description:
        // Creates a dataset in a workspace.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Geodatabase
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Uitvoeren.
        //
        ///<summary>Creates a table with some default fields.</summary>
        /// 
        ///<param name="workspace">An IWorkspace2 interface</param>
        ///<param name="tableName">A System.String of the table name in the workspace. Example: "owners"</param>
        ///<param name="fields">An IFields interface or Nothing</param>
        ///  
        ///<returns>An ITable interface or Nothing</returns>
        ///  
        ///<remarks>
        ///Notes:
        ///(1) If an IFields interface is supplied for the 'fields' collection it will be used to create the
        ///    table. If a Nothing value is supplied for the 'fields' collection, a table will be created using 
        ///    default values in the method.
        ///(2) If a table with the supplied 'tableName' exists in the workspace an ITable will be returned.
        ///    if table does not exit a new one will be created.
        ///</remarks>
        public ESRI.ArcGIS.Geodatabase.ITable CreateOrOpenTableLog(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields)
        {
            // create the behavior clasid for the featureclass
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();

            if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method

            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast
            ESRI.ArcGIS.Geodatabase.ITable table;

            if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName))
            {
                // table with that name already exists return that table
                table = featureWorkspace.OpenTable(tableName);
                return table;
            }

            uid.Value = "esriGeoDatabase.Object";

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

            // if a fields collection is not passed in then supply our own
            if (fields == null)
            {
                // create the fields using the required fields method
                fields = objectClassDescription.RequiredFields;
                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                fieldsEdit.AddField(this.CreateFieldInt("ID"));
                fieldsEdit.AddField(this.CreateFieldInt("index"));
                fieldsEdit.AddField(this.CreateFieldDouble("X_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("Y_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("M_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("X_To", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("Y_To", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("M_To", 8, 2));

                // add field to field collection
                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
            }

            // Use IFieldChecker to create a validated fields collection.
            ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
            ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.

            // create and return the table
            table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, "");

            return table;
        }
Пример #7
0
        /// <summary>
        /// 输出结果为一个张表,这张表有3个字段,其中面ID为面要素数据的FID
        /// 个数用于记录这个面包含的点的个数
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="TableName"></param>
        /// <returns></returns>
        public ITable CreateTable(string _TablePath, string _TableName)
        {
            IWorkspaceFactory pWks = new ShapefileWorkspaceFactoryClass();

            IFeatureWorkspace pFwk = pWks.OpenFromFile(_TablePath, 0) as IFeatureWorkspace;

            //用于记录面中的ID;

            IField pFieldID = new FieldClass();

            IFieldEdit pFieldIID = pFieldID as IFieldEdit;

            pFieldIID.Type_2 = esriFieldType.esriFieldTypeInteger;

            pFieldIID.Name_2 = "面ID";

            //用于记录个数的;
            IField pFieldCount = new FieldClass();

            IFieldEdit pFieldICount = pFieldCount as IFieldEdit;

            pFieldICount.Type_2 = esriFieldType.esriFieldTypeInteger;
            pFieldICount.Name_2 = "个数";

            //用于添加表中的必要字段
            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

            IFields pTableFields = objectClassDescription.RequiredFields;

            IFieldsEdit pTableFieldsEdit = pTableFields as IFieldsEdit;

            pTableFieldsEdit.AddField(pFieldID);

            pTableFieldsEdit.AddField(pFieldCount);

            ITable pTable = pFwk.CreateTable(_TableName, pTableFields, null, null, "");

            return pTable;
        }
Пример #8
0
        internal ESRI.ArcGIS.Geodatabase.ITable CreateRevisionTable(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields, string storageKeyword)
        {
            // create the behavior clasid for the featureclass
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();

            if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method

            ESRI.ArcGIS.Geodatabase.ITable table = null;

            try
            {
                ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast

                if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName))
                {
                    // if a table with the same name already exists delete it....if that is not possible return the current instance
                    table = featureWorkspace.OpenTable(tableName);

                    if (!DeleteDataset((IDataset)table))
                    {
                        return table;
                    }
                }

                uid.Value = "esriGeoDatabase.Object";

                ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

                // if a fields collection is not passed in then supply our own
                if (fields == null)
                {
                    // create the fields using the required fields method
                    fields = objectClassDescription.RequiredFields;
                    ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                    //
                    IFieldEdit osmChangesetField = new FieldClass() as IFieldEdit;
                    osmChangesetField.Name_2 = "osmchangeset";
                    osmChangesetField.Required_2 = true;
                    osmChangesetField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)osmChangesetField);

                    IFieldEdit osmActionField = new FieldClass() as IFieldEdit;
                    osmActionField.Name_2 = "osmaction";
                    osmActionField.Required_2 = true;
                    osmActionField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmActionField.Length_2 = 10;
                    fieldsEdit.AddField((IField)osmActionField);

                    IFieldEdit osmElementTypeField = new FieldClass() as IFieldEdit;
                    osmElementTypeField.Name_2 = "osmelementtype";
                    osmElementTypeField.Required_2 = true;
                    osmElementTypeField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmElementTypeField.Length_2 = 10;
                    fieldsEdit.AddField((IField)osmElementTypeField);

                    IFieldEdit osmVersionField = new FieldClass() as IFieldEdit;
                    osmVersionField.Name_2 = "osmversion";
                    osmVersionField.Required_2 = true;
                    osmVersionField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)osmVersionField);

                    IFieldEdit fcNameField = new FieldClass() as IFieldEdit;
                    fcNameField.Name_2 = "sourcefcname";
                    fcNameField.Required_2 = true;
                    fcNameField.Type_2 = esriFieldType.esriFieldTypeString;
                    fcNameField.Length_2 = 50;
                    fieldsEdit.AddField((IField)fcNameField);

                    IFieldEdit osmOldIDField = new FieldClass() as IFieldEdit;
                    osmOldIDField.Name_2 = "osmoldid";
                    osmOldIDField.Required_2 = true;
                    osmOldIDField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmOldIDField.Length_2 = 20;
                    fieldsEdit.AddField((IField)osmOldIDField);

                    IFieldEdit osmNewIDField = new FieldClass() as IFieldEdit;
                    osmNewIDField.Name_2 = "osmnewid";
                    osmNewIDField.Required_2 = true;
                    osmNewIDField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmNewIDField.Length_2 = 20;
                    fieldsEdit.AddField((IField)osmNewIDField);

                    IFieldEdit latField = new FieldClass() as IFieldEdit;
                    latField.Name_2 = "osmlat";
                    latField.Required_2 = true;
                    latField.Type_2 = esriFieldType.esriFieldTypeDouble;
                    latField.Scale_2 = 10;
                    fieldsEdit.AddField((IField)latField);

                    IFieldEdit lonField = new FieldClass() as IFieldEdit;
                    lonField.Name_2 = "osmlon";
                    lonField.Required_2 = true;
                    lonField.Type_2 = esriFieldType.esriFieldTypeDouble;
                    lonField.Scale_2 = 10;
                    fieldsEdit.AddField((IField)lonField);

                    IFieldEdit statusField = new FieldClass() as IFieldEdit;
                    statusField.Name_2 = "osmstatus";
                    statusField.Required_2 = true;
                    statusField.Type_2 = esriFieldType.esriFieldTypeString;
                    statusField.Length_2 = 40;
                    fieldsEdit.AddField((IField)statusField);

                    IFieldEdit statusCodeField = new FieldClass() as IFieldEdit;
                    statusCodeField.Name_2 = "osmstatuscode";
                    statusCodeField.Required_2 = true;
                    statusCodeField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)statusCodeField);

                    IFieldEdit errorMessageField = new FieldClass() as IFieldEdit;
                    errorMessageField.Name_2 = "osmerrormessage";
                    errorMessageField.Required_2 = true;
                    errorMessageField.Type_2 = esriFieldType.esriFieldTypeString;
                    errorMessageField.Length_2 = 255;
                    fieldsEdit.AddField((IField)errorMessageField);

                    fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
                }

                // Use IFieldChecker to create a validated fields collection.
                ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
                ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
                ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
                fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
                fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

                // The enumFieldError enumerator can be inspected at this point to determine
                // which fields were modified during validation.

                // create and return the table
                table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, storageKeyword);
            }
            catch
            {
                throw;
            }

            return table;
        }
Пример #9
0
        // ArcGIS Snippet Title:
        // Create Table
        //
        // Long Description:
        // Creates a dataset in a workspace.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Geodatabase
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Method.
        //
        ///<summary>Creates a table with some default fields.</summary>
        /// 
        ///<param name="workspace">An IWorkspace2 interface</param>
        ///<param name="tableName">A System.String of the table name in the workspace. Example: "owners"</param>
        ///<param name="fields">An IFields interface or Nothing</param>
        ///  
        ///<returns>An ITable interface or Nothing</returns>
        ///  
        ///<remarks>
        ///Notes:
        ///(1) If an IFields interface is supplied for the 'fields' collection it will be used to create the
        ///    table. If a Nothing value is supplied for the 'fields' collection, a table will be created using 
        ///    default values in the method.
        ///(2) If a table with the supplied 'tableName' exists in the workspace an ITable will be returned.
        ///    if table does not exit a new one will be created.
        ///</remarks>
        internal ESRI.ArcGIS.Geodatabase.ITable CreateRelationTable(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields, string storageKeyword, string metadataAbstract, string metadataPurpose)
        {
            // create the behavior clasid for the featureclass
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();

            if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method

            ESRI.ArcGIS.Geodatabase.ITable table = null;

            try
            {
                ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast

                if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName))
                {
                    // if a table with the same name already exists delete it....
                    table = featureWorkspace.OpenTable(tableName);

                    if (!DeleteDataset((IDataset)table))
                    {
                        return table;
                    }
                }

                uid.Value = "esriGeoDatabase.Object";

                ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

                // if a fields collection is not passed in then supply our own
                if (fields == null)
                {
                    // create the fields using the required fields method
                    fields = objectClassDescription.RequiredFields;
                    ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                    // create OSM base fields the osm administrative fields
                    // add the OSM ID field
                    IFieldEdit osmIDField = new FieldClass() as IFieldEdit;
                    osmIDField.Name_2 = "OSMID";
                    osmIDField.Required_2 = true;
                    osmIDField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmIDField.Length_2 = 20;
                    fieldsEdit.AddField((IField)osmIDField);

                    // user, uid, visible, version, changeset, timestamp
                    IFieldEdit osmuserField = new FieldClass() as IFieldEdit;
                    osmuserField.Name_2 = "osmuser";
                    osmuserField.Required_2 = true;
                    osmuserField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmuserField.Length_2 = 100;
                    fieldsEdit.AddField((IField)osmuserField);

                    IFieldEdit osmuidField = new FieldClass() as IFieldEdit;
                    osmuidField.Name_2 = "osmuid";
                    osmuidField.Required_2 = true;
                    osmuidField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)osmuidField);

                    IFieldEdit osmvisibleField = new FieldClass() as IFieldEdit;
                    osmvisibleField.Name_2 = "osmvisible";
                    osmvisibleField.Required_2 = true;
                    osmvisibleField.Type_2 = esriFieldType.esriFieldTypeString;
                    osmvisibleField.Length_2 = 20;
                    fieldsEdit.AddField((IField)osmvisibleField);

                    IFieldEdit osmversionField = new FieldClass() as IFieldEdit;
                    osmversionField.Name_2 = "osmversion";
                    osmversionField.Required_2 = true;
                    osmversionField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                    fieldsEdit.AddField((IField)osmversionField);

                    IFieldEdit osmchangesetField = new FieldClass() as IFieldEdit;
                    osmchangesetField.Name_2 = "osmchangeset";
                    osmchangesetField.Required_2 = true;
                    osmchangesetField.Type_2 = esriFieldType.esriFieldTypeInteger;
                    fieldsEdit.AddField((IField)osmchangesetField);

                    IFieldEdit osmtimestampField = new FieldClass() as IFieldEdit;
                    osmtimestampField.Name_2 = "osmtimestamp";
                    osmtimestampField.Required_2 = true;
                    osmtimestampField.Type_2 = esriFieldType.esriFieldTypeDate;
                    fieldsEdit.AddField((IField)osmtimestampField);

                    IFieldEdit osmrelationIDField = new FieldClass() as IFieldEdit;
                    osmrelationIDField.Name_2 = "osmMemberOf";
                    osmrelationIDField.Required_2 = true;
                    //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                    //{
                    osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeBlob;
                    //}
                    //else
                    //{
                    //    osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeXML;
                    //}
                    fieldsEdit.AddField((IField)osmrelationIDField);

                    IFieldEdit osmMembersField = new FieldClass() as IFieldEdit;
                    osmMembersField.Name_2 = "osmMembers";
                    //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                    //{
                    osmMembersField.Required_2 = true;
                    osmMembersField.Type_2 = esriFieldType.esriFieldTypeBlob;
                    //}
                    //else
                    //{
                    //    osmMembersField.Type_2 = esriFieldType.esriFieldTypeXML;
                    //}
                    fieldsEdit.AddField((IField)osmMembersField);

                    // add the field for the tag cloud for all other tag/value pairs
                    IFieldEdit osmXmlTagsField = new FieldClass() as IFieldEdit;
                    osmXmlTagsField.Name_2 = "osmTags";
                    osmXmlTagsField.Required_2 = true;
                    //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                    //{
                    osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeBlob;
                    //}
                    //else
                    //{
                    //    osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeXML;
                    //}
                    fieldsEdit.AddField((IField)osmXmlTagsField);

                    //IFieldEdit osmTrackChangesField = new FieldClass() as IFieldEdit;
                    //osmTrackChangesField.Name_2 = "osmTrackChanges";
                    //osmTrackChangesField.Required_2 = true;
                    //osmTrackChangesField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                    //osmTrackChangesField.DefaultValue_2 = 0;
                    //fieldsEdit.AddField((IField)osmTrackChangesField);

                    fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
                }

                // Use IFieldChecker to create a validated fields collection.
                ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
                ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
                ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
                fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
                fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

                // The enumFieldError enumerator can be inspected at this point to determine
                // which fields were modified during validation.

                // create and return the table
                table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, storageKeyword);

                // create the openstreetmap spcific metadata
                _osmUtility.CreateOSMMetadata((IDataset)table, metadataAbstract, metadataPurpose);
            }
            catch
            {
                throw;
            }

            return table;
        }
Пример #10
0
        /// <summary>
        /// 这个字段要是唯一的
        /// </summary>
        /// <param name="_FilePath"></param>
        /// <param name="_TableName"></param>
        /// <param name="_pFeatureClass"></param>
        /// <param name="_FieldName"></param>
        /// <returns></returns>
        private ITable CreateWeightTable(string _FilePath, string _TableName, IFeatureClass _pFeatureClass, string _FieldName)
        {
            IWorkspaceFactory pWks = new ShapefileWorkspaceFactoryClass();

            IFeatureWorkspace pFwk = pWks.OpenFromFile(_FilePath, 0) as IFeatureWorkspace;

            //用于添加表中的必要字段
            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

            IFields pTableFields = objectClassDescription.RequiredFields;

            IFieldsEdit pTableFieldsEdit = pTableFields as IFieldsEdit;

            int index = _pFeatureClass.FindField(_FieldName);

            IField pField = new FieldClass();

            IFieldEdit pFieldEdit = pField as IFieldEdit;

            pFieldEdit.Name_2 = "Name";
            pTableFieldsEdit.AddField(pFieldEdit);

            pFieldEdit.Type_2 = _pFeatureClass.Fields.get_Field(index).Type;
            //ArrayList arrValues = GetUniqueFieldValue(pPolygonFClass, "NAME");

            IFeatureCursor pFtCursor = _pFeatureClass.Search(null, false);

            IFeature pFt = pFtCursor.NextFeature();

            while (pFt != null)
            {
                IField pFieldv = new FieldClass();

                IFieldEdit pFieldEditv = pFieldv as IFieldEdit;

                pFieldEditv.Name_2 = pFt.get_Value(index).ToString();
                pFieldEditv.Type_2 = esriFieldType.esriFieldTypeInteger;
                pTableFieldsEdit.AddField(pFieldEditv);
                pFt = pFtCursor.NextFeature();
            }

            ITable pTable = pFwk.CreateTable(_TableName, pTableFields, null, null, "");

            IFeatureCursor pFtCursor1 = _pFeatureClass.Search(null, false);

            IFeature pFt1 = pFtCursor1.NextFeature();

            //  ICursor  pcr = pTable .Insert(true);

            while (pFt1 != null)
            {

                IRow pRow = pTable.CreateRow();

                pRow.set_Value(1, pFt1.get_Value(index));

                pRow.Store();

                pFt1 = pFtCursor1.NextFeature();
            }

            return pTable;
        }