zoukankan      html  css  js  c++  java
  • 使用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)也支持图例、符号化等基本地图概念。

    作者:我也是个傻瓜
    出处:http://www.cnblogs.com/liweis/
    签名:成熟是一种明亮而不刺眼的光辉。

  • 相关阅读:
    郑码
    AutoCAD 安装
    China Mobile 移动
    CCB 建行
    Word基础
    Java 继承
    Java 封装(内部类)
    Java 类与对象
    Java 方法
    Java 数组
  • 原文地址:https://www.cnblogs.com/liweis/p/14523553.html
Copyright © 2011-2022 走看看