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/
    签名:成熟是一种明亮而不刺眼的光辉。

  • 相关阅读:
    VTK初学一,b_PolyVertex多个图形点的绘制
    VTK初学一,a_Vertex图形点的绘制
    Python基础学习之集合
    Apache
    NTP时间同步服务和DNS服务
    NFS服务及DHCPD服务
    samba服务及vsftpd服务
    Linux rpm和yum软件管理
    Linux网络技术管理及进程管理
    Linux RAID磁盘阵列
  • 原文地址:https://www.cnblogs.com/liweis/p/14523553.html
Copyright © 2011-2022 走看看