ThinkGeo.com    |     Documentation    |     Premium Support

Line Shape

I have a problem to convert code from Edition 2 to 3. This code worked in Edition2:


 


 Dim fname As String = Path.GetFileNameWithoutExtension(Me.OpenFileDialog1.FileName).ToUpper


 Dim layer As MapSuite.Layer = New MapSuite.Layer(OpenFileDialog1.FileName, mRotated, True)


layer.Name = fname


 layer.ZoomLevel01.GeoStyle = MapSuite.GeoLineStyles.Railway1


 layer.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.ZoomLevel18


 


 I read quite a few LONGITUDEs and LATITUDEs, convert the points into a line and save it in a shapefile.


 Then I want to display the shapefile. I tried this code, but the line does not display at all.


 Can you please help me with the correct code?


 


 vertexCollection = New System.Collections.Generic.List(Of MapSuite.Core.Vertex)


 Dim dictionaryColumn As New System.Collections.Generic.Dictionary(Of String, String)


 'this is in a loop


 While 


    'get the values from  a dataset


    vertex.X = pointsRow.LONGITUDE


    vertex.Y = pointsRow.LATITUDE


    vertexCollection.Add(vertex)


 End While


 


lineShape = New MapSuite.Core.LineShape(vertexCollection)


dictionaryColumn.Add("SECTION", pointsRow.SECTION.ToString)


shapeFile.AddFeature(lineShape, dictionaryColumn)


 


'display the shapefile


layer.Name = fname


layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = MapSuite.Core.LineStyles.Railway1



Any help on how to create lines with multipoints in a shapefile and then to display the shapefile - I want to display a railway line, please?

Alta,


Here is the code for version 3 as well as the result snapshot. Let me know for any queries about it.


 



 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Create a Shape File
        Dim dbfColumn As New DbfColumn("SECTION", DbfColumnType.String, 30, 0)
        Dim dbfColumns As DbfColumn() = New DbfColumn() {dbfColumn}
        If File.Exists("newPolyLine.shp") Then
            File.Delete("newPolyLine.shp")
        End If
        ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polyline, "newPolyLine.shp", dbfColumns)

        ' Create a Polyline Feature
        Dim vertexCollection As New List(Of Vertex)
        vertexCollection.Add(New Vertex(0, 0))
        vertexCollection.Add(New Vertex(10, 10))
        vertexCollection.Add(New Vertex(10, 20))
        vertexCollection.Add(New Vertex(40, 20))

        Dim lineShape As New LineShape(vertexCollection)
        Dim dictionaryColumn As New Dictionary(Of String, String)
        dictionaryColumn.Add("SECTION", "Feature1")
        Dim Feature As New Feature(lineShape, dictionaryColumn)

        ' Add the feature to an existed shape file
        Dim newPolyLineShapeFile As New ShapeFileFeatureLayer("newPolyLine.shp", ShapeFileReadWriteMode.ReadWrite)
        newPolyLineShapeFile.Open()
        newPolyLineShapeFile.FeatureSource.BeginTransaction()
        newPolyLineShapeFile.FeatureSource.AddFeature(Feature)
        newPolyLineShapeFile.FeatureSource.CommitTransaction()
        newPolyLineShapeFile.Close()

        ' Display the shape file
        WinformsMap1.MapUnit = GeographyUnit.DecimalDegree
        newPolyLineShapeFile.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Railway1
        newPolyLineShapeFile.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
        WinformsMap1.StaticOverlay.Layers.Add(newPolyLineShapeFile)
        WinformsMap1.Refresh()

    End Sub

 



Ben.



Thanks for the help, appreciate it!

Always my pleasure! Just let us know if we can make your coding easier.