使用DevExpress展示地图—加载SHP

做简单的地图展示,不需要专业的GIS组件,使用DevExpress即可完成。以加载Shp地图文件为例。

private void LoadShp(string path)
{
    //创建SHP数据源
    ShapefileDataAdapter dataAdapter = new ShapefileDataAdapter
    {
        FileUri = new Uri(path),
        SourceCoordinateSystem = new CartesianSourceCoordinateSystem(), //坐标系
        DefaultEncoding = Encoding.UTF8, //编码
    };

    //创建矢量图层
    VectorItemsLayer vectorItemsLayer = new VectorItemsLayer
    {
        Data = dataAdapter,
        Colorizer = CreateChoroplethColorizer("SCP") //分级符号化
    };
    vectorItemsLayer.Name = "任务区";
    
//标注
    vectorItemsLayer.ShapeTitlesVisibility = VisibilityMode.Visible;
    vectorItemsLayer.ShapeTitlesPattern = "{Name}:{ SCP }%";

    //设置地图控件属性
    this.mapControl1.CoordinateSystem = new CartesianMapCoordinateSystem();
    this.mapControl1.NavigationPanelOptions.Visible = false;

    //加载图层
    mapControl1.Layers.Add(vectorItemsLayer);

    //加载图例
    MapLegendBase mapLegendBase = CreateLegend(vectorItemsLayer);
    mapLegendBase.Alignment = LegendAlignment.TopLeft;
    this.mapControl1.Legends.Add(mapLegendBase);
}

 需要注意的问题:

(1)正确设置ShapefileDataAdapter和mapControl的坐标系统CoordinateSystem,否则无法显示;

(2)当标注用到包含中文的属性时会乱码,需设置DataAdapter的默认编码属性DefaultEncoding;

(3)标注使用图层的ShapeTitlesPattern属性,它是一个字符串,对于引用的字段,需加上中括号,例如"{Name}"表示用属性表中Name来标注 ;

(4)也支持图例、符号化等基本地图概念。

posted @ 2021-03-12 14:06  我也是个傻瓜  阅读(1052)  评论(0编辑  收藏  举报