This project is read-only.

A code for generation of shapefile categories and labels for shapefile with countries of the World.

In older version of MapWinGIS code like this was used: old code

Please, stick to the new version.

    Private Sub AddShapefile()
        Dim sf As New MapWinGIS.Shapefile
        Dim filename As String = "c:\Dev\Installation projects\World\Shapefiles\world_adm0.shp"

        If Not sf.Open(filename, Nothing) Then
            MessageBox.Show("Failed to open shapefile: " + sf.ErrorMsg(sf.LastErrorCode))
            ' setting layer options (should be done before generation of categories
            ' as each category will hold a copy of this values when created)
            Dim options As MapWinGIS.ShapeDrawingOptions = sf.DefaultDrawingOptions
            options.FillVisible = True
            options.FillColor = Convert.ToUInt32(RGB(Color.SpringGreen.R, Color.SpringGreen.G, Color.SpringGreen.B))
            options.LineColor = Convert.ToUInt32(RGB(Color.Pink.R, Color.Pink.G, Color.Pink.B))

            ' set different colors by region ([Region] field is expected in attribute table)
            Dim index As Integer = sf.Table.FieldIndexByName("Region")
            sf.Categories.Generate(index, MapWinGIS.tkClassificationType.ctUniqueValues, 0)
            Dim useColorScheme As Boolean = True    ' either of 2 can be used
            If useColorScheme Then
                ' apply colors automatically
                Dim scheme As New MapWinGIS.ColorScheme
                scheme.SetColors2(MapWinGIS.tkMapColor.LightYellow, MapWinGIS.tkMapColor.LightBlue)  ' see overloads as well
                sf.Categories.ApplyColorScheme(MapWinGIS.tkColorSchemeType.ctSchemeRandom, scheme)
                ' set colors manually
                sf.Categories.Item(0).DrawingOptions.FillColor = Convert.ToUInt32(RGB(0, 255, 0))
                sf.Categories.Item(1).DrawingOptions.FillColor = Convert.ToUInt32(RGB(255, 0, 0))
            End If

            ' generate labels (name field is expected in attribute table)
            sf.Labels.Generate("[Name]", MapWinGIS.tkLabelPositioning.lpCentroid, True)
            sf.Labels.FontColor = Convert.ToUInt32(RGB(0, 0, 255))
            sf.Labels.Alignment = MapWinGIS.tkLabelAlignment.laCenter

            ' adding layer to map and zooming to it
            Dim handle As Integer = AxMap1.AddLayer(sf, True)
        End If
    End Sub
Results should be like this: 

Last edited Jun 24, 2011 at 11:52 AM by sleschinski, version 11


No comments yet.