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);