版权声明:欢迎评论和转载,转载请注明来源。 https://blog.csdn.net/zy332719794/article/details/37903625
public static IFeatureClass CreateMemoryFeatureClass(
ISpatialReference spatialReference, esriGeometryType geometryType, string name = "Temp")
{
// 创建内存工作空间
IWorkspaceFactory pWSF = new InMemoryWorkspaceFactoryClass();
IWorkspaceName pWSName = pWSF.Create("", "Temp", null, 0);
IName pName = (IName)pWSName;
IWorkspace memoryWS = (IWorkspace)pName.Open();
IField field = new FieldClass();
IFields fields = new FieldsClass();
IFieldsEdit fieldsEdit = fields as IFieldsEdit;
IFieldEdit fieldEdit = field as IFieldEdit;
fieldEdit.Name_2 = "OBJECTID";
fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
fieldEdit.IsNullable_2 = false;
fieldEdit.Required_2 = false;
fieldsEdit.AddField(field);
field = new FieldClass();
fieldEdit = field as IFieldEdit;
IGeometryDef geoDef = new GeometryDefClass();
IGeometryDefEdit geoDefEdit = (IGeometryDefEdit)geoDef;
geoDefEdit.AvgNumPoints_2 = 5;
geoDefEdit.GeometryType_2 = geometryType;
geoDefEdit.GridCount_2 = 1;
geoDefEdit.HasM_2 = false;
geoDefEdit.HasZ_2 = false;
geoDefEdit.SpatialReference_2 = spatialReference;
fieldEdit.Name_2 = "SHAPE";
fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
fieldEdit.GeometryDef_2 = geoDef;
fieldEdit.IsNullable_2 = true;
fieldEdit.Required_2 = true;
fieldsEdit.AddField(field);
field = new FieldClass();
fieldEdit = field as IFieldEdit;
fieldEdit.Name_2 = "Code";
fieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
fieldEdit.IsNullable_2 = true;
fieldsEdit.AddField(field);
//创建要素类
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)memoryWS;
IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(
name, fields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
return featureClass;
}