public static bool IsHoleReferenced(Entity ent, Transaction tr) { if (ent is Polyline2d || ent is Polyline) { // 如果不是flag,没有被引用 string cassFlag = CadUtils.GetCassFlag(ent); if (CassFlagIsland.ToLower() != cassFlag.ToLower()) { return(false); } var groupId = GroupUtils.FindEntityGroupId(tr, ent); if (!groupId.IsValid) { return(false); } // 如果不是flag,没有被引用 //ObjectId[] entityIds = GroupUtils.GetGroupedObjects(ent); //foreach (ObjectId entityId in entityIds) //{ //} var realId = ParcelPolygon.FindParcelOfHole(tr, ent); if (realId.IsNull) { return(false); } return(true); } return(false); }
public static ObjectId FindParcelOfHole(Transaction tr, Entity hole) { var entityIds = GroupUtils.GetGroupedObjects(tr, hole); ObjectId entityId = ObjectId.Null; foreach (var objectId in entityIds) { if (objectId == hole.Id) { continue; } using (var ent = tr.GetObject(objectId, OpenMode.ForRead)) { if (ent is Polyline2d || ent is Polyline) { string cassFlag = CadUtils.GetCassFlag(ent); if (CassFlagName.ToLower() == cassFlag.ToLower()) { entityId = objectId; break; } } } } return(entityId); }
static bool IsPolygonHasHole(Transaction tr, Entity entity) { ObjectId[] entityIds = GroupUtils.GetGroupedObjects(tr, entity); foreach (ObjectId entityId in entityIds) { // 如果是本地块,直接skip if (entity.ObjectId == entityId) { continue; } using (var ent = tr.GetObject(entityId, OpenMode.ForRead)) { if (ent is Polyline2d || ent is Polyline) { string cassFlag = CadUtils.GetCassFlag(ent); if (CassFlagIsland.ToLower() == cassFlag.ToLower()) { return(true); } } } } return(false); }
static Dictionary <ObjectId, IList <ObjectId> > GetPolygonHasHole(Database database, Quadtree <IGeometry> quadtree, IEnumerable <IPolygon> polygons) { var dictionary = new Dictionary <ObjectId, IList <ObjectId> >(); var possibleHoleIds = new List <ObjectId>(); using (var tr = database.TransactionManager.StartTransaction()) { // 便利多边形,如果有洞,开始计算 foreach (var polygon in polygons) { // 找洞 var insidePolygons = new List <IPolygon>(); foreach (var geom in quadtree.Query(polygon.EnvelopeInternal)) { var insidePolygon = geom as IPolygon; if (insidePolygon != null) { var objectId = (ObjectId)insidePolygon.UserData; var dbObj = tr.GetObject(objectId, OpenMode.ForRead); // 必须是孔洞 if (CadUtils.GetCassFlag(dbObj) == CassFlagIsland) { if (polygon.Contains(insidePolygon) && !insidePolygon.Equals(polygon) && insidePolygon.UserData != polygon.UserData) { insidePolygons.Add(insidePolygon); possibleHoleIds.Add(objectId); } } } } // 算面积 var polygonId = (ObjectId)polygon.UserData; if (insidePolygons.Any()) { var objectIds = new List <ObjectId>(); foreach (var insidePolygon in insidePolygons) { objectIds.Add((ObjectId)insidePolygon.UserData); } dictionary.Add(polygonId, objectIds); } } } return(dictionary); }
public static bool HasHoles(Document document) { var polylineIds = CadUtils.FindAllPolylines(document); var datebase = document.Database; using (var tr = datebase.TransactionManager.StartTransaction()) { foreach (var objectId in polylineIds) { var hole = tr.GetObject(objectId, OpenMode.ForRead) as Entity; if (CadUtils.GetCassFlag(hole) == CassFlagIsland) { return(true); } } // Saves the changes to the database and closes the transaction tr.Commit(); } return(false); }
public static ObjectId[] FindHolesInEntity(Transaction tr, Entity entity) { ObjectId[] entityIds = GroupUtils.GetGroupedObjects(tr, entity); var holeIds = new List <ObjectId>(); foreach (ObjectId entityId in entityIds) { using (var ent = tr.GetObject(entityId, OpenMode.ForRead)) { if (ent is Polyline2d || ent is Polyline) { string cassFlag = CadUtils.GetCassFlag(ent); if (CassFlagIsland.ToLower() == cassFlag.ToLower()) { holeIds.Add(entityId); } } } } return(holeIds.ToArray()); }
public static List <ObjectId> FindPotentialHoles(Document document) { var polylineIds = CadUtils.FindAllPolylines(document); var datebase = document.Database; var hashSetObjIds = new HashSet <ObjectId>(); // 避免重复的数据,用hashset using (var tr = datebase.TransactionManager.StartTransaction()) { // 读入多边形数据 var reader = new DwgReader(); var polygons = new List <IPolygon>(); var quadtree = new Quadtree <IGeometry>(); var possibleHoleIds = new List <ObjectId>(); foreach (ObjectId polylineId in polylineIds) { var polygon = reader.ReadEntityAsPolygon(tr, polylineId) as IPolygon; if (polygon != null) { polygons.Add(polygon); quadtree.Insert(polygon.EnvelopeInternal, polygon); } // ObjectIds using (var ent = tr.GetObject(polylineId, OpenMode.ForRead) as Entity) { if (ent is Polyline2d || ent is Polyline) { // 如果是地块,直接跳过 string cassFlag = CadUtils.GetCassFlag(ent); if (CassFlagName.ToLower() != cassFlag.ToLower()) { possibleHoleIds.Add(polylineId); } } } } // 遍历多边形,如果有洞,开始计算 foreach (var polygon in polygons) { //看看是否包含洞 //quadtree.Query() // 找洞 foreach (var geom in quadtree.Query(polygon.EnvelopeInternal)) { var hole = geom as IPolygon; if (hole == null) { continue; } var holeId = (ObjectId)hole.UserData; if (possibleHoleIds.Contains(holeId) && // 不是潜在的地块 !hole.Equals(polygon) && // 不是同一个多边形 hole.UserData != polygon.UserData && // 不是自己 hole.Within(polygon)) // 有洞! { hashSetObjIds.Add(holeId); // } } } tr.Commit(); return(hashSetObjIds.ToList()); } }