ArcgisEngine(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);
engine什么意思//两个⼏何对象的⼏何操作还有:
//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);
发布评论