Arcgis Engine(ae)接口详解(5):IGeometry几何高级操作

            IPoint point = new PointClass();
point.PutCoords(100, 200);

//ITopologicalOperator接口用于几何对象的几何操作
ITopologicalOperator topo = point as ITopologicalOperator;
//做一个几何对象的缓冲区(结果也是个几何对象),参数1是缓冲半径
//点线面的缓冲区都是面,所以可以直接as到IPolygon
IPolygon polygon = topo.Buffer(100) as IPolygon;

ITopologicalOperator2 topo2 = point as ITopologicalOperator2;
//错误几何对象的修复,如果当几何对象有几何错误,例如面有自相交,可以用此修复
topo2.IsKnownSimple_2 = false;
topo2.Simplify();

topo = polygon as ITopologicalOperator;
//获取面的边,面的边是线
IPolyline polyline = topo.Boundary as IPolyline;

IPolygon polygon2 = new PolygonClass();

topo = polygon as ITopologicalOperator;
//求两个几何对象的重叠部分
//两个几何对象的重叠部分,可以有很多种几何类型组合,例如面与面重叠是面,线与线重叠是线或者点,点与点重叠是点,点与面重叠是点,线与面重叠是线等等
//参数2是返回结果是多少维的意思,根据经验如果返回结果是点就是0维(esriGeometry0Dimension),线就是1维,面就是2维
//官方文档还有详细说明,使用者要结合文档和实际使用情况相互对照来学习
IGeometry geometry3 = topo.Intersect(polygon2, esriGeometryDimension.esriGeometry2Dimension);

//两个几何对象的几何操作还有:
//Union 求两个几何对象合并后的,也就是求并集
//Clip 裁剪
//Cut 用线把面一份为二
//Difference 擦除

//IRelationalOperator用于判断两个几何对象的空间关系
//IRelationalOperator的每种空间关系在官方文档有具体截图
IRelationalOperator relaOper = polygon as IRelationalOperator;
//求两个几何对象是否有重叠部分,注意:Overlaps判断的两个几何对象的几何类型必须相同
bool result = relaOper.Overlaps(polygon2);

//其他空间关系判断有:
//Contains-完全包含
//Crosses-穿过?
//Disjoint-完全不相交
//Equals-完全重叠(就是两个几何对象完全一样,常用!!!!!)
//Touches-边沿重叠?
//Within-完全包含2

IPoint point2 = new PointClass();
point.PutCoords(200, 300);

//计算两点距离
double distance = GeometryHelper.TwoPointDistance(point, point2);
调用过的封装函数
        /// <summary>
/// 计算两点距离
/// </summary>
/// <param name="point1"></param>
/// <param name="point2"></param>
/// <returns></returns>
public static double TwoPointDistance(IPoint point1, IPoint point2)
{
if (point1 == null || point2 == null) return 0;

return TwoPointDistance(point1.X, point1.Y, point2.X, point2.Y);
}

/// <summary>
/// 计算两点距离
/// </summary>
/// <param name="x1"></param>
/// <param name="y1"></param>
/// <param name="x2"></param>
/// <param name="y2"></param>
/// <returns></returns>
public static double TwoPointDistance(double x1, double y1, double x2, double y2)
{
return Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
}

1 个评论

史上最好、最经典的ArcGIS Engine和ArcGIS Python开发学习教程重磅出炉了,观看地址: http://i.youku.com/gisxiaotian

下载地址:https://gisxiaotian.taobao.com/

要回复文章请先登录注册