Create Polyline based on Points / coordinates

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

1 Like

Here’s an old 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
1 Like

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)
2 Likes

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)

2 Likes

Thanks Jerry & Nissephar sharing above code…

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

1 Like

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

1 Like