C#+Ae实现CreateFeatureClass() 方法的代码
时间: 2023-12-03 09:44:18 浏览: 255
下面是使用ArcObjects的C#代码实现CreateFeatureClass()方法:
```csharp
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
public void CreateFeatureClass(string workspacePath, string featureClassName, esriGeometryType geometryType)
{
//打开工作空间
IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
IWorkspace workspace = workspaceFactory.OpenFromFile(workspacePath, 0);
IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;
//设置字段集
IFields fields = new Fields();
IFieldsEdit fieldsEdit = fields as IFieldsEdit;
fieldsEdit.AddField(CreateField("ID", esriFieldType.esriFieldTypeOID));
fieldsEdit.AddField(CreateField("Name", esriFieldType.esriFieldTypeString));
//创建要素类
IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(featureClassName, fields, null, null, geometryType, "Shape", "");
}
private IField CreateField(string name, esriFieldType fieldType)
{
IField field = new Field();
IFieldEdit fieldEdit = field as IFieldEdit;
fieldEdit.Name_2 = name;
fieldEdit.Type_2 = fieldType;
return field;
}
```
其中,`workspacePath`为工作空间路径,`featureClassName`为要素类名称,`geometryType`为几何类型。此方法将在指定工作空间中创建一个名为`featureClassName`的要素类,并添加两个字段“ID”和“Name”。
阅读全文