|
阅读:991回复:0
如何调用ITopologicalOperator.Union方法进行地merge polygon
<DIV class=postText>ITopologicalOperator的方法是bug非常多的,在90%的情况下能够按照你预想的工作,但是在10%的情况下,既不报错也不工作。</DIV>
<DIV class=postText> ICursor pCursor;<BR> featureSelect.SelectionSet.Search(null, false, out pCursor);</DIV> <DIV class=postText> IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;<BR> IFeature pFeatureFirst = pFeatureCursor.NextFeature();</DIV> <DIV class=postText> // 开始一个编辑操作,以能够撤销<BR> m_EditWorkspace.StartEditOperation();</DIV> <DIV class=postText> IGeometry pGeometryFirst = pFeatureFirst.Shape;<BR> ITopologicalOperator2 topo_oper = (ITopologicalOperator2)pGeometryFirst;</DIV> <DIV class=postText> //ITopologicalOperator的操作是bug很多的,先强制的检查下面三个步骤,再进行操作<BR> //成功的可能性大一些<BR> topo_oper.IsKnownSimple_2 = false;<BR> topo_oper.Simplify();<BR> pGeometryFirst.SnapToSpatialReference();</DIV> <DIV class=postText> //这是准备合并的图斑使用的<BR> ITopologicalOperator2 topo_oper2;<BR> IGeometry pGeometryNext;<BR> IFeature pFeatureNext = pFeatureCursor.NextFeature();</DIV> <DIV class=postText> while (pFeatureNext != null)<BR> {<BR> pGeometryNext = pFeatureNext.ShapeCopy;</DIV> <DIV class=postText> //与上面的同理<BR> topo_oper2 = pGeometryNext as ITopologicalOperator2;<BR> topo_oper2.IsKnownSimple_2 = false;<BR> topo_oper2.Simplify();<BR> pGeometryNext.SnapToSpatialReference();</DIV> <DIV class=postText> //这才是合并图斑的关键<BR> pGeometryFirst = topo_oper.Union(pGeometryNext);<BR> pFeatureNext.Delete();</DIV> <DIV class=postText> pFeatureNext = pFeatureCursor.NextFeature();<BR> }<BR> topo_oper.IsKnownSimple_2 = false;<BR> topo_oper.Simplify();<BR> pFeatureFirst.Shape = pGeometryFirst;<BR> pFeatureFirst.Store();<BR> m_EditWorkspace.StopEditOperation();<BR></DIV> |
|
|