通过IFeatureBuffer操作要素,进行要素的插入和更新
public void Updatefeature()
{
IFeatureClass fc = null;
IFeatureCursor feaCursor = null;
IFeature pFea = null;
feaCursor = fc.Update(null, false);
while ((pFea = feaCursor.NextFeature()) != null)
{
IFeatureBuffer feaBuffer = pFea as IFeatureBuffer;
foreach (string fieldName in new List<string>())
{
feaBuffer.set_Value(pFea.Fields.FindField("字段名"), fieldName);
}
feaCursor.UpdateFeature(pFea);
}
feaCursor.Flush();
}
public void Insertfeature()
{
IFeatureLayer newLayer = null;
IFeatureBuffer buffer = newLayer.FeatureClass.CreateFeatureBuffer();
IFeatureCursor pFeatureCursor = newLayer.FeatureClass.Insert(true);
try
{
buffer.Shape = new PointClass() { X = 100, Y = 100 };// new PointClass() { X = x, Y = y };// GetProjectFormGeo(x,y);
buffer.Value[buffer.Fields.FindField("字段名")] = "字段值";
pFeatureCursor.InsertFeature(buffer);
}
catch (Exception ex)
{
pFeatureCursor.InsertFeature(buffer);
pFeatureCursor.Flush();
}
pFeatureCursor.Flush();
}