添加矢量数据(点)
// 将ILayer转换为IFeaturelayer,为了对图层上的要素进行编辑
ILayer pLayer = GetGallery(ActiveGallery);
IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;
// 定义一个要素集合,并获取图层的要素集合
IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;
// 定义一个实现添加要素的接口实例,并该实例作用于当前图层的要素集
IFeatureClassWrite fr = (IFeatureClassWrite)pFeatCls;
// 定义一个工作编辑工作空间,用于开启前图层的编辑状态
IWorkspaceEdit w = (pFeatCls as IDataset).Workspace as IWorkspaceEdit;
IFeature f;
// 开启编辑状态
w.StartEditing(true);
w.StartEditOperation();
// 开启编辑操作
//将IPoint设置为IFeature的shape属性时,需要通过中间接口IGeometry转换
Geometry peo;
peo = ppt;
f = pFeatCls.CreateFeature();//实例化IFeature对象, 这样IFeature对象就具有当前图层上要素的字段信息
f.Shape = peo;//设置IFeature对象的形状属性
for (int i = 0; i < obj.fieldNameArray.Count; i++)
{
int index = f.Fields.FindField(obj.fieldNameArray[i].ToString());
if (index != -1)
f.set_Value(i, obj.fieldValueArray[i]);//设置IFeature对象的索引是3的字段值
}
f.Store();//保存IFeature对象
fr.WriteFeature(f);//将IFeature对象,添加到当前图层上
w.StopEditOperation();//停止编辑操作
w.StopEditing(true);//关闭编辑状态,并保存修改