2017-05-31 84 views
-1

我創建了點要素。但我不能添加數據屬性表。如何創建點要素並同時在屬性表中添加數據?

IMxDocument pMxdoc = ArcMap.Application.Document as IMxDocument; 
IPoint pPoint = pMxdoc.ActivatedView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y); 
IFeatureLayer pFLayer = pMxdoc.FocusMap.Layer[3] as IFeatureLayer; 
IWorkspaceEdit pWSE = ((IDataset)(pFLayer.FeatureClass)).Workspace as IWorkspaceEdit; 
pWSE.StartEditing(false); 
pWSE.StartEditOperation(); 

IFeature pFeature = pFLayer.FeatureClass.CreateFeature(); 
pFeature.Shape = pPoint; 
pFeature.Store(); 

// I want to add data in table this here but how? 

pWSE.StopEditOperation(); 
pWSE.StopEditing(true); 

pMxdoc.ActivatedView.Refresh(); 

回答

3

你只給特徵分配一個幾何圖形,但你可能需要更多的屬性。因此,您應該使用set_Value設置屬性值:

int fieldIndex = myFeatureClass.FindField(attributeName); 
object newValue = "newValue"; 
IFeature pFeature = pFLayer.FeatureClass.CreateFeature(); 
pFeature.set_Value(fieldIndex, newValue); 
pFeature.Shape = pPoint; 
pFeature.Store(); 
+0

它正在工作。感謝HimBromBeere –

相關問題