在对已经存在的Feature进行合并创建新的Feature时,应使用ITopologicalOperator.Union()方法,将两个Feature的Geometry联合在一起。
ITopologicalOperator.Union()方法官方说明: http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#/Union_Method/002m000003w2000000/
示例代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 private bool MerageCadastre(IFeature feat1, IFeature feat2, out string message) 2 { 3 IFeatureLayer currentLayer = m_engineEditLayers.TargetLayer as IFeatureLayer; 4 message = ""; 5 try 6 { 7 object missing = System.Type.Missing; 8 object obj3 = System.Type.Missing; 9 IPolygon MeragePolygon = (feat1.ShapeCopy as ITopologicalOperator).Union(feat2.ShapeCopy) as IPolygon; 10 IFeature MerageFeaure = currentLayer.FeatureClass.CreateFeature(); 11 MerageFeaure.Shape = MeragePolygon; 12 feat1.Shape.SetEmpty(); 13 feat2.Shape.SetEmpty(); 14 feat1.Store(); 15 feat2.Store(); 16 MerageFeaure.Store(); 17 CadastreEditCommon.AddItemToUndoStack(mylist, true, EditOperationType.MergeCadastre, currentLayer.FeatureClass); 18 return true; 19 20 } 21 catch (Exception exception) 22 { 23 message = exception.ToString(); 24 return false; 25 } 26 }
之前采用的则是新建IPolygon的方法。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 private bool MerageCadastre(IFeature feat1, IFeature feat2, out string message) 2 { 3 IFeatureLayer currentLayer = m_engineEditLayers.TargetLayer as IFeatureLayer; 4 message = ""; 5 try 6 { 7 object missing = System.Type.Missing; 8 object obj3 = System.Type.Missing; 9 IPolygon MeragePolygon = new PolygonClass(); 10 IPolygon geo1 = feat1.ShapeCopy as IPolygon; 11 IPolygon geo2 = feat2.ShapeCopy as IPolygon; 12 for (int i = 0; i < (geo1 as IGeometryCollection).GeometryCount; i++) 13 { 14 (MeragePolygon as IGeometryCollection).AddGeometry((geo1 as IGeometryCollection).get_Geometry(i), ref missing, ref obj3); 15 } 16 for (int i = 0; i < (geo2 as IGeometryCollection).GeometryCount; i++) 17 { 18 (MeragePolygon as IGeometryCollection).AddGeometry((geo2 as IGeometryCollection).get_Geometry(i), ref missing, ref obj3); 19 } 20 IFeature MerageFeaure = currentLayer.FeatureClass.CreateFeature(); 21 MerageFeaure.Shape = MeragePolygon; 22 feat1.Shape.SetEmpty(); 23 feat2.Shape.SetEmpty(); 24 feat1.Store(); 25 feat2.Store(); 26 MerageFeaure.Store(); 27 CadastreEditCommon.AddItemToUndoStack(mylist, true, EditOperationType.MergeCadastre, currentLayer.FeatureClass); 28 return true; 29 30 } 31 catch (Exception exception) 32 { 33 message = exception.ToString(); 34 return false; 35 } 36 }
一般情况下新建IPolygon方法能够满足需求,但在对已经存在的Feature进行拆分后再合并保存时,会出现当前编辑图层不显示的情况。
初步判断是对应的Feature的Geometry 未能成功保存。造成了整个图层无法显示的问题。