ComponentOne Maps for WinForms
Working with Map Control / Adding Vector Data / Displaying Shapes using a Shapefile
In This Topic
    Displaying Shapes using a Shapefile
    In This Topic

    Shapefile is a popular vector data format for geographic visualization of data. It represents data using vector elements such as polylines and polygons. This type of file is usually stored in two formats:

    The following code loads both the shp and dbf format files using C1.FlexMap.ShapeReader class and adds the loaded data to the vector layer on a map:

    Dim layerUsa = MapReader.LoadShpFile("states.shp", "states.dbf", Function(vector, data) 
    vector.Tag = data("STATE_NAME")
    
    End Function)
    c1Map1.Layers.Add(layerUsa)
    
    layerUsa.Style.BackColor = Color.Purple
    layerUsa.Style.Stroke.Color = Color.LightGray
    
    c1Map1.Viewport.Center = New C1.Win.Interop.Point(-115, 50)
    c1Map1.Viewport.MinZoom = 2
    c1Map1.Viewport.Zoom = 2
    
    var layerUsa = MapReader.LoadShpFile("states.shp", "states.dbf",
                (vector, data) =>
                {
                    vector.Tag = data["STATE_NAME"];
                });
    c1Map1.Layers.Add(layerUsa);
    
    layerUsa.Style.BackColor = Color.Purple;
    layerUsa.Style.Stroke.Color = Color.LightGray;
    
    c1Map1.Viewport.Center = new C1.Win.Interop.Point(-115, 50);
    c1Map1.Viewport.MinZoom = 2;
    c1Map1.Viewport.Zoom = 2;
    

    In the above code, we have referred a class named MapReader that we have created. This class reads the vector data from the shp and dbf files.

    On adding shapes from shp and dbf files, the map will look similar to the image given below:

     Maps on adding shapes with dbf files