ArcEngine利用ITopologicalOperator实现裁剪功能
http://blog.csdn.net/longronggis/article/details/8125800
本博客发表过一篇ArcEngine通过调用GP工具实现裁剪的文章,但是GP工具对输入输出的参数要求高,而且用于裁剪的图层为shp文件,如果在系统中需要通过鼠标绘制图形实现裁剪,那么GP工具就不是那么方便。博主通过参考其他文章,实现了利用ITopologicalOperator完成裁剪功能,该方法同样适用于文件类型的裁剪图层,也适用于鼠标绘制实现裁剪。
IGeometry outputGeometry = null; //裁剪后的图形
ITopologicalOperator2 topo = null;
if (sourceGeometry.SpatialReference != clipGeometry.SpatialReference) //sourceGeometry为被裁剪的图形
{
clipGeometry.Project(sourceGeometry.SpatialReference);
} //此处应保持裁剪与被裁剪图层的空间参考一致,否则容易发生异常
switch (sourceGeometry.GeometryType)
{
case esriGeometryType.esriGeometryPolyline:
topo = sourceGeometry as ITopologicalOperator2;
topo.IsKnownSimple_2 = true;
topo.Simplify();
outputGeometry = topo.Intersect(topo.Intersect(clipGeometry, esriGeometryDimension.esriGeometry1Dimension), esriGeometryDimension.esriGeometry1Dimension);
break;
case esriGeometryType.esriGeometryPolygon:
topo = sourceGeometry as ITopologicalOperator2;
topo.IsKnownSimple_2 = true;
topo.Simplify();
outputGeometry = topo.Difference(topo.Difference(clipGeometry));
break;
default:
outputGeometry = sourceGeometry;
break;
}
return outputGeometry;
转载自:https://blog.csdn.net/zkcharge/article/details/17267929