0

我想.shp在 SharpMap 框中显示一个 shapefile,我写了这段代码:

    public partial class Details : UserControl
    {
        public Details()
        {
            InitializeComponent();

            SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
            string path = @"D:\Studies\file.shp";
            SharpMap.Map myMap = new SharpMap.Map(new System.Drawing.Size(500, 250));
            vlay=new SharpMap.Data.Providers.ShapeFile(path);
            MapBox.Map.Layers.Add(vlay);
            MapBox.Map.ZoomToExtents();

        }
    }

它没有运行,它显示:

SharpMap.Data.Providers.ShapeFile可以转换为SharpMap.Layers.VectorLayer

我应该怎么办 ?

4

1 回答 1

0

分配 vlay.DataSource,就像 Clemens 说的:

 SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
 string path = @"D:\Studies\file.shp";
 vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(path);
 MapBox.Map.Layers.Add(vlay);
 MapBox.Map.ZoomToExtents();
 MapBox.Refresh();
于 2016-01-18T21:22:03.127 回答