ArcObjects Library Reference  (GeoDatabase)    

IFeatureWorkspace CreateFeatureClass Example

[Visual Basic 6.0]
Public Sub CreateShapefile()

  Const strFolder As String = "D:\DATA"
  Const strName As String = "MyShapeFile" ' Dont include .shp extension
  Const strShapeFieldName As String = "Shape"
 
  ' Open the folder to contain the shapefile as a workspace
  Dim pFWS As IFeatureWorkspace
  Dim pWorkspaceFactory As IWorkspaceFactory
  Set pWorkspaceFactory = New ShapefileWorkspaceFactory
  Set pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)
 
  ' Set up a simple fields collection
  Dim pFields As IFields
  Dim pFieldsEdit As IFieldsEdit
  Set pFields = New esriGeoDatabase.Fields
  Set pFieldsEdit = pFields
 
  Dim pField As IField
  Dim pFieldEdit As IFieldEdit
 
  ' Make the shape field
  ' it will need a geometry definition, with a spatial reference
  Set pField = New esriGeoDatabase.Field
  Set pFieldEdit = pField
  pFieldEdit.Name = strShapeFieldName
  pFieldEdit.Type = esriFieldTypeGeometry
 
  Dim pGeomDef As IGeometryDef
  Dim pGeomDefEdit As IGeometryDefEdit
  Set pGeomDef = New GeometryDef
  Set pGeomDefEdit = pGeomDef
  With pGeomDefEdit
    .GeometryType = esriGeometryPolygon
    Set .SpatialReference = New UnknownCoordinateSystem
  End With
  Set pFieldEdit.GeometryDef = pGeomDef
  pFieldsEdit.AddField pField

  ' Add another miscellaneous text field
  Set pField = New esriGeoDatabase.Field
  Set pFieldEdit = pField
  With pFieldEdit
      .Length = 30
      .Name = "MiscText"
      .Type = esriFieldTypeString
  End With
  pFieldsEdit.AddField pField
 
  ' Create the shapefile
  ' (some parameters apply to geodatabase options and can be defaulted as Nothing)
  Dim pFeatClass As IFeatureClass
  Set pFeatClass = pFWS.CreateFeatureClass(strName, pFields, Nothing, _
                                           Nothing, esriFTSimple, strShapeFieldName, "")
End Sub


[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button Language Filter in the upper-left corner of the page.