首页 > 代码库 > 创建FeatureClass
创建FeatureClass
///<summary>Simple helper to create a featureclass in a geodatabase.</summary>/// ///<param name="workspace">An IWorkspace2 interface</param>///<param name="featureDataset">An IFeatureDataset interface or Nothing</param>///<param name="featureClassName">A System.String that contains the name of the feature class to open or create. Example: "states"</param>///<param name="fields">An IFields interface</param>///<param name="CLSID">A UID value or Nothing. Example "esriGeoDatabase.Feature" or Nothing</param>///<param name="CLSEXT">A UID value or Nothing (this is the class extension if you want to reference a class extension when creating the feature class).</param>///<param name="strConfigKeyword">An empty System.String or RDBMS table string for ArcSDE. Example: "myTable" or ""</param>/// ///<returns>An IFeatureClass interface or a Nothing</returns>/// ///<remarks>/// (1) If a ‘featureClassName‘ already exists in the workspace a reference to that feature class /// object will be returned./// (2) If an IFeatureDataset is passed in for the ‘featureDataset‘ argument the feature class/// will be created in the dataset. If a Nothing is passed in for the ‘featureDataset‘/// argument the feature class will be created in the workspace./// (3) When creating a feature class in a dataset the spatial reference is inherited /// from the dataset object./// (4) 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./// (5) The ‘strConfigurationKeyword‘ parameter allows the application to control the physical layout /// for this table in the underlying RDBMSfor example, in the case of an Oracle database, the /// configuration keyword controls the tablespace in which the table is created, the initial and /// next extents, and other properties. The ‘strConfigurationKeywords‘ for an ArcSDE instance are /// set up by the ArcSDE data administrator, the list of available keywords supported by a workspace /// may be obtained using the IWorkspaceConfiguration interface. For more information on configuration /// keywords, refer to the ArcSDE documentation. When not using an ArcSDE table use an empty /// string (ex: "").///</remarks>public ESRI.ArcGIS.Geodatabase.IFeatureClass CreateFeatureClass(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, ESRI.ArcGIS.Geodatabase.IFeatureDataset featureDataset, System.String featureClassName, ESRI.ArcGIS.Geodatabase.IFields fields, ESRI.ArcGIS.esriSystem.UID CLSID, ESRI.ArcGIS.esriSystem.UID CLSEXT, System.String strConfigKeyword){ if (featureClassName == "") return null; // name was not passed in ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName)) //feature class with that name already exists { featureClass = featureWorkspace.OpenFeatureClass(featureClassName); return featureClass; } // assign the class id value if not assigned if (CLSID == null) { CLSID = new ESRI.ArcGIS.esriSystem.UIDClass(); CLSID.Value = "http://www.mamicode.com/esriGeoDatabase.Feature"; } ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass(); // 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 ESRI.ArcGIS.Geodatabase.IField field = new ESRI.ArcGIS.Geodatabase.FieldClass(); // create a user defined text field ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field; // Explicit Cast // setup field properties fieldEdit.Name_2 = "SampleField"; fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString; fieldEdit.IsNullable_2 = true; fieldEdit.AliasName_2 = "Sample Field Column"; fieldEdit.DefaultValue_2 = "test"; fieldEdit.Editable_2 = true; fieldEdit.Length_2 = 100; // add field to field collection fieldsEdit.AddField(field); fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast } System.String strShapeField = ""; // locate the shape field for (int j = 0; j < fields.FieldCount; j++) { if (fields.get_Field(j).Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry) { strShapeField = fields.get_Field(j).Name; } } // 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. // finally create and return the feature class if (featureDataset == null)// if no feature dataset passed in, create at the workspace level { featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword); } else { featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword); } return featureClass;}
源:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Create_FeatureClass_Snippet/0049000000pz000000/
创建FeatureClass
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。