ICursor pCursor;
featureSelect.SelectionSet.Search(null, false, out pCursor);
IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;
IFeature pFeatureFirst = pFeatureCursor.NextFeature();
// 开始一个编辑操作,以能够撤销
m_EditWorkspace.StartEditOperation();
IGeometry pGeometryFirst = pFeatureFirst.Shape;
ITopologicalOperator2 topo_oper = (ITopologicalOperator2)pGeometryFirst;
//ITopologicalOperator的操作是bug很多的,先强制的检查下面三个步骤,再进行操作
//成功的可能性大一些
topo_oper.IsKnownSimple_2 = false;
topo_oper.Simplify();
pGeometryFirst.SnapToSpatialReference();
//这是准备合并的图斑使用的
ITopologicalOperator2 topo_oper2;
IGeometry pGeometryNext;
IFeature pFeatureNext = pFeatureCursor.NextFeature();
while (pFeatureNext != null)
{
pGeometryNext = pFeatureNext.ShapeCopy;
//与上面的同理
topo_oper2 = pGeometryNext as ITopologicalOperator2;
topo_oper2.IsKnownSimple_2 = false;
topo_oper2.Simplify();
pGeometryNext.SnapToSpatialReference();
//这才是合并图斑的关键
pGeometryFirst = topo_oper.Union(pGeometryNext);
pFeatureNext.Delete();
pFeatureNext = pFeatureCursor.NextFeature();
}
topo_oper.IsKnownSimple_2 = false;
topo_oper.Simplify();
pFeatureFirst.Shape = pGeometryFirst;
pFeatureFirst.Store();
m_EditWorkspace.StopEditOperation();
featureSelect.SelectionSet.Search(null, false, out pCursor);
IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;
IFeature pFeatureFirst = pFeatureCursor.NextFeature();
// 开始一个编辑操作,以能够撤销
m_EditWorkspace.StartEditOperation();
IGeometry pGeometryFirst = pFeatureFirst.Shape;
ITopologicalOperator2 topo_oper = (ITopologicalOperator2)pGeometryFirst;
//ITopologicalOperator的操作是bug很多的,先强制的检查下面三个步骤,再进行操作
//成功的可能性大一些
topo_oper.IsKnownSimple_2 = false;
topo_oper.Simplify();
pGeometryFirst.SnapToSpatialReference();
//这是准备合并的图斑使用的
ITopologicalOperator2 topo_oper2;
IGeometry pGeometryNext;
IFeature pFeatureNext = pFeatureCursor.NextFeature();
while (pFeatureNext != null)
{
pGeometryNext = pFeatureNext.ShapeCopy;
//与上面的同理
topo_oper2 = pGeometryNext as ITopologicalOperator2;
topo_oper2.IsKnownSimple_2 = false;
topo_oper2.Simplify();
pGeometryNext.SnapToSpatialReference();
//这才是合并图斑的关键
pGeometryFirst = topo_oper.Union(pGeometryNext);
pFeatureNext.Delete();
pFeatureNext = pFeatureCursor.NextFeature();
}
topo_oper.IsKnownSimple_2 = false;
topo_oper.Simplify();
pFeatureFirst.Shape = pGeometryFirst;
pFeatureFirst.Store();
m_EditWorkspace.StopEditOperation();