# Create Polyline based on Points / coordinates

**URL:** <https://mapwindow.discourse.group/t/create-polyline-based-on-points-coordinates/270>\
**Category:** MapWinGIS\
**Created:** [September 30, 2019, 6:46am UTC](https://mapwindow.discourse.group/t/create-polyline-based-on-points-coordinates/270 "2019-09-30T06:46:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carol](https://avatars.discourse-cdn.com/v4/letter/c/9d8465/32.png) [@Carol](https://mapwindow.discourse.group/u/Carol)\
**Post date:** [September 30, 2019, 6:46am UTC](https://mapwindow.discourse.group/t/create-polyline-based-on-points-coordinates/270/1 "2019-09-30T06:46:15Z")

</div>

Dear All,  
There is a set of Points selected from shapefile or Coordinates information as CSV file. Can a small example of how this can be used to convert Polyline…

Thanks ,  
Carol

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [October 3, 2019, 12:41am UTC](https://mapwindow.discourse.group/t/create-polyline-based-on-points-coordinates/270/2 "2019-10-03T00:41:02Z")

</div>

Here’s an old [VB.Net](http://VB.Net) snippet that unpacks a point collection and populates a polyline Shape.

The point collection is a string of points, where each xy coordinate is separated by a semi-colon, and x and y are separated by a comma. I hope this helps.

```
Public Function UnpackPolyline(ByVal pointCollection As String) As Shape
    Dim pPolyline as Shape
    Dim vPoints() As String, vPoint() As String

    ' create the empty Shape
    pPolyline = New Shape()
    pPolyline.Create(SHP_POLYLINE)

    ' extract the points
    vPoints = Split(pointCollection, ";")
    For i As Integer = 0 To vPoints.GetUpperBound(0)
        ' get next point
        vPoint = Split(vPoints(i), ",")
        ' add point to polyline
        pPolyline.AddPoint(CDbl(vPoint(0)), CDbl(vPoint(1)))
    Next

    Return pPolyline
End Function
```

---

<div class="post-metadata">

**Author:** ![Nissephar](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@Nissephar](https://mapwindow.discourse.group/u/Nissephar)\
**Post date:** [October 9, 2019, 7:13am UTC](https://mapwindow.discourse.group/t/create-polyline-based-on-points-coordinates/270/3 "2019-10-09T07:13:42Z")

</div>

I have the same issue with creating a polyline. I am using the example above, but I cannot get it to work. My code is looking like this:

> Dim redroute As New MapWinGIS.Shapefile  
> Dim redshp As MapWinGIS.Shape  
> redshp = New MapWinGIS.Shape  
> redshp.Create(MapWinGIS.ShpfileType.SHP\_POLYLINE)  
> For k As Integer = 1 To Me.DataGridView7.Rows(i).Cells.Count - 1

```
        If Me.DataGridView7.Rows(i).Cells(k).Value = "" Then
            Exit For
        End If
        Dim pnt As New MapWinGIS.Point
        pnt.x = todecimaldegrees(Me.DataGridView7.Rows(i).Cells(k).Value).Item(2)
        pnt.y = todecimaldegrees(Me.DataGridView7.Rows(i).Cells(k).Value).Item(1)
           
        redshp.AddPoint(CDbl(pnt.x), CDbl(pnt.y))
           
    Next
    redroute.EditAddShape(redshp)

```

---

<div class="post-metadata">

**Author:** ![Nissephar](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@Nissephar](https://mapwindow.discourse.group/u/Nissephar)\
**Post date:** [October 9, 2019, 3:23pm UTC](https://mapwindow.discourse.group/t/create-polyline-based-on-points-coordinates/270/4 "2019-10-09T15:23:29Z")

</div>

Nevermind. I found a solution. This solved my problem:

> Dim redroute As New MapWinGIS.Shapefile  
> Dim redshp As MapWinGIS.Shape  
> redshp = New MapWinGIS.Shape  
> redroute.CreateNew(“”, MapWinGIS.ShpfileType.SHP\_POLYLINE)  
> For i As Integer = 0 To Me.DataGridView7.Rows.Count - 1  
> redshp.Create(MapWinGIS.ShpfileType.SHP\_POLYLINE)  
> Dim newShape As New MapWinGIS.Shape  
> For k As Integer = 1 To Me.DataGridView7.Rows(i).Cells.Count - 1  
> Dim pntx As Double  
> Dim pnty As Double  
> pntx = todecimaldegrees(Me.DataGridView7.Rows(i).Cells(k).Value).Item(2)  
> pnty = todecimaldegrees(Me.DataGridView7.Rows(i).Cells(k).Value).Item(1)  
> redshp.AddPoint(pntx, pnty)  
> Dim serialized As String = redshp.SerializeToString()  
> newShape.CreateFromString(serialized)  
> Dim shpindex As Integer = redroute.EditAddShape(newShape)  
> redroute.EditCellValue(0, shpindex, Me.DataGridView7.Rows(i).Cells(“Column64”).Value)  
> Next  
> redlayer = AxMap1.AddLayer(redroute, True)

---

<div class="post-metadata">

**Author:** ![Carol](https://avatars.discourse-cdn.com/v4/letter/c/9d8465/32.png) [@Carol](https://mapwindow.discourse.group/u/Carol)\
**Post date:** [October 10, 2019, 7:37am UTC](https://mapwindow.discourse.group/t/create-polyline-based-on-points-coordinates/270/5 "2019-10-10T07:37:00Z")

</div>

Thanks Jerry & Nissephar sharing above code…

@Nissepher, did you created Mapwindow 5 plugin using above code…

---

<div class="post-metadata">

**Author:** ![Nissephar](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@Nissephar](https://mapwindow.discourse.group/u/Nissephar)\
**Post date:** [October 10, 2019, 7:48am UTC](https://mapwindow.discourse.group/t/create-polyline-based-on-points-coordinates/270/6 "2019-10-10T07:48:01Z")

</div>

@Carol  
I did not create a plugin for Mapwindow 5. I created a stand-alone application.

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [October 18, 2019, 7:51am UTC](https://mapwindow.discourse.group/t/create-polyline-based-on-points-coordinates/270/7 "2019-10-18T07:51:21Z")

</div>

Closed on October 18, 2019, 7:51am UTC


