In ESRI ArcGIS if we want to store spatial object so we need to create a container where we can store spatial data. In ArcGIS, if we want to store spatial as well as non-spatial data together we can create feature class.
The feature class is a spatial object where we can store spatial data with non-spatial properties. For Example, if we want to store ATM information we will create ATM feature class and store the data in that. In ATM feature class there are two things we can store one is the spatial information like which type of geometry we are going to store like Point/Line/Polygon and second is non-spatial property like Bank Name, Bank Address, Bank Type, ATM type.
To Create feature class, we have to create Geodatabase and within Geodatabase we can create feature class either this feature class is normal feature class or Standalone feature class. We can create feature class using Arc Catalog application or if required we can create programmatically using ArcObject. To create programmatically we need required Name of a feature class, spatial reference of geometry, type of geometry, non-spatial fields and its description.
- IWorkspaceFactory wsfShp = new ShapefileWorkspaceFactoryClass();
- IWorkspace pws = wsfShp.OpenFromFile(@ "D:\YS\ShapeFiles\Street", 0);
- IFeatureWorkspace pfeatWs = (IFeatureWorkspace) pws;
- IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
- IObjectClassDescription ocDescription = (IObjectClassDescription) fcDescription;
- IFields fields = ocDescription.RequiredFields;
- IFieldsEdit fieldsEdit = (IFieldsEdit) fields;
- IField oidField = new FieldClass();
- IFieldEdit oidFieldEdit = (IFieldEdit) oidField;
- oidFieldEdit.Name_2 = "OID";
- oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
- fieldsEdit.FieldCount_2 = 3;
- fieldsEdit.Field_2[0] = oidField;
-
-
- IField field = new FieldClass();
- IFieldEdit fieldEdit = (IFieldEdit) field;
- fieldEdit.Name_2 = "Name";
- fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
- fieldsEdit.Field_2[1] = field;
-
- IGeometryDef geometryDef = new GeometryDefClass();
- IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit) geometryDef;
- geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
- ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironment();
- ISpatialReference spatialReference = spatialReferenceFactory.CreateProjectedCoordinateSystem((int) esriSRProjCSType.esriSRProjCS_NAD1983UTM_20N);
- ISpatialReferenceResolution spatialReferenceResolution = (ISpatialReferenceResolution) spatialReference;
- spatialReferenceResolution.ConstructFromHorizon();
- ISpatialReferenceTolerance spatialReferenceTolerance = (ISpatialReferenceTolerance) spatialReference;
- spatialReferenceTolerance.SetDefaultXYTolerance();
- geometryDefEdit.SpatialReference_2 = spatialReference;
-
- IField geometryField = new FieldClass();
- IFieldEdit geometryFieldEdit = (IFieldEdit) geometryField;
- geometryFieldEdit.Name_2 = "Shape";
- geometryFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
- geometryFieldEdit.GeometryDef_2 = geometryDef;
- fieldsEdit.Field_2[2] = geometryField;
-
- IFieldChecker fieldChecker = new FieldCheckerClass();
- IEnumFieldError enumFieldError = null;
- IFields validatedFields = null;
- fieldChecker.ValidateWorkspace = (IWorkspace) pfeatWs;
- fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
- IFeatureClass featureClass = pfeatWs.CreateFeatureClass("Road", validatedFields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "Shape", "");