public static Geometry PolygonizeCutEdges(Geometry g) { var lines = LineStringExtracter.GetLines(g); var polygonizer = new Polygonizer(); polygonizer.Add(lines); var geom = polygonizer.GetCutEdges(); return(g.Factory.BuildGeometry(geom.ToArray <Geometry>())); }
public static IGeometry polygonizeCutEdges(IGeometry g) { var lines = LineStringExtracter.GetLines(g); Polygonizer polygonizer = new Polygonizer(); polygonizer.Add(lines); var geom = polygonizer.GetCutEdges(); return(g.Factory.BuildGeometry(CollectionUtil.Cast <ILineString, IGeometry>(geom))); }
public static Geometry polygonizeCutEdges(Geometry g) { var lines = LineStringExtracter.GetLines(g); Polygonizer polygonizer = new Polygonizer(); polygonizer.Add(lines); var geomList = polygonizer.GetCutEdges() .Select(x => (Geometry)x) .ToList(); return(g.Factory.BuildGeometry(geomList)); }
public static IGeometry polygonizeAllErrors(IGeometry g) { var lines = LineStringExtracter.GetLines(g); Polygonizer polygonizer = new Polygonizer(); polygonizer.Add(lines); var errs = new List <ILineString>(); errs.AddRange(polygonizer.GetDangles()); errs.AddRange(polygonizer.GetCutEdges()); errs.AddRange(CollectionUtil.Cast <IGeometry, ILineString>(polygonizer.GetInvalidRingLines())); return(g.Factory.BuildGeometry(CollectionUtil.Cast <ILineString, IGeometry>(errs))); }
public static Geometry PolygonizeAllErrors(Geometry g) { var lines = LineStringExtracter.GetLines(g); var polygonizer = new Polygonizer(); polygonizer.Add(lines); var errs = new List <Geometry>(); errs.AddRange(polygonizer.GetDangles()); errs.AddRange(polygonizer.GetCutEdges()); errs.AddRange(polygonizer.GetInvalidRingLines()); return(g.Factory.BuildGeometry(errs)); }
public static IGeometry polygonizeAllErrors(IGeometry g) { var lines = LineStringExtracter.GetLines(g); Polygonizer polygonizer = new Polygonizer(); polygonizer.Add(lines); var geomList = new List <IGeometry>(); geomList.AddRange(polygonizer.GetDangles()); geomList.AddRange(polygonizer.GetCutEdges()); geomList.AddRange(polygonizer.GetInvalidRingLines()); return(g.Factory.BuildGeometry(geomList)); }
public static List <ObjectId> PolygonizeLineStrings(Database database, IEnumerable <ObjectId> polylineIdCollection, String outLayerName = "0", AcadColor color = null, double precision = 0.00001) { var result = new List <ObjectId>(); using (var tr = database.TransactionManager.StartTransaction()) { // 读入多边形数据 var lineStringList = new List <IGeometry>(); foreach (ObjectId polylineId in polylineIdCollection) { var curve = tr.GetObject(polylineId, OpenMode.ForRead) as Curve; var reader = new DwgReader(); var lineString = reader.ReadGeometry(curve, tr) as LineString; if (lineString != null && lineString.IsEmpty == false) { lineStringList.Add(lineString); } } #if TryManualUnion // 创建节点 var nodedContours = new List <List <IGeometry> >(); var scale = 1.0 / precision; var geomNoder = new NetTopologySuite.Noding.Snapround.GeometryNoder(new PrecisionModel(scale)); var nodedList = geomNoder.Node(lineStringList); // 这里可能可以用nodedList.Count来计算一个gourp的size来限定线程数量 var maxCountInGroup = 200; foreach (var c in nodedList) { //Coordinate[] linePts = CoordinateArrays.RemoveRepeatedPoints(c.Coordinates); //if (linePts.Count() > 1) // nodedContours.Add(c.Factory.CreateLineString(linePts)); //c.Buffer(0.001); // 将所有的线段每maxCountInGroup个分成一组. var groupCount = nodedContours.Count; if (groupCount == 0) { nodedContours.Add(new List <IGeometry>()); } var itemCount = nodedContours[nodedContours.Count - 1].Count; if (itemCount < maxCountInGroup) { nodedContours[nodedContours.Count - 1].Add(c); } else { nodedContours.Add(new List <IGeometry>()); nodedContours[nodedContours.Count - 1].Add(c); } } var workers = new List <Worker>(); var threadList = new List <Thread>(); // 为每组geometry开一个线程做union. foreach (List <IGeometry> nodedContour in nodedContours) { // Start a thread. var worker = new Worker(nodedContour); workers.Add(worker); var thread = new Thread(worker.Execute); threadList.Add(thread); thread.Start(); } // 等待所有线程运行结束 foreach (Thread thread in threadList) { thread.Join(); } // 最后将每组union得到的IGeometry再做一次union var nodedLineString = workers[0].Geometry; for (int i = 1; i < workers.Count; i++) { nodedLineString = nodedLineString.Union(workers[i].Geometry); } #else // 开始做Union var nodedLineString = UnaryUnionOp.Union(lineStringList, new GeometryFactory(new PrecisionModel(0.9d))); //var nodedLineString = lineStringList[0]; //for (int i = 1; i < lineStringList.Count; i++) //{ // nodedLineString = nodedLineString.Union(lineStringList[i]); //} #endif //造区 Polygonizer polygonizer = new Polygonizer(); polygonizer.Add(nodedLineString); var polys = polygonizer.GetPolygons(); var dangles = polygonizer.GetDangles(); var cuts = polygonizer.GetCutEdges(); var writer = new DwgWriter(); var modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(database); var blockTableRecord = (BlockTableRecord)tr.GetObject(modelSpaceId, OpenMode.ForWrite, false); // 多边形 foreach (IGeometry geometry in polys) { var polygon = geometry as Polygon; if (polygon != null) { var polylines = writer.WritePolyline(polygon); foreach (Polyline polyline in polylines) { if (color != null) { polyline.Color = color; } polyline.Layer = outLayerName; // 输出到CAD var polylineId = blockTableRecord.AppendEntity(polyline); result.Add(polylineId); tr.AddNewlyCreatedDBObject(polyline, true); } } } //// 悬挂线 //foreach (ILineString lineString in dangles) //{ // if (lineString != null) // { // var polyline = writer.WritePolyline(lineString); // if (color != null) // polyline.Color = color; // polyline.Layer = outLayerName; // // 输出到CAD // blockTableRecord.AppendEntity(polyline); // tr.AddNewlyCreatedDBObject(polyline, true); // } //} //// 裁剪线 //foreach (ILineString lineString in cuts) //{ // if (lineString != null) // { // var polyline = writer.WritePolyline(lineString); // if (color != null) // polyline.Color = color; // polyline.Layer = outLayerName; // // 输出到CAD // blockTableRecord.AppendEntity(polyline); // tr.AddNewlyCreatedDBObject(polyline, true); // } //} tr.Commit(); } return(result); }
public static void FindDanglingLine(Database database) { var polylineIds = CadUtils.FindAllPolylines(Application.DocumentManager.MdiActiveDocument); using (var tr = database.TransactionManager.StartTransaction()) { var pmFixed3 = new PrecisionModel(3); // 读入多边形数据 var lineStringList = new List <IGeometry>(); foreach (ObjectId polylineId in polylineIds) { var curve = tr.GetObject(polylineId, OpenMode.ForRead) as Curve; var reader = new DwgReader(); IGeometry lineString; try { lineString = reader.ReadCurveAsPolygon(tr, curve) as Polygon; } catch (Exception) { lineString = reader.ReadCurveAsLineString(tr, curve) as LineString; } if (lineString != null && lineString.IsEmpty == false) { lineString = SimpleGeometryPrecisionReducer.Reduce(lineString, pmFixed3); lineStringList.Add(lineString); } } // 开始做Union var nodedLineString = UnaryUnionOp.Union(lineStringList); var polygonizer = new Polygonizer(); polygonizer.Add(nodedLineString); var polys = polygonizer.GetPolygons(); var dangles = polygonizer.GetDangles(); var cuts = polygonizer.GetCutEdges(); var writer = new DwgWriter(); var modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(database); var blockTableRecord = (BlockTableRecord)tr.GetObject(modelSpaceId, OpenMode.ForWrite, false); // 悬挂线 foreach (ILineString lineString in dangles) { //if (lineString != null) //{ // var polyline = writer.WritePolyline(lineString); // polyline.ColorIndex = 3; // //polyline.Layer = ""; // // 输出到CAD // blockTableRecord.AppendEntity(polyline); // tr.AddNewlyCreatedDBObject(polyline, true); //} } tr.Commit(); } }