### Author Topic: Properly closing a polyline  (Read 119 times)

0 Members and 1 Guest are viewing this topic.

#### autogis

• Mosquito
• Posts: 19
##### Properly closing a polyline
« on: February 20, 2019, 10:06:05 AM »
Hi folks and thank you for taking the time to read this post.  My question is: What is the correct procedure for properly closing a polyline?

This is the line I use to close the polyline:

Code: [Select]
`pline.Closed = true;`
However, if I then query the polyline as follows:

Code: [Select]
`private const double TOLERANCE = 0.001;var t = new Tolerance(TOLERANCE, TOLERANCE);using (var curve1 = pline.GetGeCurve(t))            {                using (var curve2 = pline.GetGeCurve(t))                {                    using (var curveInter = new CurveCurveIntersector3d                   (                    curve1, curve2, pline.Normal, t))                    {                        int interCount = curveInter.NumberOfIntersectionPoints;                        int overlaps = curveInter.OverlapCount();                        if (overlaps < pline.NumberOfVertices)                        {                            // WHY AM I GOING IN HERE?  OVERLAPS=33, pline.NumberOfVertices = 34                        }                    }                }            }`
My conclusion is when I programatically close the polyline, the overlap count is not being updated.   (Should be 34 also). Any ideas how to properly close the polyline?  Thank you.

#### Bryco

• Water Moccasin
• Posts: 1843
##### Re: Properly closing a polyline
« Reply #1 on: February 20, 2019, 11:29:25 AM »
Closing a polyline doe not add to the number of verticies, still the same amount. Although sometimes when the last segment has a bulge cad adds a vertex this does not happen when coding

#### autogis

• Mosquito
• Posts: 19
##### Re: Properly closing a polyline
« Reply #2 on: February 20, 2019, 11:34:28 AM »
Closing a polyline doe not add to the number of verticies, still the same amount. Although sometimes when the last segment has a bulge cad adds a vertex this does not happen when coding

Correct.  But the overlap count should have been increased to match the number of vertices.  See my example code.

#### n.yuan

• Bull Frog
• Posts: 269
##### Re: Properly closing a polyline
« Reply #3 on: February 20, 2019, 11:42:34 AM »
If the polyline's start point and end point are not at the same point, set Closed=true would extent the polyline from the previous end point to the start point. So, the polyline would ends up with the same count of vertices and segment (between vertices). In this case, we say the polygon from the polyline does not have duplicated vertices. This is the correct closed polyline equivalent to GIS polygon in AutoCAD.

In your code case, it is obviously the polyline's start point and end point are at the same location. Closed=true simply make the polyline closed (i.e. adding a segment with 0 length between start and end point. It is your responsibility as programmer, who wants to create a closed polyline as polylgon, to decide if duplicate vertices are allowed or not; and if not, you need to remove it. If you have used AutoCAD Map, you know it comes drawing clean up tool with one of the features is to remove duplicated vertices from closed polyline.

This kind of closed polylines with start/end points are at the same position very often are the result of importing GIS polygon, where the importing process does not correctly convert GID polygon into AutoCAD's closed polyline, because in GIS worked, the closed polyline loop (polylone) is expressed with series of points with the first point and the last point being the same.

So, in AutoCAD, there is not CORRECT or INCORRECT way to close a polyline. It is your code's resposibility to set Closed=True/False, and detect/deal with duplicated vertices when necessary.