FeatureClass下创建要素(CreateFeature)遇到的一些问题及解决

今天需要做一个小功能,根据点列表来生成一个多边形,并将其添加到某图层中,初始代码:

 

IFeature tmpFea = fLayer.FeatureClass.CreateFeature(); tmpFea.Shape = tmpPoly; tmpFea.Store();

 

出现一个问题:新添加的要素经常会不显示,需要缩放到全图,才偶尔能显示出来,但在属性表中是能够看到的,在ArcMap中查看也同样如此,但在ArcMap中编辑图层,再保存一下问题就解决了,所以,将代码改为如下文所示:

IDataset dataset = (IDataset)fLayer.FeatureClass; IWorkspace workspace = dataset.Workspace; //Cast for an IWorkspaceEdit IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; //start an edit session and operation workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); IFeature tmpFea = fLayer.FeatureClass.CreateFeature(); tmpFea.Shape = tmpPoly; tmpFea.Store(); //stop editing workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true);

试运行一下,问题解决了,但出现了一个新问题,图层的EXTENT并没有因为添加了一个要素而自动更改,在代码最后添加了两行,解决了这个问题:

IFeatureClassManage featureClassManage = (IFeatureClassManage)fLayer.FeatureClass; featureClassManage.UpdateExtent();

 

你可能感兴趣的:(c#,engine)