/// <summary> /// 获取构成多边形的所有环的点集(包括外环和内环),返回的环内的点集统一按顺时针或逆时针排序 /// </summary> /// <param name="polygon"></param> /// <param name="clockwise">时针方向,true为顺时针,false为逆时针</param> /// <returns></returns> public static List <List <IPoint> > GetRingPointsByClockwise(this IPolygon4 polygon, bool clockwise) { List <List <IPoint> > rings = new List <List <IPoint> >(); //外部环 IGeometryBag exteriorRingGeometryBag = polygon.ExteriorRingBag;//全部外部环 IGeometryCollection exteriorRingGeometryCollection = (IGeometryCollection)exteriorRingGeometryBag; for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++) { IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i); IPointCollection exteriorRingPointCollection = exteriorRingGeometry as IPointCollection; var exteriorPoints = exteriorRingPointCollection.GetPointList(); if (!clockwise)//外环的点是顺时针排序的,要求逆时针排序时反序List { exteriorPoints.Reverse(); } rings.Add(exteriorPoints); //外部环 var interiorRings = GetInteriorRingPoints(polygon, exteriorRingGeometry as IRing); //内部环 if (clockwise) //内环的点是逆时针排序的,要求顺时针排序时反序List { foreach (var ring in interiorRings) { ring.Reverse(); } } rings.AddRange(interiorRings); } return(rings); }
/// <summary> /// 获取构成多边形的所有环的点集(包括外环和内环) /// </summary> /// <param name="polygon"></param> /// <returns></returns> public static List <List <IPoint> > GetRingPoints(this IPolygon4 polygon) { List <List <IPoint> > rings = new List <List <IPoint> >(); //外部环 IGeometryBag exteriorRingGeometryBag = polygon.ExteriorRingBag;//全部外部环 IGeometryCollection exteriorRingGeometryCollection = (IGeometryCollection)exteriorRingGeometryBag; for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++) { IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i); IPointCollection exteriorRingPointCollection = exteriorRingGeometry as IPointCollection; var exteriorPoints = exteriorRingPointCollection.GetPointList(); rings.Add(exteriorPoints); //外部环 rings.AddRange(GetInteriorRingPoints(polygon, exteriorRingGeometry as IRing)); //内部环 } return(rings); }
/// <summary> /// 获取构成环的所有点集 /// </summary> /// <param name="ring"></param> /// <returns></returns> public static List <IPoint> GetRingPoints(this IRing ring) { IPointCollection pointCollection = ring as IPointCollection; return(pointCollection.GetPointList()); }