您的位置:首页 > 其它

属性表的创建及记录的添加

2015-08-14 15:43 357 查看
1、创建新表

/// <summary>
/// 创建一个只有ZID的数据表
/// </summary>
/// <param name="path">属性表文件路径(包括属性名)</param>
/// <returns></returns>
static public ITable CreateTable(string path)
{

string _TablePath = Path.GetDirectoryName(path);
string _TableName = Path.GetFileName(path);
IWorkspaceFactory pWks = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace pFwk = pWks.OpenFromFile(_TablePath, 0) as IFeatureWorkspace;
//添加字段
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = "ZID";//字段名称
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;//字段类型
//用于添加表中的必要字段
ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription =
new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

IFields pTableFields = objectClassDescription.RequiredFields;
IFieldsEdit pFieldsEdit = pTableFields as IFieldsEdit;
pFieldsEdit.AddField(pField);
ITable pTable = pFwk.CreateTable(_TableName, pTableFields, null, null, "");
return pTable;

}


[/code]
2、向已有表中添加字段

            ITable pTable = CreateTable(path);
IField pFieldValue = new FieldClass();
IFieldEdit pFieldEdit = pFieldValue as IFieldEdit;
pFieldEdit.Name_2 = "面积比";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
pTable.AddField(pFieldValue);


3、设置属性值(增)
                   IRow pRow = pTable.CreateRow();
pRow.set_Value(1, value1);
pRow.set_Value(2, value2);
pRow.Store();

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: