PublicESRI. ArcGIS.Geodatabase.IFeatureClass Createfeatureclass (ESRI. ArcGIS.Geodatabase.IWorkspace2 workspace, ESRI. ArcGIS.Geodatabase.IFeatureDataset Featuredataset, System.String featureclassname) {ESRI. ArcGIS.esriSystem.UID CLSID=NULL; ESRI. ArcGIS.esriSystem.UID Clsext=NULL; System.String Strconfigkeyword=NULL; if(Featureclassname = ="")return NULL;//name is not passed inESRI. 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); returnFeatureclass; } //assign the class ID value if not assigned if(CLSID = =NULL) {CLSID=NewESRI. ArcGIS.esriSystem.UIDClass (); Clsid. Value="esrigeodatabase.feature"; } ESRI. ArcGIS.Geodatabase.IObjectClassDescription objectclassdescription=NewESRI. ArcGIS.Geodatabase.FeatureClassDescriptionClass (); ESRI. ArcGIS.Geodatabase.IFields Fields=NULL; //if a Fields collection are not passed and then supply our own if(Fields = =NULL) { //Create The fields using the required fields methodFields =Objectclassdescription.requiredfields; ESRI. ArcGIS.Geodatabase.IFieldsEdit Fieldsedit= (ESRI. ArcGIS.Geodatabase.IFieldsEdit) fields;//Explicit CastESRI. ArcGIS.Geodatabase.IField field =NewESRI. ArcGIS.Geodatabase.FieldClass (); //Create a User defined text fieldESRI. ArcGIS.Geodatabase.IFieldEdit Fieldedit = (ESRI. ArcGIS.Geodatabase.IFieldEdit) field;//Explicit Cast//setup Field Propertiesfieldedit.name_2 ="Zbdid"; Fieldedit.type_2=ESRI. ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString; Fieldedit.isnullable_2=true; Fieldedit.aliasname_2="Coordinate number"; Fieldedit.defaultvalue_2="0"; Fieldedit.editable_2=true; Fieldedit.length_2= -; //add field to field collectionFieldsedit.addfield (field); fields= (ESRI. ArcGIS.Geodatabase.IFields) Fieldsedit;//Explicit Cast} System.String Strshapefield=""; //Locate the Shape field for(intj =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 the Fields collection.ESRI. ArcGIS.Geodatabase.IFieldChecker Fieldchecker =NewESRI. 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, outEnumfielderror, outvalidatedfields); //The Enumfielderror Enumerator can be inspected at the-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); } returnFeatureclass; }
Arcengine Creating a Feature class