Esempio n. 1
0
        public static void SimplifyPolylinesInterative(ObjectId polyid)
        {
            // Get the document
            var doc = Application.DocumentManager.MdiActiveDocument;
            IList <Point2dCollection> point2DCollections = new List <Point2dCollection>();
            IList <Point2dCollection> reducedCollection  = new List <Point2dCollection>();
            Point2dCollection         sortedCollection   = new Point2dCollection();
            double tolerance = 0.001;

            try
            {
                //Select Polyline Objects
                ObjectIdCollection collection = new ObjectIdCollection();
                collection.Add(polyid);

                if (collection == null || collection.Count == 0)
                {
                    return;
                }

                using (DocumentLock doclock = doc.LockDocument())
                {
                    //Get Point Collection of Polylines
                    foreach (ObjectId obj in collection)
                    {
                        point2DCollections.Add(GetPoint2dFromPolylines(obj));

                        //Log Original Information
                        GetPolylineName(obj, collection.IndexOf(obj));
                    }

                    foreach (Point2dCollection pnt2DCol in point2DCollections)
                    {
                        int            index = point2DCollections.IndexOf(pnt2DCol);
                        Point2d[]      reducedPoints;
                        List <Point2d> list = new List <Point2d>(pnt2DCol.ToArray());

                        //Reduce Polylines
                        reducedPoints = DouglasPeuckerImplementation.DouglasPeuckerReduction(list, tolerance);
                        reducedCollection.Add(ConvertCollections(reducedPoints));

                        sortedCollection = SortModified(list, ConvertCollections(reducedPoints));

                        // Add Reduced Polylines to Database
                        ModifyPolylineVertices(sortedCollection, collection[index]);

                        GetPolylineName(sortedCollection, point2DCollections.IndexOf(pnt2DCol));
                        index++;
                    }
                }
            }
            catch (System.Exception ex)
            {
                DatabaseLogs.FormatLogs("SimplifyPolylines: " + ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Offsets the features by -0.001 ft
        /// </summary>
        /// <param name="name">The name.</param>
        /// <exception cref="System.ArgumentNullException">layer name</exception>
        public static void OffsetFeatures(string name)
        {
            try
            {
                MessengerManager.MessengerManager.AddLog("Start Offset Features");

                if (String.IsNullOrEmpty(name))
                {
                    throw new ArgumentNullException("Layer Name");
                }

                var pidsToDelete = new Acaddb.ObjectIdCollection();
                var pids         = GetAllPolylines();

                //var refcentroid = GetCentroidOfOuterBoundary(GetPolylinePoints(OGR.ObjectId));


                var offset = -0.0001; //inital start value

                foreach (Acaddb.ObjectId oid in pids)
                {
                    offset = -0.001;

                    Acaddb.Polyline polyline = GetPolyline((oid));

                    if (polyline == null)
                    {
                        throw new ArgumentNullException("Polyline is Null");
                    }

                    if (polyline.Layer != name.ToUpper())
                    {
                        continue;
                    }

                    MessengerManager.MessengerManager.AddLog("Found Offset Features on Layer " + name);

                    var newpoly = polyline.GetOffsetCurves(offset).Cast <Acaddb.Polyline>();

                    newpoly.FirstOrDefault().Layer = polyline.Layer;

                    // Get the current document and database

                    var acDoc   = Application.DocumentManager.MdiActiveDocument;
                    var acCurDb = acDoc.Database;

                    using (var acTrans = Application.DocumentManager.MdiActiveDocument
                                         .TransactionManager.StartTransaction())
                    {
                        // Open the Block table for read
                        Acaddb.BlockTable acBlkTbl;
                        acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                     Acaddb.OpenMode.ForRead) as Acaddb.BlockTable;

                        // Open the Block table record Model space for write
                        Acaddb.BlockTableRecord acBlkTblRec;
                        acBlkTblRec = acTrans.GetObject(acBlkTbl[Acaddb.BlockTableRecord.ModelSpace],
                                                        Acaddb.OpenMode.ForWrite) as Acaddb.BlockTableRecord;
                        // Add each offset object
                        acBlkTblRec.AppendEntity(newpoly.FirstOrDefault());
                        acTrans.AddNewlyCreatedDBObject(newpoly.FirstOrDefault(), true);
                        acTrans.Commit();
                    }
                    pidsToDelete.Add(oid);
                }

                DeletePolys(pidsToDelete);
            }
            catch (Exception ex)
            {
                MessengerManager.MessengerManager.LogException(ex);
            }
            finally
            {
                MessengerManager.MessengerManager.AddLog("End Offset Features");
            }
        }